diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CommonFSUtils.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CommonFSUtils.java index 800764954569..fe6f3bc238a9 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CommonFSUtils.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CommonFSUtils.java @@ -17,6 +17,8 @@ */ package org.apache.hadoop.hbase.util; +import static org.apache.hadoop.fs.CommonPathCapabilities.FS_STORAGEPOLICY; + import java.io.FileNotFoundException; import java.io.IOException; import java.net.URI; @@ -515,6 +517,11 @@ private static void invokeSetStoragePolicy(final FileSystem fs, final Path path, final String storagePolicy) throws IOException { Exception toThrow = null; + if (!fs.hasPathCapability(path, FS_STORAGEPOLICY)) { + LOG.debug("The file system does not support storage policy."); + return; + } + try { fs.setStoragePolicy(path, storagePolicy); LOG.debug("Set storagePolicy={} for path={}", storagePolicy, path); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSUtils.java index ffd9a0e0a389..8e2ce8dd8c11 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSUtils.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSUtils.java @@ -26,6 +26,8 @@ import java.io.File; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.util.List; import java.util.Random; import org.apache.hadoop.conf.Configuration; @@ -415,8 +417,9 @@ public void testSetStoragePolicyDefault() throws Exception { * Note: currently the default policy is set to defer to HDFS and this case is to verify the * logic, will need to remove the check if the default policy is changed */ - private void verifyNoHDFSApiInvocationForDefaultPolicy() { + private void verifyNoHDFSApiInvocationForDefaultPolicy() throws URISyntaxException, IOException { FileSystem testFs = new AlwaysFailSetStoragePolicyFileSystem(); + testFs.initialize(new URI("hdfs://localhost/"), conf); // There should be no exception thrown when setting to default storage policy, which indicates // the HDFS API hasn't been called try {