@NotThreadSafe public abstract class ObjectMultipartUploadOutputStream extends OutputStream implements ContentHashable
The file is partitioned into multiple parts, each part is uploaded in a separate thread. The number of threads is determined by the configuration. The minimum part size is 5MB (s3) or 100KB (oss, obs) or 1MB(cos), except the last part. We choose 5MB to be the minimum part size for all object storage systems. The maximum part size is 5GB (s3, oss, cos, obs). The partition size is determined by the configuration.
In flush(), we wait for all uploads to finish.
In close() we 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 clean age will be cleaned.
Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
LOG |
protected static long |
MAXIMUM_PART_SIZE
The maximum size of a single part is 5GB.
|
protected String |
mBucketName
Bucket name of the object storage bucket.
|
protected boolean |
mClosed
Flag to indicate this stream has been closed, to ensure close is only done once.
|
protected static long |
MINIMUM_PART_SIZE
Only parts bigger than 5MB could be uploaded through multipart upload,
except the last part.
|
protected String |
mKey
Key of the file when it is uploaded to object storage.
|
protected long |
mPartitionOffset
When the offset reaches the partition size, we upload mStream.
|
protected long |
mPartitionSize
The maximum allowed size of a partition.
|
protected java.util.function.Supplier<RetryPolicy> |
mRetryPolicy
The retry policy of this multipart upload.
|
protected byte[] |
mSingleCharWrite
Pre-allocated byte buffer for writing single characters.
|
Constructor and Description |
---|
ObjectMultipartUploadOutputStream(String bucketName,
String key,
com.google.common.util.concurrent.ListeningExecutorService executor,
long multipartUploadPartitionSize,
AlluxioConfiguration ufsConf)
Constructs a new stream for writing a file.
|
Modifier and Type | Method and Description |
---|---|
protected void |
abortMultiPartUpload() |
protected abstract void |
abortMultipartUploadInternal() |
void |
close() |
protected abstract void |
completeMultipartUploadInternal() |
protected abstract void |
createEmptyObject(String key) |
void |
flush() |
protected abstract void |
initMultipartUploadInternal() |
protected abstract void |
putObject(String key,
byte[] buf,
long length) |
protected void |
uploadPart()
Uploads part async.
|
protected void |
uploadPart(byte[] buf,
int partNumber,
boolean isLastPart,
long length) |
protected abstract void |
uploadPartInternal(byte[] buf,
int partNumber,
boolean isLastPart,
long length) |
protected void |
waitForAllPartsUpload() |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getContentHash
protected static final org.slf4j.Logger LOG
protected static final long MINIMUM_PART_SIZE
protected static final long MAXIMUM_PART_SIZE
protected final String mBucketName
protected final String mKey
protected final java.util.function.Supplier<RetryPolicy> mRetryPolicy
protected final byte[] mSingleCharWrite
protected final long mPartitionSize
protected boolean mClosed
protected long mPartitionOffset
public ObjectMultipartUploadOutputStream(String bucketName, String key, com.google.common.util.concurrent.ListeningExecutorService executor, long multipartUploadPartitionSize, AlluxioConfiguration ufsConf)
bucketName
- the name of the bucketkey
- the key of the fileexecutor
- executormultipartUploadPartitionSize
- the size in bytes for partitions of multipart uploadsufsConf
- the object store under file system configurationpublic void write(int b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
protected void uploadPart() throws IOException
IOException
protected void uploadPart(byte[] buf, int partNumber, boolean isLastPart, long length) throws IOException
IOException
protected void abortMultiPartUpload() throws IOException
IOException
protected void waitForAllPartsUpload() throws IOException
IOException
protected abstract void uploadPartInternal(byte[] buf, int partNumber, boolean isLastPart, long length) throws IOException
buf
- the byte bufpartNumber
- the part numberisLastPart
- whether this is the last partlength
- the length of the part to be uploadedIOException
protected abstract void initMultipartUploadInternal() throws IOException
IOException
protected abstract void completeMultipartUploadInternal() throws IOException
IOException
protected abstract void abortMultipartUploadInternal() throws IOException
IOException
protected abstract void createEmptyObject(String key) throws IOException
key
- the keyIOException
protected abstract void putObject(String key, byte[] buf, long length) throws IOException
key
- the keybuf
- the byte buflength
- the length of the file to be uploadedIOException
Copyright © 2023. All Rights Reserved.