Search in sources :

Example 1 with FileSystemLinkResolver

use of org.apache.hadoop.fs.FileSystemLinkResolver in project hadoop by apache.

the class DistributedFileSystem method rename.

@SuppressWarnings("deprecation")
@Override
public boolean rename(Path src, Path dst) throws IOException {
    statistics.incrementWriteOps(1);
    storageStatistics.incrementOpCounter(OpType.RENAME);
    final Path absSrc = fixRelativePart(src);
    final Path absDst = fixRelativePart(dst);
    // Try the rename without resolving first
    try {
        return dfs.rename(getPathName(absSrc), getPathName(absDst));
    } catch (UnresolvedLinkException e) {
        // Fully resolve the source
        final Path source = getFileLinkStatus(absSrc).getPath();
        // Keep trying to resolve the destination
        return new FileSystemLinkResolver<Boolean>() {

            @Override
            public Boolean doCall(final Path p) throws IOException {
                return dfs.rename(getPathName(source), getPathName(p));
            }

            @Override
            public Boolean next(final FileSystem fs, final Path p) throws IOException {
                // Should just throw an error in FileSystem#checkPath
                return doCall(p);
            }
        }.resolve(this, absDst);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) UnresolvedLinkException(org.apache.hadoop.fs.UnresolvedLinkException) FileSystem(org.apache.hadoop.fs.FileSystem) FileSystemLinkResolver(org.apache.hadoop.fs.FileSystemLinkResolver)

Example 2 with FileSystemLinkResolver

use of org.apache.hadoop.fs.FileSystemLinkResolver in project hadoop by apache.

the class DistributedFileSystem method rename.

/**
   * This rename operation is guaranteed to be atomic.
   */
@SuppressWarnings("deprecation")
@Override
public void rename(Path src, Path dst, final Options.Rename... options) throws IOException {
    statistics.incrementWriteOps(1);
    storageStatistics.incrementOpCounter(OpType.RENAME);
    final Path absSrc = fixRelativePart(src);
    final Path absDst = fixRelativePart(dst);
    // Try the rename without resolving first
    try {
        dfs.rename(getPathName(absSrc), getPathName(absDst), options);
    } catch (UnresolvedLinkException e) {
        // Fully resolve the source
        final Path source = getFileLinkStatus(absSrc).getPath();
        // Keep trying to resolve the destination
        new FileSystemLinkResolver<Void>() {

            @Override
            public Void doCall(final Path p) throws IOException {
                dfs.rename(getPathName(source), getPathName(p), options);
                return null;
            }

            @Override
            public Void next(final FileSystem fs, final Path p) throws IOException {
                // Should just throw an error in FileSystem#checkPath
                return doCall(p);
            }
        }.resolve(this, absDst);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) UnresolvedLinkException(org.apache.hadoop.fs.UnresolvedLinkException) FileSystem(org.apache.hadoop.fs.FileSystem) FileSystemLinkResolver(org.apache.hadoop.fs.FileSystemLinkResolver)

Aggregations

FileSystem (org.apache.hadoop.fs.FileSystem)2 FileSystemLinkResolver (org.apache.hadoop.fs.FileSystemLinkResolver)2 Path (org.apache.hadoop.fs.Path)2 UnresolvedLinkException (org.apache.hadoop.fs.UnresolvedLinkException)2