From 356b4b61d7d7e51c97d0c65f7c2a933fe7c34d9c Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Tue, 20 Aug 2024 14:28:42 -0700 Subject: [PATCH] HBASE-27746 Check if the file system supports storage policy before invoking setStoragePolicy() (#5189) (cherry picked from commit 0646151cd612389ce5ed3fac035a807525aea390) (cherry picked from commit 35b11ebae280ea8046a09808b80504ee3ede050a) (cherry picked from commit d93c0c05653e3b2cc9653dcf193fd1459c5bfa53) --- .../java/org/apache/hadoop/hbase/util/CommonFSUtils.java | 7 +++++++ .../java/org/apache/hadoop/hbase/util/TestFSUtils.java | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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 73bb6f38cd27..0e37e0f062e6 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.lang.reflect.InvocationTargetException; @@ -519,6 +521,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 ebac18c153ca..65383a3b8c70 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 {