Package org.apache.hadoop.fs.shell
Class CopyCommandWithMultiThread
java.lang.Object
org.apache.hadoop.conf.Configured
org.apache.hadoop.fs.shell.Command
org.apache.hadoop.fs.shell.FsCommand
org.apache.hadoop.fs.shell.CopyCommandWithMultiThread
- All Implemented Interfaces:
Configurable
Abstract command to enable sub copy commands run with multi-thread.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprotected PathDataprotected static final org.slf4j.LoggerFields inherited from class org.apache.hadoop.fs.shell.Command
args, COMMAND_DESCRIPTION_FIELD, COMMAND_NAME_FIELD, COMMAND_USAGE_FIELD, err, exceptions, exitCode, name, numErrors, out, recursive -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcopyFileToTarget(PathData src, PathData target) Copies the source file to the target.protected voidcopyStreamToTarget(InputStream in, PathData target) If direct write is disabled ,copies the stream contents to a temporary file "target.protected ThreadPoolExecutorprotected voidgetLocalDestination(LinkedList<String> args) The last arg is expected to be a local path, if only one argument is given then the destination will be the current directoryprotected voidgetRemoteDestination(LinkedList<String> args) The last arg is expected to be a remote path, if only one argument is given then the destination will be the remote user's directoryprotected PathDatagetTargetPath(PathData src) protected intprotected intprotected booleanprotected voidpreserve(org.apache.hadoop.fs.shell.CommandWithDestination.FileAttribute fileAttribute) Add file attributes that need to be preserved.protected voidpreserveAttributes(PathData src, PathData target, boolean preserveRawXAttrs) Preserve the attributes of the source to the target.protected voidprocessArguments(LinkedList<PathData> args) Processes the command's list of expanded arguments.protected voidprocessPath(PathData src) Hook for commands to implement an operation to be applied on each path for the command.protected voidprocessPath(PathData src, PathData dst) Called with a source and target destination pairprotected voidThis is the last chance to modify an argument before going into the (possibly) recursiveCommand.processPaths(PathData, PathData...)->Command.processPath(PathData)loop.protected voidrecursePath(PathData src) Gets the directory listing for a path and invokesCommand.processPaths(PathData, PathData...)protected voidsetDirectWrite(boolean flag) protected voidsetLazyPersist(boolean flag) protected voidsetOverwrite(boolean flag) This method is used to enable the force(-f) option while copying the files.protected voidsetPreserve(boolean preserve) If true, the last modified time, last access time, owner, group and permission information of the source file will be preserved as far as targetFileSystemimplementation allows.protected voidsetThreadCount(String optValue) set thread count by option value, if the value less than 1, use 1 instead.protected voidsetThreadPoolQueueSize(String optValue) set thread pool queue size by option value, if the value less than 1, use DEFAULT_QUEUE_SIZE instead.protected voidsetVerifyChecksum(boolean flag) protected voidsetWriteChecksum(boolean flag) Methods inherited from class org.apache.hadoop.fs.shell.FsCommand
getCommandName, processRawArguments, registerCommands, run, runAllMethods inherited from class org.apache.hadoop.fs.shell.Command
displayError, displayError, displayWarning, exitCodeForError, expandArgument, expandArguments, getCommandFactory, getDepth, getDescription, getListingGroupSize, getName, getReplacementCommand, getUsage, isDeprecated, isPathRecursable, isRecursive, isSorted, postProcessPath, processArgument, processNonexistentPath, processOptions, processPaths, processPaths, run, run, setCommandFactory, setName, setRecursiveMethods inherited from class org.apache.hadoop.conf.Configured
getConf, setConf
-
Field Details
-
DEFAULT_QUEUE_SIZE
public static final int DEFAULT_QUEUE_SIZE- See Also:
-
LOG
protected static final org.slf4j.Logger LOG -
dst
-
-
Constructor Details
-
CopyCommandWithMultiThread
public CopyCommandWithMultiThread()
-
-
Method Details
-
setThreadCount
set thread count by option value, if the value less than 1, use 1 instead.- Parameters:
optValue- option value
-
setThreadPoolQueueSize
set thread pool queue size by option value, if the value less than 1, use DEFAULT_QUEUE_SIZE instead.- Parameters:
optValue- option value
-
getThreadCount
@VisibleForTesting protected int getThreadCount() -
getThreadPoolQueueSize
@VisibleForTesting protected int getThreadPoolQueueSize() -
getExecutor
-
processArguments
Description copied from class:CommandProcesses the command's list of expanded arguments.Command.processArgument(PathData)will be invoked with each item in the list. The loop catches IOExceptions, increments the error count, and displays the exception.- Parameters:
args- a list ofPathDatato process- Throws:
IOException- if anything goes wrong...
-
isMultiThreadNecessary
@VisibleForTesting protected boolean isMultiThreadNecessary(LinkedList<PathData> args) throws IOException - Throws:
IOException
-
copyFileToTarget
Copies the source file to the target.- Parameters:
src- item to copytarget- where to copy the item- Throws:
IOException- if copy fails
-
setOverwrite
protected void setOverwrite(boolean flag) This method is used to enable the force(-f) option while copying the files.- Parameters:
flag- true/false
-
setLazyPersist
protected void setLazyPersist(boolean flag) -
setVerifyChecksum
protected void setVerifyChecksum(boolean flag) -
setWriteChecksum
protected void setWriteChecksum(boolean flag) -
setDirectWrite
protected void setDirectWrite(boolean flag) -
setPreserve
protected void setPreserve(boolean preserve) If true, the last modified time, last access time, owner, group and permission information of the source file will be preserved as far as targetFileSystemimplementation allows.- Parameters:
preserve- preserve.
-
preserve
protected void preserve(org.apache.hadoop.fs.shell.CommandWithDestination.FileAttribute fileAttribute) Add file attributes that need to be preserved. This method may be called multiple times to add attributes.- Parameters:
fileAttribute- - Attribute to add, one at a time
-
getLocalDestination
The last arg is expected to be a local path, if only one argument is given then the destination will be the current directory- Parameters:
args- is the list of arguments- Throws:
IOException- raised on errors performing I/O.
-
getRemoteDestination
The last arg is expected to be a remote path, if only one argument is given then the destination will be the remote user's directory- Parameters:
args- is the list of arguments- Throws:
PathIOException- if path doesn't exist or matches too many timesIOException
-
processPathArgument
Description copied from class:CommandThis is the last chance to modify an argument before going into the (possibly) recursiveCommand.processPaths(PathData, PathData...)->Command.processPath(PathData)loop. Ex. ls and du use this to expand out directories.- Overrides:
processPathArgumentin classCommand- Parameters:
src- aPathDatarepresenting a path which exists- Throws:
IOException- if anything goes wrong...
-
processPath
Description copied from class:CommandHook for commands to implement an operation to be applied on each path for the command. Note implementation of this method is optional if earlier methods in the chain handle the operation.- Overrides:
processPathin classCommand- Parameters:
src- aPathDataobject- Throws:
IOException- if anything else goes wrong in the user-implementation
-
processPath
Called with a source and target destination pair- Parameters:
src- for the operationdst- for the operation- Throws:
IOException- if anything goes wrong
-
recursePath
Description copied from class:CommandGets the directory listing for a path and invokesCommand.processPaths(PathData, PathData...)- Overrides:
recursePathin classCommand- Parameters:
src-PathDatafor directory to recurse into- Throws:
IOException- if anything goes wrong...
-
getTargetPath
- Throws:
IOException
-
copyStreamToTarget
If direct write is disabled ,copies the stream contents to a temporary file "target._COPYING_". If the copy is successful, the temporary file will be renamed to the real path, else the temporary file will be deleted. if direct write is enabled , then creation temporary file is skipped.- Parameters:
in- the input stream for the copytarget- where to store the contents of the stream- Throws:
IOException- if copy fails
-
preserveAttributes
protected void preserveAttributes(PathData src, PathData target, boolean preserveRawXAttrs) throws IOException Preserve the attributes of the source to the target. The method callsshouldPreserve(FileAttribute)to check what attribute to preserve.- Parameters:
src- source to preservetarget- where to preserve attributespreserveRawXAttrs- true if raw.* xattrs should be preserved- Throws:
IOException- if fails to preserve attributes
-