Java Code Examples for org.apache.hadoop.fs.Options#Rename
The following examples show how to use
org.apache.hadoop.fs.Options#Rename .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HadoopUtils.java From incubator-gobblin with Apache License 2.0 | 6 votes |
/** * A wrapper around {@link FileSystem#rename(Path, Path)} which throws {@link IOException} if * {@link FileSystem#rename(Path, Path)} returns False. */ public static void renamePath(FileSystem fs, Path oldName, Path newName, boolean overwrite) throws IOException { //In default implementation of rename with rewrite option in FileSystem, if the parent dir of dst does not exist, it will throw exception, //Which will fail some of our job unintentionally. So we only call that method when fs is an instance of DistributedFileSystem to avoid inconsistency problem if(fs instanceof DistributedFileSystem) { Options.Rename renameOptions = (overwrite) ? Options.Rename.OVERWRITE : Options.Rename.NONE; ((DistributedFileSystem) fs).rename(oldName, newName, renameOptions); } else { if (!fs.exists(oldName)) { throw new FileNotFoundException(String.format("Failed to rename %s to %s: src not found", oldName, newName)); } if (fs.exists(newName)) { if (overwrite) { HadoopUtils.moveToTrash(fs, newName); } else { throw new FileAlreadyExistsException(String.format("Failed to rename %s to %s: dst already exists", oldName, newName)); } } if (!fs.rename(oldName, newName)) { throw new IOException(String.format("Failed to rename %s to %s", oldName, newName)); } } }
Example 2
Source File: DFSClient.java From hadoop with Apache License 2.0 | 6 votes |
/** * Rename file or directory. * @see ClientProtocol#rename2(String, String, Options.Rename...) */ public void rename(String src, String dst, Options.Rename... options) throws IOException { checkOpen(); TraceScope scope = getSrcDstTraceScope("rename2", src, dst); try { namenode.rename2(src, dst, options); } catch(RemoteException re) { throw re.unwrapRemoteException(AccessControlException.class, DSQuotaExceededException.class, FileAlreadyExistsException.class, FileNotFoundException.class, ParentNotDirectoryException.class, SafeModeException.class, NSQuotaExceededException.class, UnresolvedPathException.class, SnapshotAccessControlException.class); } finally { scope.close(); } }
Example 3
Source File: NameNodeRpcServer.java From big-c with Apache License 2.0 | 6 votes |
@Override // ClientProtocol public void rename2(String src, String dst, Options.Rename... options) throws IOException { checkNNStartup(); if(stateChangeLog.isDebugEnabled()) { stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst); } if (!checkPathLength(dst)) { throw new IOException("rename: Pathname too long. Limit " + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels."); } CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache); if (cacheEntry != null && cacheEntry.isSuccess()) { return; // Return previous response } boolean success = false; try { namesystem.renameTo(src, dst, cacheEntry != null, options); success = true; } finally { RetryCache.setState(cacheEntry, success); } metrics.incrFilesRenamed(); }
Example 4
Source File: NameNodeRpcServer.java From hadoop with Apache License 2.0 | 6 votes |
@Override // ClientProtocol public void rename2(String src, String dst, Options.Rename... options) throws IOException { checkNNStartup(); if(stateChangeLog.isDebugEnabled()) { stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst); } if (!checkPathLength(dst)) { throw new IOException("rename: Pathname too long. Limit " + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels."); } CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache); if (cacheEntry != null && cacheEntry.isSuccess()) { return; // Return previous response } boolean success = false; try { namesystem.renameTo(src, dst, cacheEntry != null, options); success = true; } finally { RetryCache.setState(cacheEntry, success); } metrics.incrFilesRenamed(); }
Example 5
Source File: DFSClient.java From big-c with Apache License 2.0 | 6 votes |
/** * Rename file or directory. * @see ClientProtocol#rename2(String, String, Options.Rename...) */ public void rename(String src, String dst, Options.Rename... options) throws IOException { checkOpen(); TraceScope scope = getSrcDstTraceScope("rename2", src, dst); try { namenode.rename2(src, dst, options); } catch(RemoteException re) { throw re.unwrapRemoteException(AccessControlException.class, DSQuotaExceededException.class, FileAlreadyExistsException.class, FileNotFoundException.class, ParentNotDirectoryException.class, SafeModeException.class, NSQuotaExceededException.class, UnresolvedPathException.class, SnapshotAccessControlException.class); } finally { scope.close(); } }
Example 6
Source File: WebHdfsFileSystem.java From big-c with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public void rename(final Path src, final Path dst, final Options.Rename... options) throws IOException { statistics.incrementWriteOps(1); final HttpOpParam.Op op = PutOpParam.Op.RENAME; new FsPathRunner(op, src, new DestinationParam(makeQualified(dst).toUri().getPath()), new RenameOptionSetParam(options) ).run(); }
Example 7
Source File: FSEditLog.java From big-c with Apache License 2.0 | 5 votes |
/** * Add rename record to edit log. * * The destination should be the file name, not the destination directory. */ void logRename(String src, String dst, long timestamp, boolean toLogRpcIds, Options.Rename... options) { RenameOp op = RenameOp.getInstance(cache.get()) .setSource(src) .setDestination(dst) .setTimestamp(timestamp) .setOptions(options); logRpcIds(op, toLogRpcIds); logEdit(op); }
Example 8
Source File: FSDirRenameOp.java From big-c with Apache License 2.0 | 5 votes |
/** * Rename src to dst. * <br> * Note: This is to be used by {@link org.apache.hadoop.hdfs.server * .namenode.FSEditLogLoader} only. * <br> * * @param fsd FSDirectory * @param src source path * @param dst destination path * @param timestamp modification time * @param options Rename options */ static boolean renameForEditLog( FSDirectory fsd, String src, String dst, long timestamp, Options.Rename... options) throws IOException { BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo(); final INodesInPath srcIIP = fsd.getINodesInPath4Write(src, false); final INodesInPath dstIIP = fsd.getINodesInPath4Write(dst, false); boolean ret = unprotectedRenameTo(fsd, src, dst, srcIIP, dstIIP, timestamp, collectedBlocks, options); if (!collectedBlocks.getToDeleteList().isEmpty()) { fsd.getFSNamesystem().removeBlocksAndUpdateSafemodeTotal(collectedBlocks); } return ret; }
Example 9
Source File: FSDirRenameOp.java From big-c with Apache License 2.0 | 5 votes |
/** * @see {@link #unprotectedRenameTo(FSDirectory, String, String, INodesInPath, * INodesInPath, long, BlocksMapUpdateInfo, Options.Rename...)} */ static void renameTo(FSDirectory fsd, FSPermissionChecker pc, String src, String dst, BlocksMapUpdateInfo collectedBlocks, boolean logRetryCache, Options.Rename... options) throws IOException { final INodesInPath srcIIP = fsd.getINodesInPath4Write(src, false); final INodesInPath dstIIP = fsd.getINodesInPath4Write(dst, false); if (fsd.isPermissionEnabled()) { // Rename does not operate on link targets // Do not resolveLink when checking permissions of src and dst // Check write access to parent of src fsd.checkPermission(pc, srcIIP, false, null, FsAction.WRITE, null, null, false); // Check write access to ancestor of dst fsd.checkPermission(pc, dstIIP, false, FsAction.WRITE, null, null, null, false); } if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug("DIR* FSDirectory.renameTo: " + src + " to " + dst); } final long mtime = Time.now(); fsd.writeLock(); try { if (unprotectedRenameTo(fsd, src, dst, srcIIP, dstIIP, mtime, collectedBlocks, options)) { FSDirDeleteOp.incrDeletedFileCount(1); } } finally { fsd.writeUnlock(); } fsd.getEditLog().logRename(src, dst, mtime, logRetryCache, options); }
Example 10
Source File: FSDirRenameOp.java From big-c with Apache License 2.0 | 5 votes |
/** * The new rename which has the POSIX semantic. */ static Map.Entry<BlocksMapUpdateInfo, HdfsFileStatus> renameToInt( FSDirectory fsd, final String srcArg, final String dstArg, boolean logRetryCache, Options.Rename... options) throws IOException { String src = srcArg; String dst = dstArg; if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug("DIR* NameSystem.renameTo: with options -" + " " + src + " to " + dst); } if (!DFSUtil.isValidName(dst)) { throw new InvalidPathException("Invalid name: " + dst); } final FSPermissionChecker pc = fsd.getPermissionChecker(); byte[][] srcComponents = FSDirectory.getPathComponentsForReservedPath(src); byte[][] dstComponents = FSDirectory.getPathComponentsForReservedPath(dst); BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo(); src = fsd.resolvePath(pc, src, srcComponents); dst = fsd.resolvePath(pc, dst, dstComponents); renameTo(fsd, pc, src, dst, collectedBlocks, logRetryCache, options); INodesInPath dstIIP = fsd.getINodesInPath(dst, false); HdfsFileStatus resultingStat = fsd.getAuditFileInfo(dstIIP); return new AbstractMap.SimpleImmutableEntry<>( collectedBlocks, resultingStat); }
Example 11
Source File: FSEditLog.java From hadoop with Apache License 2.0 | 5 votes |
/** * Add rename record to edit log. * * The destination should be the file name, not the destination directory. */ void logRename(String src, String dst, long timestamp, boolean toLogRpcIds, Options.Rename... options) { RenameOp op = RenameOp.getInstance(cache.get()) .setSource(src) .setDestination(dst) .setTimestamp(timestamp) .setOptions(options); logRpcIds(op, toLogRpcIds); logEdit(op); }
Example 12
Source File: FSDirRenameOp.java From hadoop with Apache License 2.0 | 5 votes |
/** * Rename src to dst. * <br> * Note: This is to be used by {@link org.apache.hadoop.hdfs.server * .namenode.FSEditLogLoader} only. * <br> * * @param fsd FSDirectory * @param src source path * @param dst destination path * @param timestamp modification time * @param options Rename options */ static boolean renameForEditLog( FSDirectory fsd, String src, String dst, long timestamp, Options.Rename... options) throws IOException { BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo(); final INodesInPath srcIIP = fsd.getINodesInPath4Write(src, false); final INodesInPath dstIIP = fsd.getINodesInPath4Write(dst, false); boolean ret = unprotectedRenameTo(fsd, src, dst, srcIIP, dstIIP, timestamp, collectedBlocks, options); if (!collectedBlocks.getToDeleteList().isEmpty()) { fsd.getFSNamesystem().removeBlocksAndUpdateSafemodeTotal(collectedBlocks); } return ret; }
Example 13
Source File: FSDirRenameOp.java From hadoop with Apache License 2.0 | 5 votes |
/** * @see {@link #unprotectedRenameTo(FSDirectory, String, String, INodesInPath, * INodesInPath, long, BlocksMapUpdateInfo, Options.Rename...)} */ static void renameTo(FSDirectory fsd, FSPermissionChecker pc, String src, String dst, BlocksMapUpdateInfo collectedBlocks, boolean logRetryCache, Options.Rename... options) throws IOException { final INodesInPath srcIIP = fsd.getINodesInPath4Write(src, false); final INodesInPath dstIIP = fsd.getINodesInPath4Write(dst, false); if (fsd.isPermissionEnabled()) { // Rename does not operate on link targets // Do not resolveLink when checking permissions of src and dst // Check write access to parent of src fsd.checkPermission(pc, srcIIP, false, null, FsAction.WRITE, null, null, false); // Check write access to ancestor of dst fsd.checkPermission(pc, dstIIP, false, FsAction.WRITE, null, null, null, false); } if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug("DIR* FSDirectory.renameTo: " + src + " to " + dst); } final long mtime = Time.now(); fsd.writeLock(); try { if (unprotectedRenameTo(fsd, src, dst, srcIIP, dstIIP, mtime, collectedBlocks, options)) { FSDirDeleteOp.incrDeletedFileCount(1); } } finally { fsd.writeUnlock(); } fsd.getEditLog().logRename(src, dst, mtime, logRetryCache, options); }
Example 14
Source File: FSDirRenameOp.java From hadoop with Apache License 2.0 | 5 votes |
/** * The new rename which has the POSIX semantic. */ static Map.Entry<BlocksMapUpdateInfo, HdfsFileStatus> renameToInt( FSDirectory fsd, final String srcArg, final String dstArg, boolean logRetryCache, Options.Rename... options) throws IOException { String src = srcArg; String dst = dstArg; if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug("DIR* NameSystem.renameTo: with options -" + " " + src + " to " + dst); } if (!DFSUtil.isValidName(dst)) { throw new InvalidPathException("Invalid name: " + dst); } final FSPermissionChecker pc = fsd.getPermissionChecker(); byte[][] srcComponents = FSDirectory.getPathComponentsForReservedPath(src); byte[][] dstComponents = FSDirectory.getPathComponentsForReservedPath(dst); BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo(); src = fsd.resolvePath(pc, src, srcComponents); dst = fsd.resolvePath(pc, dst, dstComponents); renameTo(fsd, pc, src, dst, collectedBlocks, logRetryCache, options); INodesInPath dstIIP = fsd.getINodesInPath(dst, false); HdfsFileStatus resultingStat = fsd.getAuditFileInfo(dstIIP); return new AbstractMap.SimpleImmutableEntry<>( collectedBlocks, resultingStat); }
Example 15
Source File: WebHdfsFileSystem.java From hadoop with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public void rename(final Path src, final Path dst, final Options.Rename... options) throws IOException { statistics.incrementWriteOps(1); final HttpOpParam.Op op = PutOpParam.Op.RENAME; new FsPathRunner(op, src, new DestinationParam(makeQualified(dst).toUri().getPath()), new RenameOptionSetParam(options) ).run(); }
Example 16
Source File: HadoopUtils.java From incubator-gobblin with Apache License 2.0 | 4 votes |
/** * A wrapper around {@link FileContext#rename(Path, Path, Options.Rename...)}}. */ public static void renamePath(FileContext fc, Path oldName, Path newName, boolean overwrite) throws IOException { Options.Rename renameOptions = (overwrite) ? Options.Rename.OVERWRITE : Options.Rename.NONE; fc.rename(oldName, newName, renameOptions); }
Example 17
Source File: ClientProtocol.java From big-c with Apache License 2.0 | 3 votes |
/** * Rename src to dst. * <ul> * <li>Fails if src is a file and dst is a directory. * <li>Fails if src is a directory and dst is a file. * <li>Fails if the parent of dst does not exist or is a file. * </ul> * <p> * Without OVERWRITE option, rename fails if the dst already exists. * With OVERWRITE option, rename overwrites the dst, if it is a file * or an empty directory. Rename fails if dst is a non-empty directory. * <p> * This implementation of rename is atomic. * <p> * @param src existing file or directory name. * @param dst new name. * @param options Rename options * * @throws AccessControlException If access is denied * @throws DSQuotaExceededException If rename violates disk space * quota restriction * @throws FileAlreadyExistsException If <code>dst</code> already exists and * <code>options</options> has {@link Rename#OVERWRITE} option * false. * @throws FileNotFoundException If <code>src</code> does not exist * @throws NSQuotaExceededException If rename violates namespace * quota restriction * @throws ParentNotDirectoryException If parent of <code>dst</code> * is not a directory * @throws SafeModeException rename not allowed in safemode * @throws UnresolvedLinkException If <code>src</code> or * <code>dst</code> contains a symlink * @throws SnapshotAccessControlException if path is in RO snapshot * @throws IOException If an I/O error occurred */ @AtMostOnce public void rename2(String src, String dst, Options.Rename... options) throws AccessControlException, DSQuotaExceededException, FileAlreadyExistsException, FileNotFoundException, NSQuotaExceededException, ParentNotDirectoryException, SafeModeException, UnresolvedLinkException, SnapshotAccessControlException, IOException;
Example 18
Source File: ClientProtocol.java From hadoop with Apache License 2.0 | 3 votes |
/** * Rename src to dst. * <ul> * <li>Fails if src is a file and dst is a directory. * <li>Fails if src is a directory and dst is a file. * <li>Fails if the parent of dst does not exist or is a file. * </ul> * <p> * Without OVERWRITE option, rename fails if the dst already exists. * With OVERWRITE option, rename overwrites the dst, if it is a file * or an empty directory. Rename fails if dst is a non-empty directory. * <p> * This implementation of rename is atomic. * <p> * @param src existing file or directory name. * @param dst new name. * @param options Rename options * * @throws AccessControlException If access is denied * @throws DSQuotaExceededException If rename violates disk space * quota restriction * @throws FileAlreadyExistsException If <code>dst</code> already exists and * <code>options</options> has {@link Rename#OVERWRITE} option * false. * @throws FileNotFoundException If <code>src</code> does not exist * @throws NSQuotaExceededException If rename violates namespace * quota restriction * @throws ParentNotDirectoryException If parent of <code>dst</code> * is not a directory * @throws SafeModeException rename not allowed in safemode * @throws UnresolvedLinkException If <code>src</code> or * <code>dst</code> contains a symlink * @throws SnapshotAccessControlException if path is in RO snapshot * @throws IOException If an I/O error occurred */ @AtMostOnce public void rename2(String src, String dst, Options.Rename... options) throws AccessControlException, DSQuotaExceededException, FileAlreadyExistsException, FileNotFoundException, NSQuotaExceededException, ParentNotDirectoryException, SafeModeException, UnresolvedLinkException, SnapshotAccessControlException, IOException;
Example 19
Source File: RenameOptionSetParam.java From hadoop with Apache License 2.0 | 2 votes |
/** * Constructor. * @param options rename options. */ public RenameOptionSetParam(final Options.Rename... options) { super(DOMAIN, toEnumSet(Options.Rename.class, options)); }
Example 20
Source File: RenameOptionSetParam.java From big-c with Apache License 2.0 | 2 votes |
/** * Constructor. * @param options rename options. */ public RenameOptionSetParam(final Options.Rename... options) { super(DOMAIN, toEnumSet(Options.Rename.class, options)); }