Skip to content

Commit 426d82d

Browse files
committed
add ParallelConfiguration for maxInFlightParts
1 parent 0aa1529 commit 426d82d

6 files changed

Lines changed: 128 additions & 24 deletions

File tree

services/s3/src/it/java/software/amazon/awssdk/services/s3/multipart/S3MultipartClientFileDownloadIntegrationTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public void init() {
8787
this.interceptor = new TestInterceptor();
8888
this.s3Client = S3AsyncClient.builder()
8989
.multipartEnabled(true)
90-
.multipartConfiguration(c -> c.maxInflightDownloads(50))
9190
.overrideConfiguration(o -> o.addExecutionInterceptor(this.interceptor))
9291
.credentialsProvider(CREDENTIALS_PROVIDER_CHAIN)
9392
.build();

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/multipart/MultipartConfigurationResolver.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import software.amazon.awssdk.annotations.SdkInternalApi;
1919
import software.amazon.awssdk.services.s3.multipart.MultipartConfiguration;
20+
import software.amazon.awssdk.services.s3.multipart.ParallelConfiguration;
2021
import software.amazon.awssdk.utils.Validate;
2122

2223
/**
@@ -26,11 +27,12 @@
2627
public final class MultipartConfigurationResolver {
2728

2829
private static final long DEFAULT_MIN_PART_SIZE = 8L * 1024 * 1024;
29-
private static final int DEFAULT_MAX_IN_FLIGHT = 50;
30+
private static final int DEFAULT_MAX_IN_FLIGHT_PARTS = 50;
31+
3032
private final long minimalPartSizeInBytes;
3133
private final long apiCallBufferSize;
3234
private final long thresholdInBytes;
33-
private final int maxInFlight;
35+
private final int maxInFlightParts;
3436

3537
public MultipartConfigurationResolver(MultipartConfiguration multipartConfiguration) {
3638
Validate.notNull(multipartConfiguration, "multipartConfiguration");
@@ -39,7 +41,13 @@ public MultipartConfigurationResolver(MultipartConfiguration multipartConfigurat
3941
this.apiCallBufferSize = Validate.getOrDefault(multipartConfiguration.apiCallBufferSizeInBytes(),
4042
() -> minimalPartSizeInBytes * 4);
4143
this.thresholdInBytes = Validate.getOrDefault(multipartConfiguration.thresholdInBytes(), () -> minimalPartSizeInBytes);
42-
this.maxInFlight = Validate.getOrDefault(multipartConfiguration.maxInflightDownloads(), () -> DEFAULT_MAX_IN_FLIGHT);
44+
ParallelConfiguration parallelConfiguration = multipartConfiguration.parallelConfiguration();
45+
if (parallelConfiguration == null) {
46+
this.maxInFlightParts = DEFAULT_MAX_IN_FLIGHT_PARTS;
47+
} else {
48+
this.maxInFlightParts = Validate.getOrDefault(multipartConfiguration.parallelConfiguration().maxInFlightParts(),
49+
() -> DEFAULT_MAX_IN_FLIGHT_PARTS);
50+
}
4351
}
4452

4553
public long minimalPartSizeInBytes() {
@@ -54,7 +62,7 @@ public long apiCallBufferSize() {
5462
return apiCallBufferSize;
5563
}
5664

57-
public int maxInFlight() {
58-
return maxInFlight;
65+
public int maxInFlightParts() {
66+
return maxInFlightParts;
5967
}
6068
}

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/multipart/MultipartS3AsyncClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private MultipartS3AsyncClient(S3AsyncClient delegate, MultipartConfiguration mu
6363
long minPartSizeInBytes = resolver.minimalPartSizeInBytes();
6464
long threshold = resolver.thresholdInBytes();
6565
long apiCallBufferSize = resolver.apiCallBufferSize();
66-
int maxInFLight = resolver.maxInFlight();
66+
int maxInFLight = resolver.maxInFlightParts();
6767
mpuHelper = new UploadObjectHelper(delegate, resolver);
6868
copyObjectHelper = new CopyObjectHelper(delegate, minPartSizeInBytes, threshold);
6969
downloadObjectHelper = new DownloadObjectHelper(delegate, apiCallBufferSize, maxInFLight);

services/s3/src/main/java/software/amazon/awssdk/services/s3/multipart/MultipartConfiguration.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package software.amazon.awssdk.services.s3.multipart;
1717

18+
import java.util.function.Consumer;
1819
import software.amazon.awssdk.annotations.SdkPublicApi;
1920
import software.amazon.awssdk.core.async.AsyncRequestBody;
2021
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
@@ -44,13 +45,13 @@ public final class MultipartConfiguration implements ToCopyableBuilder<Multipart
4445
private final Long thresholdInBytes;
4546
private final Long minimumPartSizeInBytes;
4647
private final Long apiCallBufferSizeInBytes;
47-
private final Integer maxInflightDownloads;
48+
private final ParallelConfiguration parallelConfiguration;;
4849

4950
private MultipartConfiguration(DefaultMultipartConfigBuilder builder) {
5051
this.thresholdInBytes = builder.thresholdInBytes;
5152
this.minimumPartSizeInBytes = builder.minimumPartSizeInBytes;
5253
this.apiCallBufferSizeInBytes = builder.apiCallBufferSizeInBytes;
53-
this.maxInflightDownloads = builder.maxInflightDownloads;
54+
this.parallelConfiguration = builder.parallelConfiguration;
5455
}
5556

5657
public static Builder builder() {
@@ -91,8 +92,12 @@ public Long apiCallBufferSizeInBytes() {
9192
return this.apiCallBufferSizeInBytes;
9293
}
9394

94-
public Integer maxInflightDownloads() {
95-
return this.maxInflightDownloads;
95+
/**
96+
*
97+
* @return
98+
*/
99+
public ParallelConfiguration parallelConfiguration() {
100+
return this.parallelConfiguration;
96101
}
97102

98103
/**
@@ -172,52 +177,65 @@ public interface Builder extends CopyableBuilder<Builder, MultipartConfiguration
172177

173178
/**
174179
* todo
175-
* @param maxInflightDownloads
180+
* @param
176181
* @return
177182
*/
178-
Builder maxInflightDownloads(Integer maxInflightDownloads);
183+
Builder parallelConfiguration(ParallelConfiguration parallelConfiguration);
184+
185+
Builder parallelConfiguration(Consumer<ParallelConfiguration.Builder> consumer);
179186

180187
/**
181188
* todo
182189
* @return
183190
*/
184-
Integer maxInflightDownloads();
191+
ParallelConfiguration parallelConfiguration();
185192

186193
}
187194

