Skip to content

Commit 5251cb7

Browse files
committed
[fix](rest-s3)Set AWS Request Checksum Calculation only if not set, avoid issues on non-S3 storage
AWS SDK for Java v2 uses the system property AwsSystemSetting.AWS_REQUEST_CHECKSUM_CALCULATION to control request payload checksum calculation. According to the official discussion AWS SDK v2 Discussion #5802 : By default, the SDK may automatically calculate checksums when required. For AWS S3, setting the default value "WHEN_REQUIRED" ensures checksums are calculated only when necessary, providing both compatibility and performance benefits. aws-chunked encoding is not supported with the specified x-amz-content-sha256 value because these services do not support AWS-specific chunked encoding or SHA256 checksum.
1 parent d420ca8 commit 5251cb7

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

fe/fe-core/src/main/java/org/apache/doris/datasource/property/storage/AbstractS3CompatibleProperties.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
3030
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
3131
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
32+
import software.amazon.awssdk.core.SdkSystemSetting;
3233

3334
import java.util.HashMap;
3435
import java.util.Map;
@@ -250,6 +251,7 @@ public void initializeHadoopStorageConfig() {
250251
// storage is OSS, OBS, etc., users may still configure the schema as "s3://".
251252
// To ensure backward compatibility, we append S3-related properties by default.
252253
appendS3HdfsProperties(hadoopStorageConfig);
254+
setDefaultRequestChecksum();
253255
}
254256

255257
private void appendS3HdfsProperties(Configuration hadoopStorageConfig) {
@@ -275,6 +277,34 @@ private void appendS3HdfsProperties(Configuration hadoopStorageConfig) {
275277
hadoopStorageConfig.set("fs.s3a.path.style.access", getUsePathStyle());
276278
}
277279

280+
/**
281+
* Sets the AWS request checksum calculation property to "WHEN_REQUIRED"
282+
* only if it has not been explicitly set by the user.
283+
*
284+
* <p>
285+
* Background:
286+
* AWS SDK for Java v2 uses the system property
287+
* {@link SdkSystemSetting#AWS_REQUEST_CHECKSUM_CALCULATION} to determine
288+
* whether request payloads should have a checksum calculated.
289+
* <p>
290+
* According to the official AWS discussion:
291+
* https://github.com/aws/aws-sdk-java-v2/discussions/5802
292+
* - Default SDK behavior may calculate checksums automatically if the property is not set.
293+
* - Automatic calculation can affect performance or cause unexpected behavior for large requests.
294+
* <p>
295+
* This method ensures:
296+
* 1. The property is set to "WHEN_REQUIRED" only if the user has not already set it.
297+
* 2. User-specified settings are never overridden.
298+
* 3. Aligns with AWS SDK recommended best practices.
299+
* </p>
300+
*/
301+
public static void setDefaultRequestChecksum() {
302+
String key = SdkSystemSetting.AWS_REQUEST_CHECKSUM_CALCULATION.property();
303+
if (System.getProperty(key) == null) {
304+
System.setProperty(key, "WHEN_REQUIRED");
305+
}
306+
}
307+
278308
@Override
279309
public String getStorageName() {
280310
return "S3";

fe/fe-core/src/test/java/org/apache/doris/datasource/property/storage/OSSPropertiesTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.jupiter.api.Test;
2626
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
2727
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
28+
import software.amazon.awssdk.core.SdkSystemSetting;
2829

2930
import java.util.HashMap;
3031
import java.util.Map;
@@ -268,4 +269,13 @@ public void testS3DisableHadoopCache() throws UserException {
268269
Assertions.assertFalse(s3Properties.hadoopStorageConfig.getBoolean("fs.oss.impl.disable.cache", false));
269270
}
270271

272+
@Test
273+
public void testResuestCheckSum() throws UserException {
274+
Map<String, String> props = Maps.newHashMap();
275+
props.put("oss.endpoint", "oss-cn-hangzhou.aliyuncs.com");
276+
Assertions.assertEquals("WHEN_REQUIRED", System.getProperty(SdkSystemSetting.AWS_REQUEST_CHECKSUM_CALCULATION.property()));
277+
System.setProperty("aws.requestChecksumCalculation", "ALWAYS");
278+
Assertions.assertEquals("ALWAYS", System.getProperty(SdkSystemSetting.AWS_REQUEST_CHECKSUM_CALCULATION.property()));
279+
}
280+
271281
}

0 commit comments

Comments
 (0)