HDFS-9894. Add unsetStoragePolicy API to FileContext/AbstractFileSystem and derivatives. Contributed by Xiaobing Zhou.

(cherry picked from commit 7149cdb3c2d9dd390cd8668883cbe5db94090e0a)
This commit is contained in:
Jing Zhao 2016-04-21 18:07:35 -07:00 committed by Owen O'Malley
parent a96ea528cc
commit 5353289c8c
7 changed files with 54 additions and 1 deletions

View File

@ -1236,6 +1236,17 @@ public abstract class AbstractFileSystem {
+ " doesn't support setStoragePolicy"); + " doesn't support setStoragePolicy");
} }
/**
* Unset the storage policy set for a given file or directory.
* @param src file or directory path.
* @throws IOException
*/
public void unsetStoragePolicy(final Path src) throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName()
+ " doesn't support unsetStoragePolicy");
}
/** /**
* Retrieve the storage policy for a given file or directory. * Retrieve the storage policy for a given file or directory.
* *

View File

@ -2705,6 +2705,23 @@ public class FileContext {
}.resolve(this, absF); }.resolve(this, absF);
} }
/**
* Unset the storage policy set for a given file or directory.
* @param src file or directory path.
* @throws IOException
*/
public void unsetStoragePolicy(final Path src) throws IOException {
final Path absF = fixRelativePart(src);
new FSLinkResolver<Void>() {
@Override
public Void next(final AbstractFileSystem fs, final Path p)
throws IOException {
fs.unsetStoragePolicy(src);
return null;
}
}.resolve(this, absF);
}
/** /**
* Query the effective storage policy ID for the given file or directory. * Query the effective storage policy ID for the given file or directory.
* *

View File

@ -2649,7 +2649,7 @@ public abstract class FileSystem extends Configured implements Closeable {
* @param src file or directory path. * @param src file or directory path.
* @throws IOException * @throws IOException
*/ */
public void unsetStoragePolicy(Path src) throws IOException { public void unsetStoragePolicy(final Path src) throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName() throw new UnsupportedOperationException(getClass().getSimpleName()
+ " doesn't support unsetStoragePolicy"); + " doesn't support unsetStoragePolicy");
} }

View File

@ -405,6 +405,12 @@ public abstract class FilterFs extends AbstractFileSystem {
myFs.setStoragePolicy(path, policyName); myFs.setStoragePolicy(path, policyName);
} }
@Override
public void unsetStoragePolicy(final Path src)
throws IOException {
myFs.unsetStoragePolicy(src);
}
@Override @Override
public BlockStoragePolicySpi getStoragePolicy(final Path src) public BlockStoragePolicySpi getStoragePolicy(final Path src)
throws IOException { throws IOException {

View File

@ -385,6 +385,12 @@ class ChRootedFs extends AbstractFileSystem {
myFs.setStoragePolicy(fullPath(path), policyName); myFs.setStoragePolicy(fullPath(path), policyName);
} }
@Override
public void unsetStoragePolicy(final Path src)
throws IOException {
myFs.unsetStoragePolicy(fullPath(src));
}
@Override @Override
public BlockStoragePolicySpi getStoragePolicy(final Path src) public BlockStoragePolicySpi getStoragePolicy(final Path src)
throws IOException { throws IOException {

View File

@ -749,6 +749,14 @@ public class ViewFs extends AbstractFileSystem {
res.targetFileSystem.setStoragePolicy(res.remainingPath, policyName); res.targetFileSystem.setStoragePolicy(res.remainingPath, policyName);
} }
@Override
public void unsetStoragePolicy(final Path src)
throws IOException {
InodeTree.ResolveResult<AbstractFileSystem> res =
fsState.resolve(getUriPath(src), true);
res.targetFileSystem.unsetStoragePolicy(res.remainingPath);
}
/** /**
* Retrieve the storage policy for a given file or directory. * Retrieve the storage policy for a given file or directory.
* *

View File

@ -473,6 +473,11 @@ public class Hdfs extends AbstractFileSystem {
dfs.setStoragePolicy(getUriPath(path), policyName); dfs.setStoragePolicy(getUriPath(path), policyName);
} }
@Override
public void unsetStoragePolicy(final Path src) throws IOException {
dfs.unsetStoragePolicy(getUriPath(src));
}
@Override @Override
public BlockStoragePolicySpi getStoragePolicy(Path src) throws IOException { public BlockStoragePolicySpi getStoragePolicy(Path src) throws IOException {
return dfs.getStoragePolicy(getUriPath(src)); return dfs.getStoragePolicy(getUriPath(src));