Skip to content

Commit 5353289

Browse files
Jing9omalley
authored andcommitted
HDFS-9894. Add unsetStoragePolicy API to FileContext/AbstractFileSystem and derivatives. Contributed by Xiaobing Zhou.
(cherry picked from commit 7149cdb3c2d9dd390cd8668883cbe5db94090e0a)
1 parent a96ea52 commit 5353289

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
@@ -2705,6 +2705,23 @@ public Void next(final AbstractFileSystem fs, final Path p)
27052705
}.resolve(this, absF);
27062706
}
27072707

2708+
/**
2709+
* Unset the storage policy set for a given file or directory.
2710+
* @param src file or directory path.
2711+
* @throws IOException
2712+
*/
2713+
public void unsetStoragePolicy(final Path src) throws IOException {
2714+
final Path absF = fixRelativePart(src);
2715+
new FSLinkResolver<Void>() {
2716+
@Override
2717+
public Void next(final AbstractFileSystem fs, final Path p)
2718+
throws IOException {
2719+
fs.unsetStoragePolicy(src);
2720+
return null;
2721+
}
2722+
}.resolve(this, absF);
2723+
}
2724+
27082725
/**
27092726
* Query the effective storage policy ID for the given file or directory.
27102727
*

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
@@ -2649,7 +2649,7 @@ public void setStoragePolicy(final Path src, final String policyName)
26492649
* @param src file or directory path.
26502650
* @throws IOException
26512651
*/
2652-
public void unsetStoragePolicy(Path src) throws IOException {
2652+
public void unsetStoragePolicy(final Path src) throws IOException {
26532653
throw new UnsupportedOperationException(getClass().getSimpleName()
26542654
+ " doesn't support unsetStoragePolicy");
26552655
}

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)