-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HADOOP-13600. S3a rename() to copy files in a directory in parallel #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/CopyContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.fs.s3a; | ||
|
||
import com.amazonaws.event.ProgressListener; | ||
import com.amazonaws.services.s3.transfer.Copy; | ||
|
||
|
||
/** | ||
* A wrapper around a {@link Copy} object, the source key for the copy, the destination for the copy, the length of the | ||
* key copied, and the {@link ProgressListener.ExceptionReporter} for the copy. | ||
*/ | ||
class CopyContext { | ||
|
||
private final Copy copy; | ||
private final String srcKey; | ||
private final String destKey; | ||
private final long length; | ||
private final ProgressListener.ExceptionReporter progressListener; | ||
|
||
CopyContext(Copy copy, String srcKey, String destKey, long length, | ||
ProgressListener.ExceptionReporter progressListener) { | ||
this.copy = copy; | ||
this.srcKey = srcKey; | ||
this.destKey = destKey; | ||
this.length = length; | ||
this.progressListener = progressListener; | ||
} | ||
|
||
Copy getCopy() { | ||
return copy; | ||
} | ||
|
||
String getSrcKey() { | ||
return srcKey; | ||
} | ||
|
||
String getDestKey() { | ||
return destKey; | ||
} | ||
|
||
long getLength() { | ||
return length; | ||
} | ||
|
||
ProgressListener.ExceptionReporter getProgressListener() { | ||
return progressListener; | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/LazyTransferManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.fs.s3a; | ||
|
||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.transfer.TransferManager; | ||
import com.amazonaws.services.s3.transfer.TransferManagerConfiguration; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
|
||
import static org.apache.hadoop.fs.s3a.Constants.COPY_MAX_THREADS; | ||
import static org.apache.hadoop.fs.s3a.Constants.DEFAULT_COPY_MAX_THREADS; | ||
import static org.apache.hadoop.fs.s3a.Constants.DEFAULT_KEEPALIVE_TIME; | ||
import static org.apache.hadoop.fs.s3a.Constants.DEFAULT_MAX_THREADS; | ||
import static org.apache.hadoop.fs.s3a.Constants.KEEPALIVE_TIME; | ||
import static org.apache.hadoop.fs.s3a.Constants.MAX_THREADS; | ||
import static org.apache.hadoop.fs.s3a.S3AUtils.getMaxThreads; | ||
import static org.apache.hadoop.fs.s3a.S3AUtils.longOption; | ||
|
||
|
||
/** | ||
* A wrapper around a {@link TransferManager} that lazily initializes the {@link TransferManager}. | ||
*/ | ||
class LazyTransferManager { | ||
|
||
private final AmazonS3 s3; | ||
private final TransferManagerConfiguration transferConfiguration; | ||
private final int maxThreads; | ||
private final long keepAliveTime; | ||
private final String threadPoolName; | ||
|
||
private TransferManager transferManager; | ||
private ExecutorService executorService; | ||
|
||
private LazyTransferManager(AmazonS3 s3, TransferManagerConfiguration transferConfiguration, int maxThreads, | ||
long keepAliveTime, String threadPoolName) { | ||
this.s3 = s3; | ||
this.transferConfiguration = transferConfiguration; | ||
this.maxThreads = maxThreads; | ||
this.keepAliveTime = keepAliveTime; | ||
this.threadPoolName = threadPoolName; | ||
} | ||
|
||
synchronized TransferManager get() { | ||
if (transferManager == null) { | ||
transferManager = createTransferManager(); | ||
return transferManager; | ||
} | ||
return transferManager; | ||
} | ||
|
||
boolean isInitialized() { | ||
return transferManager == null; | ||
} | ||
|
||
ExecutorService getExecutorService() { | ||
return executorService; | ||
} | ||
|
||
private TransferManager createTransferManager() { | ||
executorService = new ThreadPoolExecutor( | ||
maxThreads, Integer.MAX_VALUE, | ||
keepAliveTime, TimeUnit.SECONDS, | ||
new LinkedBlockingQueue<>(), | ||
BlockingThreadPoolExecutorService.newDaemonThreadFactory( | ||
threadPoolName)); | ||
|
||
TransferManager transferManager = new TransferManager(s3, executorService); | ||
transferManager.setConfiguration(transferConfiguration); | ||
return transferManager; | ||
} | ||
|
||
static LazyTransferManager createLazyUploadTransferManager(AmazonS3 s3, Configuration conf, long partSize, | ||
long multiPartThreshold) { | ||
int maxThreads = getMaxThreads(conf, MAX_THREADS, DEFAULT_MAX_THREADS); | ||
long keepAliveTime = longOption(conf, KEEPALIVE_TIME, DEFAULT_KEEPALIVE_TIME, 0); | ||
|
||
TransferManagerConfiguration transferConfiguration = new TransferManagerConfiguration(); | ||
transferConfiguration.setMinimumUploadPartSize(partSize); | ||
transferConfiguration.setMultipartUploadThreshold(multiPartThreshold); | ||
|
||
return new LazyTransferManager(s3, transferConfiguration, maxThreads, keepAliveTime, "s3a-upload-unbounded"); | ||
} | ||
|
||
static LazyTransferManager createLazyCopyTransferManager(AmazonS3 s3, Configuration conf, long partSize, | ||
long multiPartThreshold) { | ||
int maxThreads = getMaxThreads(conf, COPY_MAX_THREADS, DEFAULT_COPY_MAX_THREADS); | ||
long keepAliveTime = longOption(conf, KEEPALIVE_TIME, DEFAULT_KEEPALIVE_TIME, 0); | ||
|
||
TransferManagerConfiguration transferConfiguration = new TransferManagerConfiguration(); | ||
transferConfiguration.setMultipartCopyPartSize(partSize); | ||
transferConfiguration.setMultipartCopyThreshold(multiPartThreshold); | ||
|
||
return new LazyTransferManager(s3, transferConfiguration, maxThreads, keepAliveTime, "s3a-copy-unbounded"); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will need apache license text at top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, always forget those. Fixed.