@InterfaceAudience.Private @InterfaceStability.Unstable public class WriteOperationHelper extends Object implements WriteOperations
It hides direct access to the S3 API and is a location where the object operations can be evolved/enhanced.
Features
- 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.
Modifier and Type | Class and Description |
---|---|
static interface |
WriteOperationHelper.WriteOperationHelperCallbacks
Callbacks for writeOperationHelper.
|
Modifier | Constructor and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
abortMultipartCommit(String destKey,
String uploadId)
Abort a multipart commit operation.
|
void |
abortMultipartUpload(software.amazon.awssdk.services.s3.model.MultipartUpload upload)
Abort a multipart commit operation.
|
void |
abortMultipartUpload(String destKey,
String uploadId,
boolean shouldRetry,
Invoker.Retried retrying)
Abort a multipart upload operation.
|
int |
abortMultipartUploadsUnderPath(String prefix)
Abort multipart uploads under a path: limited to the first
few hundred.
|
void |
close()
Deactivate the audit span.
|
software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse |
commitUpload(String destKey,
String uploadId,
List<software.amazon.awssdk.services.s3.model.CompletedPart> partETags,
long length)
This completes a multipart upload to the destination key via
finalizeMultipartUpload() . |
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)
This completes a multipart upload to the destination key via
finalizeMultipartUpload() . |
software.amazon.awssdk.services.s3.model.PutObjectRequest |
createPutObjectRequest(String destKey,
long length,
PutObjectOptions options,
boolean isFile)
Create a
PutObjectRequest request against the specific key. |
org.apache.hadoop.fs.store.audit.AuditSpan |
createSpan(String operation,
String path1,
String path2) |
org.apache.hadoop.fs.store.audit.AuditSpan |
getAuditSpan()
Get the audit span this object was created with.
|
org.apache.hadoop.conf.Configuration |
getConf()
Get the configuration of this instance; essentially the owning
filesystem configuration.
|
RequestFactory |
getRequestFactory()
Get the request factory which uses this store's audit span.
|
void |
incrementWriteOperations()
Increment the write operation counter
of the filesystem.
|
String |
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.Builder |
newUploadPartRequestBuilder(String destKey,
String uploadId,
int partNumber,
long size)
Create and initialize a part request builder of a multipart upload.
|
software.amazon.awssdk.services.s3.model.PutObjectResponse |
putObject(software.amazon.awssdk.services.s3.model.PutObjectRequest putObjectRequest,
PutObjectOptions putOptions,
S3ADataBlocks.BlockUploadData uploadData,
boolean isFile,
org.apache.hadoop.fs.statistics.DurationTrackerFactory durationTrackerFactory)
PUT an object directly (i.e.
|
<T> T |
retry(String action,
String path,
boolean idempotent,
org.apache.hadoop.util.functional.CallableRaisingIOE<T> operation)
Execute a function with retry processing.
|
void |
revertCommit(String destKey)
Revert a commit by deleting the file.
|
String |
toString()
The toString method is intended to be used in logging/toString calls.
|
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)
Upload part of a multi-partition file.
|
void |
writeFailed(Exception ex)
Callback on a write failure.
|
void |
writeSuccessful(long length)
Callback on a successful write.
|
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)
owner
- owner FS creating the helperconf
- Configuration objectstatisticsContext
- statistics contextauditSpanSource
- source of spansauditSpan
- span to activatewriteOperationHelperCallbacks
- callbacks used by writeOperationHelperpublic <T> T retry(String action, String path, boolean idempotent, org.apache.hadoop.util.functional.CallableRaisingIOE<T> operation) throws IOException
retry
in interface WriteOperations
T
- type of return valueaction
- 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 executeIOException
- any IOE raised, or translated exceptionpublic org.apache.hadoop.fs.store.audit.AuditSpan getAuditSpan()
@Retries.OnceRaw public software.amazon.awssdk.services.s3.model.PutObjectRequest createPutObjectRequest(String destKey, long length, PutObjectOptions options, boolean isFile)
PutObjectRequest
request against the specific key.createPutObjectRequest
in interface WriteOperations
destKey
- destination keylength
- size, if known. Use -1 for not knownoptions
- options for the requestisFile
- is data to be uploaded a filepublic void writeSuccessful(long length)
writeSuccessful
in interface WriteOperations
length
- length of the writepublic void writeFailed(Exception ex)
writeFailed
in interface WriteOperations
ex
- Any exception raised which triggered the failure.@Retries.RetryTranslated public String initiateMultiPartUpload(String destKey, PutObjectOptions options) throws IOException
initiateMultiPartUpload
in interface WriteOperations
destKey
- destination of uploadoptions
- options for the put requestIOException
- IO problem@Retries.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
finalizeMultipartUpload()
.
Retry policy: retrying, translated.
Retries increment the errorCount
counter.completeMPUwithRetries
in interface WriteOperations
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 optionsIOException
- if problems arose which could not be retried, or
the retry count was exceeded@Retries.RetryTranslated public void abortMultipartUpload(String destKey, String uploadId, boolean shouldRetry, Invoker.Retried retrying) throws IOException
abortMultipartUpload
in interface WriteOperations
destKey
- destination key of the uploaduploadId
- multipart operation IdshouldRetry
- should failures trigger a retry?retrying
- callback invoked on every retryIOException
- failure to abortFileNotFoundException
- if the abort ID is unknown@Retries.RetryTranslated public void abortMultipartUpload(software.amazon.awssdk.services.s3.model.MultipartUpload upload) throws IOException
abortMultipartUpload
in interface WriteOperations
upload
- upload to abort.IOException
- on problems.@Retries.RetryTranslated public int abortMultipartUploadsUnderPath(String prefix) throws IOException
abortMultipartUploadsUnderPath
in interface WriteOperations
prefix
- prefix for uploads to abortIOException
- trouble; FileNotFoundExceptions are swallowed.@Retries.RetryTranslated public List<software.amazon.awssdk.services.s3.model.MultipartUpload> listMultipartUploads(String prefix) throws IOException
WriteOperations
listMultipartUploads
in interface WriteOperations
prefix
- prefix for uploads to listIOException
- on problems@Retries.RetryTranslated public void abortMultipartCommit(String destKey, String uploadId) throws IOException
abortMultipartCommit
in interface WriteOperations
destKey
- destination key of ongoing operationuploadId
- multipart operation IdIOException
- on problems.FileNotFoundException
- if the abort ID is unknown@Retries.OnceTranslated public software.amazon.awssdk.services.s3.model.UploadPartRequest.Builder newUploadPartRequestBuilder(String destKey, String uploadId, int partNumber, long size) throws IOException
newUploadPartRequestBuilder
in interface WriteOperations
destKey
- destination key of ongoing operationuploadId
- ID of ongoing uploadpartNumber
- current part number of the uploadsize
- amount of dataIllegalArgumentException
- if the parameters are invalid.org.apache.hadoop.fs.PathIOException
- if the part number is out of range.IOException
public String toString()
@Retries.RetryTranslated public software.amazon.awssdk.services.s3.model.PutObjectResponse putObject(software.amazon.awssdk.services.s3.model.PutObjectRequest putObjectRequest, PutObjectOptions putOptions, S3ADataBlocks.BlockUploadData uploadData, boolean isFile, org.apache.hadoop.fs.statistics.DurationTrackerFactory durationTrackerFactory) throws IOException
putObject
in interface WriteOperations
putObjectRequest
- the requestputOptions
- put object optionsdurationTrackerFactory
- factory for duration trackinguploadData
- data to be uploadedisFile
- is data to be uploaded a fileIOException
- on problems@Retries.OnceTranslated public void revertCommit(String destKey) throws IOException
revertCommit
in interface WriteOperations
destKey
- destination keyIOException
- on problems@Retries.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
finalizeMultipartUpload()
.
Markers are never deleted on commit; this avoids having to
issue many duplicate deletions.
Retry policy: retrying, translated.
Retries increment the errorCount
counter.commitUpload
in interface WriteOperations
destKey
- destinationuploadId
- multipart operation IdpartETags
- list of partial uploadslength
- length of the uploadIOException
- if problems arose which could not be retried, or
the retry count was exceeded@Retries.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
uploadPart
in interface WriteOperations
request
- requestdurationTrackerFactory
- duration tracker factory for operationrequest
- the upload part request.body
- the request body.IOException
- on problemspublic org.apache.hadoop.conf.Configuration getConf()
getConf
in interface WriteOperations
public org.apache.hadoop.fs.store.audit.AuditSpan createSpan(String operation, @Nullable String path1, @Nullable String path2) throws IOException
createSpan
in interface org.apache.hadoop.fs.store.audit.AuditSpanSource
IOException
public void incrementWriteOperations()
WriteOperations
incrementWriteOperations
in interface WriteOperations
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public RequestFactory getRequestFactory()
Copyright © 2008–2024 Apache Software Foundation. All rights reserved.