@NotThreadSafe
public class S3ALowLevelOutputStream
extends java.io.OutputStream
mFile on the local disk. When the data mPartitionOffset
in this temporary file reaches the mPartitionSize, the file will be submitted
to the upload executor mExecutor and we do not wait for uploads to finish.
A new temp file will be created for the future write and the mPartitionOffset
will be reset to zero. The process goes until all the data has been written to temp files.
In flush(), we upload the buffered data if they are bigger than 5MB
and wait for all uploads to finish. The temp files will be deleted after uploading successfully.
In close(), we upload the last part of data (if exists), wait for all uploads to finish,
and complete the multipart upload.
close() will not be retried, but all the multipart upload
related operations(init, upload, complete, and abort) will be retried.
If an error occurs and we have no way to recover, we abort the multipart uploads.
Some multipart uploads may not be completed/aborted in normal ways and need periodical cleanup
by enabling the PropertyKey.UNDERFS_CLEANUP_ENABLED.
When a leader master starts or a cleanup interval is reached, all the multipart uploads
older than PropertyKey.UNDERFS_S3_INTERMEDIATE_UPLOAD_CLEAN_AGE will be cleaned.| Modifier and Type | Field and Description |
|---|---|
protected com.amazonaws.services.s3.AmazonS3 |
mClient
The Amazon S3 client to interact with S3.
|
protected java.lang.String |
mKey
Key of the file when it is uploaded to S3.
|
| Constructor and Description |
|---|
S3ALowLevelOutputStream(java.lang.String bucketName,
java.lang.String key,
com.amazonaws.services.s3.AmazonS3 s3Client,
com.google.common.util.concurrent.ListeningExecutorService executor,
long streamingUploadPartitionSize,
java.util.List<java.lang.String> tmpDirs,
boolean sseEnabled)
Constructs a new stream for writing a file.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
abortMultiPartUpload() |
protected void |
abortMultiPartUpload(com.amazonaws.services.s3.AmazonS3 s3Client,
java.lang.String uploadId)
Aborts multipart upload.
|
void |
close() |
protected void |
completeMultiPartUpload() |
protected void |
completeMultiPartUpload(com.amazonaws.services.s3.AmazonS3 s3Client,
java.lang.String uploadId)
Completes multipart upload.
|
protected void |
execUpload(com.amazonaws.services.s3.AmazonS3 s3Client,
com.amazonaws.services.s3.model.UploadPartRequest request)
Executes the upload part request.
|
protected void |
execUpload(com.amazonaws.services.s3.model.UploadPartRequest request) |
void |
flush() |
protected com.amazonaws.services.s3.AmazonS3 |
getClient() |
protected void |
initMultiPartUpload() |
protected void |
uploadPart()
Uploads part async.
|
protected void |
waitForAllPartsUpload()
Waits for the submitted upload tasks to finish.
|
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
protected com.amazonaws.services.s3.AmazonS3 mClient
protected final java.lang.String mKey
public S3ALowLevelOutputStream(java.lang.String bucketName,
java.lang.String key,
com.amazonaws.services.s3.AmazonS3 s3Client,
com.google.common.util.concurrent.ListeningExecutorService executor,
long streamingUploadPartitionSize,
java.util.List<java.lang.String> tmpDirs,
boolean sseEnabled)
bucketName - the name of the bucketkey - the key of the files3Client - the Amazon S3 client to upload the file withexecutor - a thread pool executorstreamingUploadPartitionSize - the size in bytes for partitions of streaming uploadstmpDirs - a list of temporary directoriessseEnabled - whether or not server side encryption is enabledpublic void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void write(byte[] b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void write(byte[] b,
int off,
int len)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.OutputStreamjava.io.IOExceptionprotected void initMultiPartUpload()
throws java.io.IOException
java.io.IOExceptionprotected void uploadPart()
throws java.io.IOException
java.io.IOExceptionprotected void execUpload(com.amazonaws.services.s3.model.UploadPartRequest request)
throws java.io.IOException
java.io.IOExceptionprotected void execUpload(com.amazonaws.services.s3.AmazonS3 s3Client,
com.amazonaws.services.s3.model.UploadPartRequest request)
request - the upload part requestprotected void waitForAllPartsUpload()
throws java.io.IOException
java.io.IOExceptionprotected void completeMultiPartUpload()
throws java.io.IOException
java.io.IOExceptionprotected void completeMultiPartUpload(com.amazonaws.services.s3.AmazonS3 s3Client,
java.lang.String uploadId)
throws java.io.IOException
java.io.IOExceptionprotected void abortMultiPartUpload()
protected void abortMultiPartUpload(com.amazonaws.services.s3.AmazonS3 s3Client,
java.lang.String uploadId)
protected com.amazonaws.services.s3.AmazonS3 getClient()
Copyright © 2021. All Rights Reserved.