Skip to content

HBASE-27746 Check if the file system supports storage policy before invoking setStoragePolicy() #5189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is required otherwise uri is null pointer and will fail hasPathCapability() API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not use the 'hdfs' scheme here? It is not HDFS, actually...

// There should be no exception thrown when setting to default storage policy, which indicates
// the HDFS API hasn't been called
try {
Expand Down