bgaborg commented on a change in pull request #606: HADOOP-16190. S3A copyFile
operation to include source versionID or etag in the copy request
URL: https://github.com/apache/hadoop/pull/606#discussion_r275126182
##########
File path:
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
##########
@@ -2878,27 +2880,41 @@ private void copyFile(String srcKey, String dstKey,
long size)
}
};
- once("copyFile(" + srcKey + ", " + dstKey + ")", srcKey,
- () -> {
- ObjectMetadata srcom = getObjectMetadata(srcKey);
- ObjectMetadata dstom = cloneObjectMetadata(srcom);
- setOptionalObjectMetadata(dstom);
- CopyObjectRequest copyObjectRequest =
- new CopyObjectRequest(bucket, srcKey, bucket, dstKey);
- setOptionalCopyObjectRequestParameters(copyObjectRequest);
- copyObjectRequest.setCannedAccessControlList(cannedACL);
- copyObjectRequest.setNewObjectMetadata(dstom);
- Copy copy = transfers.copy(copyObjectRequest);
- copy.addProgressListener(progressListener);
- try {
- copy.waitForCopyResult();
- incrementWriteOperations();
- instrumentation.filesCopied(1, size);
- } catch (InterruptedException e) {
- throw new InterruptedIOException("Interrupted copying " + srcKey
- + " to " + dstKey + ", cancelling");
- }
- });
+ try {
+ return once("copyFile(" + srcKey + ", " + dstKey + ")", srcKey,
+ () -> {
+ ObjectMetadata srcom = getObjectMetadata(srcKey);
+ ObjectMetadata dstom = cloneObjectMetadata(srcom);
+ setOptionalObjectMetadata(dstom);
+ CopyObjectRequest copyObjectRequest =
+ new CopyObjectRequest(bucket, srcKey, bucket, dstKey);
+ setOptionalCopyObjectRequestParameters(copyObjectRequest);
+ copyObjectRequest.setCannedAccessControlList(cannedACL);
+ copyObjectRequest.setNewObjectMetadata(dstom);
+ String id = srcom.getVersionId();
+ if (id != null) {
+ copyObjectRequest.setSourceVersionId(id);
+ } else if (isNotEmpty(srcom.getETag())) {
+ copyObjectRequest.withMatchingETagConstraint(srcom.getETag());
+ }
+ Copy copy = transfers.copy(copyObjectRequest);
+ copy.addProgressListener(progressListener);
+ try {
+ CopyResult r = copy.waitForCopyResult();
+ incrementWriteOperations();
+ instrumentation.filesCopied(1, size);
+ return r;
+ } catch (InterruptedException e) {
+ throw (IOException) new InterruptedIOException(
Review comment:
Why do you cast `InterruptedIOException` to `IOException`? If you cast it,
then this method won't throw InterruptedIOException, just `IOException`, so it
can be removed from it's signature.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]