Skip to content

Commit 9f2e918

Browse files
authored
Pass null part-size to CRT when not configured (#6588)
* pass null part size to CRT when not configured * add changelog * fix crt resource management test - wrong final part content-range * regression test logs
1 parent 34b4060 commit 9f2e918

File tree

8 files changed

+50
-12
lines changed

8 files changed

+50
-12
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "s3",
4+
"contributor": "",
5+
"description": "Pass null part-size to CRT when not configured"
6+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
<rxjava3.version>3.1.5</rxjava3.version>
130130
<commons-codec.verion>1.17.1</commons-codec.verion>
131131
<jmh.version>1.37</jmh.version>
132-
<awscrt.version>0.39.4</awscrt.version>
132+
<awscrt.version>0.40.1</awscrt.version>
133133

134134
<!--Test dependencies -->
135135
<junit5.version>5.10.0</junit5.version>

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/crt/S3CrtAsyncHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ private S3ClientOptions createS3ClientOption() {
105105
.withCredentialsProvider(s3NativeClientConfiguration.credentialsProvider())
106106
.withClientBootstrap(s3NativeClientConfiguration.clientBootstrap())
107107
.withTlsContext(s3NativeClientConfiguration.tlsContext())
108-
.withPartSize(s3NativeClientConfiguration.partSizeBytes())
109108
.withMultipartUploadThreshold(s3NativeClientConfiguration.thresholdInBytes())
110109
.withComputeContentMd5(false)
111110
.withEnableS3Express(true)
@@ -121,6 +120,7 @@ private S3ClientOptions createS3ClientOption() {
121120
if (Boolean.FALSE.equals(s3NativeClientConfiguration.isUseEnvironmentVariableValues())) {
122121
options.withProxyEnvironmentVariableSetting(disabledHttpProxyEnvironmentVariableSetting());
123122
}
123+
Optional.ofNullable(s3NativeClientConfiguration.partSizeBytes()).ifPresent(options::withPartSize);
124124
Optional.ofNullable(s3NativeClientConfiguration.proxyOptions()).ifPresent(options::withProxyOptions);
125125
Optional.ofNullable(s3NativeClientConfiguration.connectionTimeout())
126126
.map(Duration::toMillis)

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/crt/S3NativeClientConfiguration.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class S3NativeClientConfiguration implements SdkAutoCloseable {
5353
private final ClientBootstrap clientBootstrap;
5454
private final CrtCredentialsProviderAdapter credentialProviderAdapter;
5555
private final CredentialsProvider credentialsProvider;
56-
private final long partSizeInBytes;
56+
private final Long partSizeInBytes;
5757
private final long thresholdInBytes;
5858
private final double targetThroughputInGbps;
5959
private final int maxConcurrency;
@@ -88,10 +88,8 @@ public S3NativeClientConfiguration(Builder builder) {
8888

8989
this.credentialsProvider = credentialProviderAdapter.crtCredentials();
9090

91-
this.partSizeInBytes = builder.partSizeInBytes == null ? DEFAULT_PART_SIZE_IN_BYTES :
92-
builder.partSizeInBytes;
93-
this.thresholdInBytes = builder.thresholdInBytes == null ? this.partSizeInBytes :
94-
builder.thresholdInBytes;
91+
this.partSizeInBytes = builder.partSizeInBytes;
92+
this.thresholdInBytes = resolveThresholdInBytes(builder);
9593
this.targetThroughputInGbps = builder.targetThroughputInGbps == null ?
9694
DEFAULT_TARGET_THROUGHPUT_IN_GBPS : builder.targetThroughputInGbps;
9795

@@ -101,8 +99,7 @@ public S3NativeClientConfiguration(Builder builder) {
10199

102100
this.endpointOverride = builder.endpointOverride;
103101

104-
this.readBufferSizeInBytes = builder.readBufferSizeInBytes == null ?
105-
partSizeInBytes * 10 : builder.readBufferSizeInBytes;
102+
this.readBufferSizeInBytes = resolveReadBufferSizeInBytes(builder);
106103

107104
if (builder.httpConfiguration != null) {
108105
this.proxyOptions = resolveProxy(builder.httpConfiguration.proxyConfiguration(), tlsContext).orElse(null);
@@ -120,6 +117,21 @@ public S3NativeClientConfiguration(Builder builder) {
120117
builder.advancedOptions == null ? null : builder.advancedOptions.get(CRT_MEMORY_BUFFER_DISABLED);
121118
}
122119

120+
private Long resolveReadBufferSizeInBytes(Builder builder) {
121+
if (builder.readBufferSizeInBytes != null) {
122+
return builder.readBufferSizeInBytes;
123+
}
124+
long partSize = this.partSizeInBytes == null ? DEFAULT_PART_SIZE_IN_BYTES : this.partSizeInBytes;
125+
return partSize * 10;
126+
}
127+
128+
private long resolveThresholdInBytes(Builder builder) {
129+
if (builder.thresholdInBytes != null) {
130+
return builder.thresholdInBytes;
131+
}
132+
return this.partSizeInBytes == null ? DEFAULT_PART_SIZE_IN_BYTES : this.partSizeInBytes;
133+
}
134+
123135
private static Boolean resolveUseEnvironmentVariableValues(Builder builder) {
124136
if (builder != null && builder.httpConfiguration != null && builder.httpConfiguration.proxyConfiguration() != null) {
125137
return builder.httpConfiguration.proxyConfiguration().isUseEnvironmentVariableValues();
@@ -164,7 +176,7 @@ public TlsContext tlsContext() {
164176
return tlsContext;
165177
}
166178

167-
public long partSizeBytes() {
179+
public Long partSizeBytes() {
168180
return partSizeInBytes;
169181
}
170182

services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/crt/S3CrtAsyncHttpClientTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,25 @@ void build_partSizeConfigured_shouldApplyToThreshold() {
509509
}
510510
}
511511

512+
@Test
513+
public void build_noPartSize_shouldUseDefaultsForThresholdAndReadWindowSize() {
514+
S3NativeClientConfiguration configuration =
515+
S3NativeClientConfiguration.builder()
516+
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test",
517+
"test")))
518+
.signingRegion("us-west-2")
519+
.build();
520+
try (S3CrtAsyncHttpClient client =
521+
(S3CrtAsyncHttpClient) S3CrtAsyncHttpClient.builder()
522+
.s3ClientConfiguration(configuration).build()) {
523+
long defaultPartSizeInBytes = 1024 * 1024L * 8L;
524+
S3ClientOptions clientOptions = client.s3ClientOptions();
525+
assertThat(clientOptions.getPartSize()).isEqualTo(0);
526+
assertThat(clientOptions.getMultiPartUploadThreshold()).isEqualTo(defaultPartSizeInBytes);
527+
assertThat(clientOptions.getInitialReadWindowSize()).isEqualTo(defaultPartSizeInBytes * 10);
528+
}
529+
}
530+
512531
@Test
513532
void build_nullHttpConfiguration() {
514533
S3NativeClientConfiguration configuration =

services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/crt/S3CrtClientGetObjectResourceManagementTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private static void stubGetObjectCalls() {
144144
}
145145

146146
// final part
147-
String contentRange = "bytes " + PART_SIZE * numOfParts + "-" + (totalContentSize - 1) + "/" + totalContentSize;
147+
String contentRange = "bytes " + PART_SIZE * (numOfParts - 1) + "-" + (totalContentSize - 1) + "/" + totalContentSize;
148148
String range = "bytes=" + PART_SIZE * (numOfParts - 1) + "-" + (totalContentSize - 1);
149149
stubFor(get(anyUrl()).withHeader("Range", equalTo(range)).willReturn(aResponse().withStatus(200)
150150
.withHeader("content-length", String.valueOf(finalPartSize))

test/s3-tests/src/it/java/software/amazon/awssdk/services/s3/regression/upload/UploadConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void setPayloadSigning(boolean payloadSigning) {
106106

107107
@Override
108108
public String toString() {
109-
return ToString.builder("FlattenUploadConfig")
109+
return ToString.builder("UploadConfig")
110110
.add("bucketType", bucketType)
111111
.add("forcePathStyle", forcePathStyle)
112112
.add("requestChecksumValidation", requestChecksumValidation)

test/s3-tests/src/it/java/software/amazon/awssdk/services/s3/regression/upload/UploadStreamingRegressionTesting.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ protected TestCallable<PutObjectResponse> callTmUpload(PutObjectRequest request,
176176
CompletedUpload completedUpload = CompletableFutureUtils.joinLikeSync(upload.completionFuture());
177177
return completedUpload.response();
178178
} catch (Exception e) {
179+
LOG.error(() -> "Upload failed for " + config.toString());
179180
throw new RuntimeException(e);
180181
} finally {
181182
transferManager.close();

0 commit comments

Comments
 (0)