|
@@ -1161,8 +1161,9 @@ public class S3AFileSystem extends FileSystem {
|
|
* @param inputStream source data.
|
|
* @param inputStream source data.
|
|
* @return the request
|
|
* @return the request
|
|
*/
|
|
*/
|
|
- private PutObjectRequest newPutObjectRequest(String key,
|
|
|
|
- ObjectMetadata metadata, InputStream inputStream) {
|
|
|
|
|
|
+ PutObjectRequest newPutObjectRequest(String key,
|
|
|
|
+ ObjectMetadata metadata,
|
|
|
|
+ InputStream inputStream) {
|
|
Preconditions.checkNotNull(inputStream);
|
|
Preconditions.checkNotNull(inputStream);
|
|
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key,
|
|
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key,
|
|
inputStream, metadata);
|
|
inputStream, metadata);
|
|
@@ -1240,14 +1241,10 @@ public class S3AFileSystem extends FileSystem {
|
|
* @return the upload initiated
|
|
* @return the upload initiated
|
|
* @throws AmazonClientException on problems
|
|
* @throws AmazonClientException on problems
|
|
*/
|
|
*/
|
|
- public PutObjectResult putObjectDirect(PutObjectRequest putObjectRequest)
|
|
|
|
|
|
+ PutObjectResult putObjectDirect(PutObjectRequest putObjectRequest)
|
|
throws AmazonClientException {
|
|
throws AmazonClientException {
|
|
- long len;
|
|
|
|
- if (putObjectRequest.getFile() != null) {
|
|
|
|
- len = putObjectRequest.getFile().length();
|
|
|
|
- } else {
|
|
|
|
- len = putObjectRequest.getMetadata().getContentLength();
|
|
|
|
- }
|
|
|
|
|
|
+ long len = getPutRequestLength(putObjectRequest);
|
|
|
|
+ LOG.debug("PUT {} bytes to {}", len, putObjectRequest.getKey());
|
|
incrementPutStartStatistics(len);
|
|
incrementPutStartStatistics(len);
|
|
try {
|
|
try {
|
|
PutObjectResult result = s3.putObject(putObjectRequest);
|
|
PutObjectResult result = s3.putObject(putObjectRequest);
|
|
@@ -1259,6 +1256,23 @@ public class S3AFileSystem extends FileSystem {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Get the length of the PUT, verifying that the length is known.
|
|
|
|
+ * @param putObjectRequest a request bound to a file or a stream.
|
|
|
|
+ * @return the request length
|
|
|
|
+ * @throws IllegalArgumentException if the length is negative
|
|
|
|
+ */
|
|
|
|
+ private long getPutRequestLength(PutObjectRequest putObjectRequest) {
|
|
|
|
+ long len;
|
|
|
|
+ if (putObjectRequest.getFile() != null) {
|
|
|
|
+ len = putObjectRequest.getFile().length();
|
|
|
|
+ } else {
|
|
|
|
+ len = putObjectRequest.getMetadata().getContentLength();
|
|
|
|
+ }
|
|
|
|
+ Preconditions.checkState(len >= 0, "Cannot PUT object of unknown length");
|
|
|
|
+ return len;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Upload part of a multi-partition file.
|
|
* Upload part of a multi-partition file.
|
|
* Increments the write and put counters.
|
|
* Increments the write and put counters.
|
|
@@ -2257,13 +2271,23 @@ public class S3AFileSystem extends FileSystem {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Perform post-write actions.
|
|
* Perform post-write actions.
|
|
|
|
+ * This operation MUST be called after any PUT/multipart PUT completes
|
|
|
|
+ * successfully.
|
|
|
|
+ * This includes
|
|
|
|
+ * <ol>
|
|
|
|
+ * <li>Calling {@link #deleteUnnecessaryFakeDirectories(Path)}</li>
|
|
|
|
+ * <li>Updating any metadata store with details on the newly created
|
|
|
|
+ * object.</li>
|
|
|
|
+ * </ol>
|
|
* @param key key written to
|
|
* @param key key written to
|
|
* @param length total length of file written
|
|
* @param length total length of file written
|
|
*/
|
|
*/
|
|
- public void finishedWrite(String key, long length) {
|
|
|
|
|
|
+ @InterfaceAudience.Private
|
|
|
|
+ void finishedWrite(String key, long length) {
|
|
LOG.debug("Finished write to {}, len {}", key, length);
|
|
LOG.debug("Finished write to {}, len {}", key, length);
|
|
Path p = keyToQualifiedPath(key);
|
|
Path p = keyToQualifiedPath(key);
|
|
deleteUnnecessaryFakeDirectories(p.getParent());
|
|
deleteUnnecessaryFakeDirectories(p.getParent());
|
|
|
|
+ Preconditions.checkArgument(length >= 0, "content length is negative");
|
|
|
|
|
|
// See note about failure semantics in s3guard.md doc.
|
|
// See note about failure semantics in s3guard.md doc.
|
|
try {
|
|
try {
|