Skip to content

Commit 356b4b6

Browse files
committed
HBASE-27746 Check if the file system supports storage policy before invoking setStoragePolicy() (apache#5189)
(cherry picked from commit 0646151) (cherry picked from commit 35b11eb) (cherry picked from commit d93c0c0)
1 parent 5328fa2 commit 356b4b6

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.lang.reflect.InvocationTargetException;
@@ -519,6 +521,11 @@ private static void invokeSetStoragePolicy(final FileSystem fs, final Path path,
519521
final String storagePolicy) throws IOException {
520522
Exception toThrow = null;
521523

524+
if (!fs.hasPathCapability(path, FS_STORAGEPOLICY)) {
525+
LOG.debug("The file system does not support storage policy.");
526+
return;
527+
}
528+
522529
try {
523530
fs.setStoragePolicy(path, storagePolicy);
524531
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)