Skip to content

Commit

Permalink
HBASE-27746 Check if the file system supports storage policy before i…
Browse files Browse the repository at this point in the history
…nvoking setStoragePolicy() (apache#5189)
  • Loading branch information
jojochuang authored Aug 20, 2024
1 parent 41dd87c commit 0646151
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0646151

Please sign in to comment.