Skip to content

Commit 4e2842e

Browse files
authored
HBASE-27746 Check if the file system supports storage policy before invoking setStoragePolicy() (#5189) (#6170)
(cherry picked from commit 0646151)
1 parent 14e197e commit 4e2842e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

hbase-common/src/main/java/org/apache/hadoop/hbase/util/CommonFSUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hbase.util;
1919

20+
import static org.apache.hadoop.fs.CommonPathCapabilities.FS_STORAGEPOLICY;
21+
2022
import java.io.FileNotFoundException;
2123
import java.io.IOException;
2224
import java.net.URI;
@@ -515,6 +517,11 @@ private static void invokeSetStoragePolicy(final FileSystem fs, final Path path,
515517
final String storagePolicy) throws IOException {
516518
Exception toThrow = null;
517519

520+
if (!fs.hasPathCapability(path, FS_STORAGEPOLICY)) {
521+
LOG.debug("The file system does not support storage policy.");
522+
return;
523+
}
524+
518525
try {
519526
fs.setStoragePolicy(path, storagePolicy);
520527
LOG.debug("Set storagePolicy={} for path={}", storagePolicy, path);

hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import java.io.File;
2828
import java.io.IOException;
29+
import java.net.URI;
30+
import java.net.URISyntaxException;
2931
import java.util.List;
3032
import java.util.Random;
3133
import org.apache.hadoop.conf.Configuration;
@@ -415,8 +417,9 @@ public void testSetStoragePolicyDefault() throws Exception {
415417
* Note: currently the default policy is set to defer to HDFS and this case is to verify the
416418
* logic, will need to remove the check if the default policy is changed
417419
*/
418-
private void verifyNoHDFSApiInvocationForDefaultPolicy() {
420+
private void verifyNoHDFSApiInvocationForDefaultPolicy() throws URISyntaxException, IOException {
419421
FileSystem testFs = new AlwaysFailSetStoragePolicyFileSystem();
422+
testFs.initialize(new URI("hdfs://localhost/"), conf);
420423
// There should be no exception thrown when setting to default storage policy, which indicates
421424
// the HDFS API hasn't been called
422425
try {

0 commit comments

Comments
 (0)