diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java index fca237d5333..33c03cae21f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java @@ -719,6 +719,14 @@ public class HRegionFileSystem { } } + static boolean mkdirs(FileSystem fs, Configuration conf, Path dir) throws IOException { + if (FSUtils.isDistributedFileSystem(fs) || + !conf.getBoolean(HConstants.ENABLE_DATA_FILE_UMASK, false)) { + return fs.mkdirs(dir); + } + FsPermission perms = FSUtils.getFilePermissions(fs, conf, HConstants.DATA_FILE_UMASK_KEY); + return fs.mkdirs(dir, perms); + } /** * Create the region merges directory. * @throws IOException If merges dir already exists or we fail to create it. @@ -734,7 +742,7 @@ public class HRegionFileSystem { + " before creating them again."); } } - if (!fs.mkdirs(mergesdir)) + if (!mkdirs(fs, conf, mergesdir)) throw new IOException("Failed create of " + mergesdir); } @@ -1026,7 +1034,7 @@ public class HRegionFileSystem { IOException lastIOE = null; do { try { - return fs.mkdirs(dir); + return mkdirs(fs, conf, dir); } catch (IOException ioe) { lastIOE = ioe; if (fs.exists(dir)) return true; // directory is present diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java index b7e1736cc9f..28c08926c7c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java @@ -720,7 +720,9 @@ public class StoreFile { } if (!fs.exists(dir)) { - fs.mkdirs(dir); + // Handle permission for non-HDFS filesystem properly + // See HBASE-17710 + HRegionFileSystem.mkdirs(fs, conf, dir); } if (filePath == null) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java index d3df8b735d6..3e2d2302634 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java @@ -197,6 +197,20 @@ public abstract class FSUtils { } } + /** + * @return True is fs is instance of DistributedFileSystem + * @throws IOException + */ + public static boolean isDistributedFileSystem(final FileSystem fs) throws IOException { + FileSystem fileSystem = fs; + // If passed an instance of HFileSystem, it fails instanceof DistributedFileSystem. + // Check its backing fs for dfs-ness. + if (fs instanceof HFileSystem) { + fileSystem = ((HFileSystem)fs).getBackingFs(); + } + return fileSystem instanceof DistributedFileSystem; + } + /** * Compare of path component. Does not consider schema; i.e. if schemas * different but path starts with rootPath,