@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 | 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)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
abortMultipartCommit(String destKey,
String uploadId)
Abort a multipart commit operation.
|
void |
abortMultipartUpload(com.amazonaws.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.
|
com.amazonaws.services.s3.model.CompleteMultipartUploadResult |
commitUpload(String destKey,
String uploadId,
List<com.amazonaws.services.s3.model.PartETag> partETags,
long length,
BulkOperationState operationState)
This completes a multipart upload to the destination key via
finalizeMultipartUpload(). |
com.amazonaws.services.s3.model.CompleteMultipartUploadResult |
completeMPUwithRetries(String destKey,
String uploadId,
List<com.amazonaws.services.s3.model.PartETag> partETags,
long length,
AtomicInteger errorCount)
This completes a multipart upload to the destination key via
finalizeMultipartUpload(). |
com.amazonaws.services.s3.model.PutObjectRequest |
createPutObjectRequest(String dest,
File sourceFile)
Create a
PutObjectRequest request to upload a file. |
com.amazonaws.services.s3.model.PutObjectRequest |
createPutObjectRequest(String destKey,
InputStream inputStream,
long length,
Map<String,String> headers)
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.
|
BulkOperationState |
initiateCommitOperation(org.apache.hadoop.fs.Path path)
Initiate a commit operation through any metastore.
|
String |
initiateMultiPartUpload(String destKey)
Start the multipart upload process.
|
BulkOperationState |
initiateOperation(org.apache.hadoop.fs.Path path,
BulkOperationState.OperationType operationType)
Initiate a commit operation through any metastore.
|
List<com.amazonaws.services.s3.model.MultipartUpload> |
listMultipartUploads(String prefix)
Abort multipart uploads under a path: limited to the first
few hundred.
|
com.amazonaws.services.s3.model.ObjectMetadata |
newObjectMetadata(long length)
Create a new object metadata instance.
|
com.amazonaws.services.s3.model.SelectObjectContentRequest |
newSelectRequest(org.apache.hadoop.fs.Path path)
Create a S3 Select request for the destination path.
|
com.amazonaws.services.s3.model.UploadPartRequest |
newUploadPartRequest(String destKey,
String uploadId,
int partNumber,
int size,
InputStream uploadStream,
File sourceFile,
Long offset)
Create and initialize a part request of a multipart upload.
|
com.amazonaws.services.s3.model.PutObjectResult |
putObject(com.amazonaws.services.s3.model.PutObjectRequest putObjectRequest)
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,
BulkOperationState operationState)
Revert a commit by deleting the file.
|
com.amazonaws.services.s3.model.SelectObjectContentResult |
select(org.apache.hadoop.fs.Path source,
com.amazonaws.services.s3.model.SelectObjectContentRequest request,
String action)
Execute an S3 Select operation.
|
String |
toString()
The toString method is intended to be used in logging/toString calls.
|
com.amazonaws.services.s3.transfer.model.UploadResult |
uploadObject(com.amazonaws.services.s3.model.PutObjectRequest putObjectRequest)
PUT an object via the transfer manager.
|
com.amazonaws.services.s3.model.UploadPartResult |
uploadPart(com.amazonaws.services.s3.model.UploadPartRequest request)
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)
owner - owner FS creating the helperconf - Configuration objectstatisticsContext - statistics contextauditSpanSource - source of spansauditSpan - span to activatepublic <T> T retry(String action, String path, boolean idempotent, org.apache.hadoop.util.functional.CallableRaisingIOE<T> operation) throws IOException
retry in interface WriteOperationsT - 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 com.amazonaws.services.s3.model.PutObjectRequest createPutObjectRequest(String destKey, InputStream inputStream, long length, Map<String,String> headers)
PutObjectRequest request against the specific key.createPutObjectRequest in interface WriteOperationsdestKey - destination keyinputStream - source data.length - size, if known. Use -1 for not knownheaders - optional map of custom headers.@Retries.OnceRaw public com.amazonaws.services.s3.model.PutObjectRequest createPutObjectRequest(String dest, File sourceFile)
PutObjectRequest request to upload a file.createPutObjectRequest in interface WriteOperationsdest - key to PUT to.sourceFile - source filepublic void writeSuccessful(long length)
writeSuccessful in interface WriteOperationslength - length of the writepublic void writeFailed(Exception ex)
writeFailed in interface WriteOperationsex - Any exception raised which triggered the failure.public com.amazonaws.services.s3.model.ObjectMetadata newObjectMetadata(long length)
newObjectMetadata in interface WriteOperationslength - size, if known. Use -1 for not known@Retries.RetryTranslated public String initiateMultiPartUpload(String destKey) throws IOException
initiateMultiPartUpload in interface WriteOperationsdestKey - destination of uploadIOException - IO problem@Retries.RetryTranslated public com.amazonaws.services.s3.model.CompleteMultipartUploadResult completeMPUwithRetries(String destKey, String uploadId, List<com.amazonaws.services.s3.model.PartETag> partETags, long length, AtomicInteger errorCount) throws IOException
finalizeMultipartUpload().
Retry policy: retrying, translated.
Retries increment the errorCount counter.completeMPUwithRetries in interface WriteOperationsdestKey - destinationuploadId - multipart operation IdpartETags - list of partial uploadslength - length of the uploaderrorCount - a counter incremented by 1 on every error; for
use in statisticsIOException - 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 WriteOperationsdestKey - 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(com.amazonaws.services.s3.model.MultipartUpload upload) throws IOException
abortMultipartUpload in interface WriteOperationsupload - upload to abort.IOException - on problems.@Retries.RetryTranslated public int abortMultipartUploadsUnderPath(String prefix) throws IOException
abortMultipartUploadsUnderPath in interface WriteOperationsprefix - prefix for uploads to abortIOException - trouble; FileNotFoundExceptions are swallowed.@Retries.RetryTranslated public List<com.amazonaws.services.s3.model.MultipartUpload> listMultipartUploads(String prefix) throws IOException
WriteOperationslistMultipartUploads in interface WriteOperationsprefix - prefix for uploads to abortIOException - trouble; FileNotFoundExceptions are swallowed.@Retries.RetryTranslated public void abortMultipartCommit(String destKey, String uploadId) throws IOException
abortMultipartCommit in interface WriteOperationsdestKey - destination key of ongoing operationuploadId - multipart operation IdIOException - on problems.FileNotFoundException - if the abort ID is unknown@Retries.OnceTranslated public com.amazonaws.services.s3.model.UploadPartRequest newUploadPartRequest(String destKey, String uploadId, int partNumber, int size, InputStream uploadStream, File sourceFile, Long offset) throws IOException
uploadStream or sourceFile
must be specified.
A subset of the file may be posted, by providing the starting point
in offset and a length of block in size equal to
or less than the remaining bytes.
The part number must be less than 10000.
Retry policy is once-translated; to much effortnewUploadPartRequest in interface WriteOperationsdestKey - destination key of ongoing operationuploadId - ID of ongoing uploadpartNumber - current part number of the uploadsize - amount of datauploadStream - source of data to uploadsourceFile - optional source file.offset - offset in file to start reading.IllegalArgumentException - if the parameters are invalid.org.apache.hadoop.fs.PathIOException - if the part number is out of range.IOExceptionpublic String toString()
@Retries.RetryTranslated public com.amazonaws.services.s3.model.PutObjectResult putObject(com.amazonaws.services.s3.model.PutObjectRequest putObjectRequest) throws IOException
putObject in interface WriteOperationsputObjectRequest - the requestIOException - on problems@Retries.RetryTranslated public com.amazonaws.services.s3.transfer.model.UploadResult uploadObject(com.amazonaws.services.s3.model.PutObjectRequest putObjectRequest) throws IOException
uploadObject in interface WriteOperationsputObjectRequest - the requestIOException - on problems@Retries.OnceTranslated public void revertCommit(String destKey, @Nullable BulkOperationState operationState) throws IOException
revertCommit in interface WriteOperationsdestKey - destination keyoperationState - operational state for a bulk updateIOException - on problems@Retries.RetryTranslated public com.amazonaws.services.s3.model.CompleteMultipartUploadResult commitUpload(String destKey, String uploadId, List<com.amazonaws.services.s3.model.PartETag> partETags, long length, @Nullable BulkOperationState operationState) throws IOException
finalizeMultipartUpload().
Retry policy: retrying, translated.
Retries increment the errorCount counter.commitUpload in interface WriteOperationsdestKey - destinationuploadId - multipart operation IdpartETags - list of partial uploadslength - length of the uploadoperationState - operational state for a bulk updateIOException - if problems arose which could not be retried, or
the retry count was exceededpublic BulkOperationState initiateCommitOperation(org.apache.hadoop.fs.Path path) throws IOException
initiateCommitOperation in interface WriteOperationspath - path under which the writes will all take place.IOException - failure to instantiate.public BulkOperationState initiateOperation(org.apache.hadoop.fs.Path path, BulkOperationState.OperationType operationType) throws IOException
initiateOperation in interface WriteOperationspath - path under which the writes will all take place.operationType - operation to initiateIOException - failure to instantiate.@Retries.RetryTranslated public com.amazonaws.services.s3.model.UploadPartResult uploadPart(com.amazonaws.services.s3.model.UploadPartRequest request) throws IOException
uploadPart in interface WriteOperationsrequest - requestIOException - on problemspublic org.apache.hadoop.conf.Configuration getConf()
getConf in interface WriteOperationspublic com.amazonaws.services.s3.model.SelectObjectContentRequest newSelectRequest(org.apache.hadoop.fs.Path path)
newSelectRequest in interface WriteOperationspath - pre-qualified path for query@Retries.RetryTranslated public com.amazonaws.services.s3.model.SelectObjectContentResult select(org.apache.hadoop.fs.Path source, com.amazonaws.services.s3.model.SelectObjectContentRequest request, String action) throws IOException
select in interface WriteOperationssource - source for selectionrequest - Select request to issue.action - the action for use in exception creationIOException - failurepublic 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.AuditSpanSourceIOExceptionpublic void incrementWriteOperations()
WriteOperationsincrementWriteOperations in interface WriteOperationspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic RequestFactory getRequestFactory()
Copyright © 2008–2022 Apache Software Foundation. All rights reserved.