Package org.apache.hadoop.fs.s3a
Class WriteOperationHelper
java.lang.Object
org.apache.hadoop.fs.s3a.WriteOperationHelper
- All Implemented Interfaces:
Closeable,AutoCloseable,WriteOperations,org.apache.hadoop.fs.store.audit.AuditSpanSource
Helper for low-level operations against an S3 Bucket for writing data,
creating and committing pending writes, and other S3-layer operations.
It hides direct access to the S3 API and is a location where the object operations can be evolved/enhanced.
Features
- Methods to create and submit requests to S3, so avoiding all direct interaction with the AWS APIs.
- Some extra preflight checks of arguments, so failing fast on errors.
- Callbacks to let the FS know of events in the output stream upload process.
- Other low-level access to S3 functions, for private use.
- Failure handling, including converting exceptions to IOEs.
- Integration with instrumentation.
- A nested class in S3AFileSystem - Single shared instance created and reused. - [HADOOP-13786] A separate class, single instance in S3AFS - [HDFS-13934] Split into interface and implementation - [HADOOP-15711] Adds audit tracking; one instance per use.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallbacks for writeOperationHelper. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWriteOperationHelper(S3AFileSystem owner, org.apache.hadoop.conf.Configuration conf, S3AStatisticsContext statisticsContext, org.apache.hadoop.fs.store.audit.AuditSpanSource auditSpanSource, org.apache.hadoop.fs.store.audit.AuditSpan auditSpan, WriteOperationHelper.WriteOperationHelperCallbacks writeOperationHelperCallbacks) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidabortMultipartCommit(String destKey, String uploadId) Abort a multipart commit operation.voidabortMultipartUpload(String destKey, String uploadId, boolean shouldRetry, Invoker.Retried retrying) Abort a multipart upload operation.voidabortMultipartUpload(software.amazon.awssdk.services.s3.model.MultipartUpload upload) Abort a multipart commit operation.intabortMultipartUploadsUnderPath(String prefix) Abort multipart uploads under a path: limited to the first few hundred.voidclose()Deactivate the audit span.software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponsecommitUpload(String destKey, String uploadId, List<software.amazon.awssdk.services.s3.model.CompletedPart> partETags, long length) This completes a multipart upload to the destination key viafinalizeMultipartUpload().software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponsecompleteMPUwithRetries(String destKey, String uploadId, List<software.amazon.awssdk.services.s3.model.CompletedPart> partETags, long length, AtomicInteger errorCount, PutObjectOptions putOptions) This completes a multipart upload to the destination key viafinalizeMultipartUpload().software.amazon.awssdk.services.s3.model.PutObjectRequestcreatePutObjectRequest(String destKey, long length, PutObjectOptions options) Create aPutObjectRequestrequest against the specific key.org.apache.hadoop.fs.store.audit.AuditSpancreateSpan(String operation, String path1, String path2) org.apache.hadoop.fs.store.audit.AuditSpanGet the audit span this object was created with.org.apache.hadoop.conf.ConfigurationgetConf()Get the configuration of this instance; essentially the owning filesystem configuration.Get the request factory which uses this store's audit span.voidIncrement the write operation counter of the filesystem.initiateMultiPartUpload(String destKey, PutObjectOptions options) Start the multipart upload process.List<software.amazon.awssdk.services.s3.model.MultipartUpload>listMultipartUploads(String prefix) List in-progress multipart uploads under a path: limited to the first few hundred.software.amazon.awssdk.services.s3.model.UploadPartRequest.BuildernewUploadPartRequestBuilder(String destKey, String uploadId, int partNumber, boolean isLastPart, long size) Create and initialize a part request builder of a multipart upload.software.amazon.awssdk.services.s3.model.PutObjectResponseputObject(software.amazon.awssdk.services.s3.model.PutObjectRequest putObjectRequest, PutObjectOptions putOptions, S3ADataBlocks.BlockUploadData uploadData, org.apache.hadoop.fs.statistics.DurationTrackerFactory durationTrackerFactory) PUT an object directly (i.e. not via the transfer manager).<T> Tretry(String action, String path, boolean idempotent, org.apache.hadoop.util.functional.CallableRaisingIOE<T> operation) Execute a function with retry processing.voidrevertCommit(String destKey) Revert a commit by deleting the file.toString()The toString method is intended to be used in logging/toString calls.software.amazon.awssdk.services.s3.model.UploadPartResponseuploadPart(software.amazon.awssdk.services.s3.model.UploadPartRequest request, software.amazon.awssdk.core.sync.RequestBody body, org.apache.hadoop.fs.statistics.DurationTrackerFactory durationTrackerFactory) Upload part of a multi-partition file.voidwriteFailed(Exception ex) Callback on a write failure.voidwriteSuccessful(long length) Callback on a successful write.
-
Constructor Details
-
WriteOperationHelper
protected WriteOperationHelper(S3AFileSystem owner, org.apache.hadoop.conf.Configuration conf, S3AStatisticsContext statisticsContext, org.apache.hadoop.fs.store.audit.AuditSpanSource auditSpanSource, org.apache.hadoop.fs.store.audit.AuditSpan auditSpan, WriteOperationHelper.WriteOperationHelperCallbacks writeOperationHelperCallbacks) Constructor.- Parameters:
owner- owner FS creating the helperconf- Configuration objectstatisticsContext- statistics contextauditSpanSource- source of spansauditSpan- span to activatewriteOperationHelperCallbacks- callbacks used by writeOperationHelper
-
-
Method Details
-
retry
public <T> T retry(String action, String path, boolean idempotent, org.apache.hadoop.util.functional.CallableRaisingIOE<T> operation) throws IOException Execute a function with retry processing. Also activates the current span.- Specified by:
retryin interfaceWriteOperations- Type Parameters:
T- type of return value- Parameters:
action- action to execute (used in error messages)path- path of work (used in error messages)idempotent- does the operation have semantics which mean that it can be retried even if was already executed?operation- operation to execute- Returns:
- the result of the call
- Throws:
IOException- any IOE raised, or translated exception
-
getAuditSpan
public org.apache.hadoop.fs.store.audit.AuditSpan getAuditSpan()Get the audit span this object was created with.- Returns:
- the audit span
-
createPutObjectRequest
@OnceRaw public software.amazon.awssdk.services.s3.model.PutObjectRequest createPutObjectRequest(String destKey, long length, PutObjectOptions options) Create aPutObjectRequestrequest against the specific key.- Specified by:
createPutObjectRequestin interfaceWriteOperations- Parameters:
destKey- destination keylength- size, if known. Use -1 for not knownoptions- options for the request- Returns:
- the request
-
writeSuccessful
public void writeSuccessful(long length) Callback on a successful write.- Specified by:
writeSuccessfulin interfaceWriteOperations- Parameters:
length- length of the write
-
writeFailed
Callback on a write failure.- Specified by:
writeFailedin interfaceWriteOperations- Parameters:
ex- Any exception raised which triggered the failure.
-
initiateMultiPartUpload
@RetryTranslated public String initiateMultiPartUpload(String destKey, PutObjectOptions options) throws IOException Start the multipart upload process. Retry policy: retrying, translated.- Specified by:
initiateMultiPartUploadin interfaceWriteOperations- Parameters:
destKey- destination of uploadoptions- options for the put request- Returns:
- the upload result containing the ID
- Throws:
IOException- IO problem
-
completeMPUwithRetries
@RetryTranslated public software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse completeMPUwithRetries(String destKey, String uploadId, List<software.amazon.awssdk.services.s3.model.CompletedPart> partETags, long length, AtomicInteger errorCount, PutObjectOptions putOptions) throws IOException This completes a multipart upload to the destination key viafinalizeMultipartUpload(). Retry policy: retrying, translated. Retries increment theerrorCountcounter.- Specified by:
completeMPUwithRetriesin interfaceWriteOperations- Parameters:
destKey- destinationuploadId- multipart operation IdpartETags- list of partial uploadslength- length of the uploaderrorCount- a counter incremented by 1 on every error; for use in statisticsputOptions- put object options- Returns:
- the result of the operation.
- Throws:
IOException- if problems arose which could not be retried, or the retry count was exceeded
-
abortMultipartUpload
@RetryTranslated public void abortMultipartUpload(String destKey, String uploadId, boolean shouldRetry, Invoker.Retried retrying) throws IOException Abort a multipart upload operation.- Specified by:
abortMultipartUploadin interfaceWriteOperations- Parameters:
destKey- destination key of the uploaduploadId- multipart operation IdshouldRetry- should failures trigger a retry?retrying- callback invoked on every retry- Throws:
IOException- failure to abortFileNotFoundException- if the abort ID is unknown
-
abortMultipartUpload
@RetryTranslated public void abortMultipartUpload(software.amazon.awssdk.services.s3.model.MultipartUpload upload) throws FileNotFoundException, IOException Abort a multipart commit operation.- Specified by:
abortMultipartUploadin interfaceWriteOperations- Parameters:
upload- upload to abort.- Throws:
FileNotFoundException- if the upload is unknownIOException- on problems.
-
abortMultipartUploadsUnderPath
Abort multipart uploads under a path: limited to the first few hundred.- Specified by:
abortMultipartUploadsUnderPathin interfaceWriteOperations- Parameters:
prefix- prefix for uploads to abort- Returns:
- a count of aborts
- Throws:
IOException- trouble; FileNotFoundExceptions are swallowed.
-
listMultipartUploads
@RetryTranslated public List<software.amazon.awssdk.services.s3.model.MultipartUpload> listMultipartUploads(String prefix) throws IOException Description copied from interface:WriteOperationsList in-progress multipart uploads under a path: limited to the first few hundred.- Specified by:
listMultipartUploadsin interfaceWriteOperations- Parameters:
prefix- prefix for uploads to list- Returns:
- a list of in-progress multipart uploads
- Throws:
IOException- on problems
-
abortMultipartCommit
@RetryTranslated public void abortMultipartCommit(String destKey, String uploadId) throws IOException Abort a multipart commit operation.- Specified by:
abortMultipartCommitin interfaceWriteOperations- Parameters:
destKey- destination key of ongoing operationuploadId- multipart operation Id- Throws:
IOException- on problems.FileNotFoundException- if the abort ID is unknown
-
newUploadPartRequestBuilder
@OnceTranslated public software.amazon.awssdk.services.s3.model.UploadPartRequest.Builder newUploadPartRequestBuilder(String destKey, String uploadId, int partNumber, boolean isLastPart, long size) throws IOException Create and initialize a part request builder of a multipart upload. The part number must be less than 10000. Retry policy is once-translated; to much effort- Specified by:
newUploadPartRequestBuilderin interfaceWriteOperations- Parameters:
destKey- destination key of ongoing operationuploadId- ID of ongoing uploadpartNumber- current part number of the uploadisLastPart- is this the last part?size- amount of data- Returns:
- the request builder.
- Throws:
IllegalArgumentException- if the parameters are invalid.org.apache.hadoop.fs.PathIOException- if the part number is out of range.PathIOException- if the part number is out of range.IOException
-
toString
The toString method is intended to be used in logging/toString calls. -
putObject
@RetryTranslated public software.amazon.awssdk.services.s3.model.PutObjectResponse putObject(software.amazon.awssdk.services.s3.model.PutObjectRequest putObjectRequest, PutObjectOptions putOptions, S3ADataBlocks.BlockUploadData uploadData, org.apache.hadoop.fs.statistics.DurationTrackerFactory durationTrackerFactory) throws IOException PUT an object directly (i.e. not via the transfer manager). Byte length is calculated from the file length, or, if there is no file, from the content length of the header.- Specified by:
putObjectin interfaceWriteOperations- Parameters:
putObjectRequest- the requestputOptions- put object optionsuploadData- data to be uploadeddurationTrackerFactory- factory for duration tracking- Returns:
- the upload initiated
- Throws:
IOException- on problems
-
revertCommit
Revert a commit by deleting the file. Relies on retry code in filesystem. Does not attempt to recreate the parent directory- Specified by:
revertCommitin interfaceWriteOperations- Parameters:
destKey- destination key- Throws:
IOException- on problems
-
commitUpload
@RetryTranslated public software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse commitUpload(String destKey, String uploadId, List<software.amazon.awssdk.services.s3.model.CompletedPart> partETags, long length) throws IOException This completes a multipart upload to the destination key viafinalizeMultipartUpload(). Retry policy: retrying, translated. Retries increment theerrorCountcounter.- Specified by:
commitUploadin interfaceWriteOperations- Parameters:
destKey- destinationuploadId- multipart operation IdpartETags- list of partial uploadslength- length of the upload- Returns:
- the result of the operation.
- Throws:
IOException- if problems arose which could not be retried, or the retry count was exceeded
-
uploadPart
@RetryTranslated public software.amazon.awssdk.services.s3.model.UploadPartResponse uploadPart(software.amazon.awssdk.services.s3.model.UploadPartRequest request, software.amazon.awssdk.core.sync.RequestBody body, org.apache.hadoop.fs.statistics.DurationTrackerFactory durationTrackerFactory) throws IOException Upload part of a multi-partition file.- Specified by:
uploadPartin interfaceWriteOperations- Parameters:
durationTrackerFactory- duration tracker factory for operationrequest- the upload part request.body- the request body.- Returns:
- the result of the operation.
- Throws:
IOException- on problems
-
getConf
public org.apache.hadoop.conf.Configuration getConf()Get the configuration of this instance; essentially the owning filesystem configuration.- Specified by:
getConfin interfaceWriteOperations- Returns:
- the configuration.
-
createSpan
public org.apache.hadoop.fs.store.audit.AuditSpan createSpan(String operation, @Nullable String path1, @Nullable String path2) throws IOException - Specified by:
createSpanin interfaceorg.apache.hadoop.fs.store.audit.AuditSpanSource- Throws:
IOException
-
incrementWriteOperations
public void incrementWriteOperations()Description copied from interface:WriteOperationsIncrement the write operation counter of the filesystem.- Specified by:
incrementWriteOperationsin interfaceWriteOperations
-
close
Deactivate the audit span.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getRequestFactory
Get the request factory which uses this store's audit span.- Returns:
- the request factory.
-