Skip to content

Commit bb352a7

Browse files
committed
pass null part size to CRT when not configured
1 parent 10a69b7 commit bb352a7

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

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
@@ -104,7 +104,6 @@ private S3ClientOptions createS3ClientOption() {
104104
.withCredentialsProvider(s3NativeClientConfiguration.credentialsProvider())
105105
.withClientBootstrap(s3NativeClientConfiguration.clientBootstrap())
106106
.withTlsContext(s3NativeClientConfiguration.tlsContext())
107-
.withPartSize(s3NativeClientConfiguration.partSizeBytes())
108107
.withMultipartUploadThreshold(s3NativeClientConfiguration.thresholdInBytes())
109108
.withComputeContentMd5(false)
110109
.withEnableS3Express(true)
@@ -120,6 +119,7 @@ private S3ClientOptions createS3ClientOption() {
120119
if (Boolean.FALSE.equals(s3NativeClientConfiguration.isUseEnvironmentVariableValues())) {
121120
options.withProxyEnvironmentVariableSetting(disabledHttpProxyEnvironmentVariableSetting());
122121
}
122+
Optional.ofNullable(s3NativeClientConfiguration.partSizeBytes()).ifPresent(options::withPartSize);
123123
Optional.ofNullable(s3NativeClientConfiguration.proxyOptions()).ifPresent(options::withProxyOptions);
124124
Optional.ofNullable(s3NativeClientConfiguration.connectionTimeout())
125125
.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
@@ -51,7 +51,7 @@ public class S3NativeClientConfiguration implements SdkAutoCloseable {
5151
private final ClientBootstrap clientBootstrap;
5252
private final CrtCredentialsProviderAdapter credentialProviderAdapter;
5353
private final CredentialsProvider credentialsProvider;
54-
private final long partSizeInBytes;
54+
private final Long partSizeInBytes;
5555
private final long thresholdInBytes;
5656
private final double targetThroughputInGbps;
5757
private final int maxConcurrency;
@@ -85,10 +85,8 @@ public S3NativeClientConfiguration(Builder builder) {
8585

8686
this.credentialsProvider = credentialProviderAdapter.crtCredentials();
8787

88-
this.partSizeInBytes = builder.partSizeInBytes == null ? DEFAULT_PART_SIZE_IN_BYTES :
89-
builder.partSizeInBytes;
90-
this.thresholdInBytes = builder.thresholdInBytes == null ? this.partSizeInBytes :
91-
builder.thresholdInBytes;
88+
this.partSizeInBytes = builder.partSizeInBytes;
89+
this.thresholdInBytes = resolveThresholdInBytes(builder);
9290
this.targetThroughputInGbps = builder.targetThroughputInGbps == null ?
9391
DEFAULT_TARGET_THROUGHPUT_IN_GBPS : builder.targetThroughputInGbps;
9492

@@ -98,8 +96,7 @@ public S3NativeClientConfiguration(Builder builder) {
9896

9997
this.endpointOverride = builder.endpointOverride;
10098

101-
this.readBufferSizeInBytes = builder.readBufferSizeInBytes == null ?
102-
partSizeInBytes * 10 : builder.readBufferSizeInBytes;
99+
this.readBufferSizeInBytes = resolveReadBufferSizeInBytes(builder);
103100

104101
if (builder.httpConfiguration != null) {
105102
this.proxyOptions = resolveProxy(builder.httpConfiguration.proxyConfiguration(), tlsContext).orElse(null);
@@ -115,6 +112,21 @@ public S3NativeClientConfiguration(Builder builder) {
115112
this.useEnvironmentVariableProxyOptionsValues = resolveUseEnvironmentVariableValues(builder);
116113
}
117114

115+
private Long resolveReadBufferSizeInBytes(Builder builder) {
116+
if (builder.readBufferSizeInBytes != null) {
117+
return builder.readBufferSizeInBytes;
118+
}
119+
long partSize = this.partSizeInBytes == null ? DEFAULT_PART_SIZE_IN_BYTES : this.partSizeInBytes;
120+
return partSize * 10;
121+
}
122+
123+
private long resolveThresholdInBytes(Builder builder) {
124+
if (builder.thresholdInBytes != null) {
125+
return builder.thresholdInBytes;
126+
}
127+
return this.partSizeInBytes == null ? DEFAULT_PART_SIZE_IN_BYTES : this.partSizeInBytes;
128+
}
129+
118130
private static Boolean resolveUseEnvironmentVariableValues(Builder builder) {
119131
if (builder != null && builder.httpConfiguration != null && builder.httpConfiguration.proxyConfiguration() != null) {
120132
return builder.httpConfiguration.proxyConfiguration().isUseEnvironmentVariableValues();
@@ -159,7 +171,7 @@ public TlsContext tlsContext() {
159171
return tlsContext;
160172
}
161173

162-
public long partSizeBytes() {
174+
public Long partSizeBytes() {
163175
return partSizeInBytes;
164176
}
165177

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
@@ -486,6 +486,25 @@ void build_partSizeConfigured_shouldApplyToThreshold() {
486486
}
487487
}
488488

489+
@Test
490+
public void build_noPartSize_shouldUseDefaultsForThresholdAndReadWindowSize() {
491+
S3NativeClientConfiguration configuration =
492+
S3NativeClientConfiguration.builder()
493+
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test",
494+
"test")))
495+
.signingRegion("us-west-2")
496+
.build();
497+
try (S3CrtAsyncHttpClient client =
498+
(S3CrtAsyncHttpClient) S3CrtAsyncHttpClient.builder()
499+
.s3ClientConfiguration(configuration).build()) {
500+
long defaultPartSizeInBytes = 1024 * 1024L * 8L;
501+
S3ClientOptions clientOptions = client.s3ClientOptions();
502+
assertThat(clientOptions.getPartSize()).isEqualTo(0);
503+
assertThat(clientOptions.getMultiPartUploadThreshold()).isEqualTo(defaultPartSizeInBytes);
504+
assertThat(clientOptions.getInitialReadWindowSize()).isEqualTo(defaultPartSizeInBytes * 10);
505+
}
506+
}
507+
489508
@Test
490509
void build_nullHttpConfiguration() {
491510
S3NativeClientConfiguration configuration =

0 commit comments

Comments
 (0)