Skip to content

Commit 4a043b3

Browse files
Jing9omalley
authored andcommitted
HDFS-9894. Add unsetStoragePolicy API to FileContext/AbstractFileSystem and derivatives. Contributed by Xiaobing Zhou.
1 parent 14ab7a8 commit 4a043b3

File tree

7 files changed

+54
-1
lines changed

7 files changed

+54
-1
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,17 @@ public void setStoragePolicy(final Path path, final String policyName)
12361236
+ " doesn't support setStoragePolicy");
12371237
}
12381238

1239+
1240+
/**
1241+
* Unset the storage policy set for a given file or directory.
1242+
* @param src file or directory path.
1243+
* @throws IOException
1244+
*/
1245+
public void unsetStoragePolicy(final Path src) throws IOException {
1246+
throw new UnsupportedOperationException(getClass().getSimpleName()
1247+
+ " doesn't support unsetStoragePolicy");
1248+
}
1249+
12391250
/**
12401251
* Retrieve the storage policy for a given file or directory.
12411252
*

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,23 @@ public Void next(final AbstractFileSystem fs, final Path p)
26952695
}.resolve(this, absF);
26962696
}
26972697

2698+
/**
2699+
* Unset the storage policy set for a given file or directory.
2700+
* @param src file or directory path.
2701+
* @throws IOException
2702+
*/
2703+
public void unsetStoragePolicy(final Path src) throws IOException {
2704+
final Path absF = fixRelativePart(src);
2705+
new FSLinkResolver<Void>() {
2706+
@Override
2707+
public Void next(final AbstractFileSystem fs, final Path p)
2708+
throws IOException {
2709+
fs.unsetStoragePolicy(src);
2710+
return null;
2711+
}
2712+
}.resolve(this, absF);
2713+
}
2714+
26982715
/**
26992716
* Query the effective storage policy ID for the given file or directory.
27002717
*

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,7 @@ public void setStoragePolicy(final Path src, final String policyName)
26632663
* @param src file or directory path.
26642664
* @throws IOException
26652665
*/
2666-
public void unsetStoragePolicy(Path src) throws IOException {
2666+
public void unsetStoragePolicy(final Path src) throws IOException {
26672667
throw new UnsupportedOperationException(getClass().getSimpleName()
26682668
+ " doesn't support unsetStoragePolicy");
26692669
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ public void setStoragePolicy(Path path, String policyName)
405405
myFs.setStoragePolicy(path, policyName);
406406
}
407407

408+
@Override
409+
public void unsetStoragePolicy(final Path src)
410+
throws IOException {
411+
myFs.unsetStoragePolicy(src);
412+
}
413+
408414
@Override
409415
public BlockStoragePolicySpi getStoragePolicy(final Path src)
410416
throws IOException {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFs.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ public void setStoragePolicy(Path path, String policyName)
385385
myFs.setStoragePolicy(fullPath(path), policyName);
386386
}
387387

388+
@Override
389+
public void unsetStoragePolicy(final Path src)
390+
throws IOException {
391+
myFs.unsetStoragePolicy(fullPath(src));
392+
}
393+
388394
@Override
389395
public BlockStoragePolicySpi getStoragePolicy(final Path src)
390396
throws IOException {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,14 @@ public void setStoragePolicy(final Path path, final String policyName)
749749
res.targetFileSystem.setStoragePolicy(res.remainingPath, policyName);
750750
}
751751

752+
@Override
753+
public void unsetStoragePolicy(final Path src)
754+
throws IOException {
755+
InodeTree.ResolveResult<AbstractFileSystem> res =
756+
fsState.resolve(getUriPath(src), true);
757+
res.targetFileSystem.unsetStoragePolicy(res.remainingPath);
758+
}
759+
752760
/**
753761
* Retrieve the storage policy for a given file or directory.
754762
*

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/fs/Hdfs.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ public void setStoragePolicy(Path path, String policyName) throws IOException {
473473
dfs.setStoragePolicy(getUriPath(path), policyName);
474474
}
475475

476+
@Override
477+
public void unsetStoragePolicy(final Path src) throws IOException {
478+
dfs.unsetStoragePolicy(getUriPath(src));
479+
}
480+
476481
@Override
477482
public BlockStoragePolicySpi getStoragePolicy(Path src) throws IOException {
478483
return dfs.getStoragePolicy(getUriPath(src));

0 commit comments

Comments
 (0)