188195
private static class DefaultMultipartConfigBuilder implements Builder {
189196
private Long thresholdInBytes;
190197
private Long minimumPartSizeInBytes;
191198
private Long apiCallBufferSizeInBytes;
192-
private Integer maxInflightDownloads;
199+
private ParallelConfiguration parallelConfiguration;
193200

201+
@Override
194202
public Builder thresholdInBytes(Long thresholdInBytes) {
195203
this.thresholdInBytes = thresholdInBytes;
196204
return this;
197205
}
198206

207+
@Override
199208
public Long thresholdInBytes() {
200209
return this.thresholdInBytes;
201210
}
202211

212+
@Override
203213
public Builder minimumPartSizeInBytes(Long minimumPartSizeInBytes) {
204214
this.minimumPartSizeInBytes = minimumPartSizeInBytes;
205215
return this;
206216
}
207217

218+
@Override
208219
public Long minimumPartSizeInBytes() {
209220
return this.minimumPartSizeInBytes;
210221
}
211222

212223
@Override
213-
public Builder maxInflightDownloads(Integer maxInflightDownloads) {
214-
this.maxInflightDownloads = maxInflightDownloads;
224+
public Builder parallelConfiguration(ParallelConfiguration parallelConfiguration) {
225+
this.parallelConfiguration = parallelConfiguration;
215226
return this;
216227
}
217228

218229
@Override
219-
public Integer maxInflightDownloads() {
220-
return this.maxInflightDownloads;
230+
public Builder parallelConfiguration(Consumer<ParallelConfiguration.Builder> configuration) {
231+
ParallelConfiguration.Builder builder = ParallelConfiguration.builder();
232+
configuration.accept(builder);
233+
return parallelConfiguration(builder.build());
234+
}
235+
236+
@Override
237+
public ParallelConfiguration parallelConfiguration() {
238+
return this.parallelConfiguration;
221239
}
222240

223241
@Override
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.s3.multipart;
17+
18+
import software.amazon.awssdk.annotations.SdkPublicApi;
19+
import software.amazon.awssdk.utils.builder.CopyableBuilder;
20+
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
21+
22+
@SdkPublicApi
23+
public class ParallelConfiguration implements ToCopyableBuilder<ParallelConfiguration.Builder, ParallelConfiguration> {
24+
25+
private final Integer maxInFlightParts;
26+
27+
public ParallelConfiguration(Builder builder) {
28+
this.maxInFlightParts = builder.maxInFlightParts;
29+
}
30+
31+
public static Builder builder() {
32+
return new Builder();
33+
}
34+
35+
public Integer maxInFlightParts() {
36+
return maxInFlightParts;
37+
}
38+
39+
@Override
40+
public Builder toBuilder() {
41+
return builder().maxInFlightParts(maxInFlightParts);
42+
}
43+
44+
public static class Builder implements CopyableBuilder<Builder, ParallelConfiguration> {
45+
private int maxInFlightParts;
46+
47+
public Builder maxInFlightParts(int maxInFlightParts) {
48+
this.maxInFlightParts = maxInFlightParts;
49+
return this;
50+
}
51+
52+
public int maxInFlightParts() {
53+
return maxInFlightParts;
54+
}
55+
56+
@Override
57+
public ParallelConfiguration build() {
58+
return new ParallelConfiguration(this);
59+
}
60+
}
61+
}

services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/multipart/MultipartConfigurationResolverTest.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.junit.jupiter.api.Test;
2121
import software.amazon.awssdk.services.s3.multipart.MultipartConfiguration;
22+
import software.amazon.awssdk.services.s3.multipart.ParallelConfiguration;
2223

2324
public class MultipartConfigurationResolverTest {
2425

@@ -59,17 +60,32 @@ void resolveApiCallBufferSize_valueNotProvided_shouldComputeBasedOnPartSize() {
5960
assertThat(resolver.apiCallBufferSize()).isEqualTo(40L);
6061
}
6162

63+
@Test
64+
void resolveMaxInFlightParts_valueProvidedWithBuilder_shouldHonor() {
65+
MultipartConfiguration configuration =
66+
MultipartConfiguration.builder()
67+
.parallelConfiguration(p -> p.maxInFlightParts(1))
68+
.build();
69+
MultipartConfigurationResolver resolver = new MultipartConfigurationResolver(configuration);
70+
assertThat(resolver.maxInFlightParts()).isEqualTo(1);
71+
}
72+
6273
@Test
6374
void valueProvidedForAllFields_shouldHonor() {
64-
MultipartConfiguration configuration = MultipartConfiguration.builder()
65-
.minimumPartSizeInBytes(10L)
66-
.thresholdInBytes(8L)
67-
.apiCallBufferSizeInBytes(3L)
68-
.build();
75+
MultipartConfiguration configuration =
76+
MultipartConfiguration.builder()
77+
.minimumPartSizeInBytes(10L)
78+
.thresholdInBytes(8L)
79+
.apiCallBufferSizeInBytes(3L)
80+
.parallelConfiguration(ParallelConfiguration.builder()
81+
.maxInFlightParts(1)
82+
.build())
83+
.build();
6984
MultipartConfigurationResolver resolver = new MultipartConfigurationResolver(configuration);
7085
assertThat(resolver.minimalPartSizeInBytes()).isEqualTo(10L);
7186
assertThat(resolver.thresholdInBytes()).isEqualTo(8L);
7287
assertThat(resolver.apiCallBufferSize()).isEqualTo(3L);
88+
assertThat(resolver.maxInFlightParts()).isEqualTo(1);
7389
}
7490

7591
@Test
@@ -79,5 +95,7 @@ void noValueProvided_shouldUseDefault() {
7995
assertThat(resolver.minimalPartSizeInBytes()).isEqualTo(8L * 1024 * 1024);
8096
assertThat(resolver.thresholdInBytes()).isEqualTo(8L * 1024 * 1024);
8197
assertThat(resolver.apiCallBufferSize()).isEqualTo(8L * 1024 * 1024 * 4);
98+
assertThat(resolver.maxInFlightParts()).isEqualTo(50);
8299
}
100+
83101
}

0 commit comments

Comments
 (0)