18
18
19
19
package org .apache .hadoop .fs .s3a .impl ;
20
20
21
+ import java .time .Duration ;
21
22
import java .util .Base64 ;
22
23
import java .util .HashMap ;
23
24
import java .util .List ;
59
60
import org .apache .hadoop .fs .s3a .auth .delegation .EncryptionSecrets ;
60
61
61
62
import static org .apache .commons .lang3 .StringUtils .isNotEmpty ;
63
+ import static org .apache .hadoop .fs .s3a .Constants .DEFAULT_PART_UPLOAD_TIMEOUT ;
62
64
import static org .apache .hadoop .fs .s3a .S3AEncryptionMethods .UNKNOWN_ALGORITHM ;
65
+ import static org .apache .hadoop .fs .s3a .impl .AWSClientConfig .setRequestTimeout ;
63
66
import static org .apache .hadoop .fs .s3a .impl .InternalConstants .DEFAULT_UPLOAD_PART_COUNT_LIMIT ;
64
67
import static org .apache .hadoop .util .Preconditions .checkArgument ;
65
68
import static org .apache .hadoop .util .Preconditions .checkNotNull ;
@@ -128,6 +131,12 @@ public class RequestFactoryImpl implements RequestFactory {
128
131
*/
129
132
private final boolean isMultipartUploadEnabled ;
130
133
134
+ /**
135
+ * Timeout for uploading objects/parts.
136
+ * This will be set on data put/post operations only.
137
+ */
138
+ private final Duration partUploadTimeout ;
139
+
131
140
/**
132
141
* Constructor.
133
142
* @param builder builder with all the configuration.
@@ -142,6 +151,7 @@ protected RequestFactoryImpl(
142
151
this .contentEncoding = builder .contentEncoding ;
143
152
this .storageClass = builder .storageClass ;
144
153
this .isMultipartUploadEnabled = builder .isMultipartUploadEnabled ;
154
+ this .partUploadTimeout = builder .partUploadTimeout ;
145
155
}
146
156
147
157
/**
@@ -338,6 +348,11 @@ public PutObjectRequest.Builder newPutObjectRequestBuilder(String key,
338
348
putObjectRequestBuilder .storageClass (storageClass );
339
349
}
340
350
351
+ // Set the timeout for object uploads but not directory markers.
352
+ if (!isDirectoryMarker ) {
353
+ setRequestTimeout (putObjectRequestBuilder , partUploadTimeout );
354
+ }
355
+
341
356
return prepareRequest (putObjectRequestBuilder );
342
357
}
343
358
@@ -581,6 +596,9 @@ public UploadPartRequest.Builder newUploadPartRequestBuilder(
581
596
.partNumber (partNumber )
582
597
.contentLength (size );
583
598
uploadPartEncryptionParameters (builder );
599
+
600
+ // Set the request timeout for the part upload
601
+ setRequestTimeout (builder , partUploadTimeout );
584
602
return prepareRequest (builder );
585
603
}
586
604
@@ -688,6 +706,13 @@ public static final class RequestFactoryBuilder {
688
706
*/
689
707
private boolean isMultipartUploadEnabled = true ;
690
708
709
+ /**
710
+ * Timeout for uploading objects/parts.
711
+ * This will be set on data put/post operations only.
712
+ * A zero value means "no custom timeout"
713
+ */
714
+ private Duration partUploadTimeout = DEFAULT_PART_UPLOAD_TIMEOUT ;
715
+
691
716
private RequestFactoryBuilder () {
692
717
}
693
718
@@ -785,6 +810,18 @@ public RequestFactoryBuilder withMultipartUploadEnabled(
785
810
this .isMultipartUploadEnabled = value ;
786
811
return this ;
787
812
}
813
+
814
+ /**
815
+ * Timeout for uploading objects/parts.
816
+ * This will be set on data put/post operations only.
817
+ * A zero value means "no custom timeout"
818
+ * @param value new value
819
+ * @return the builder
820
+ */
821
+ public RequestFactoryBuilder withPartUploadTimeout (final Duration value ) {
822
+ partUploadTimeout = value ;
823
+ return this ;
824
+ }
788
825
}
789
826
790
827
/**
0 commit comments