diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java index eee5e83..ffc660b 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java @@ -918,6 +918,14 @@ public final class HConstants { public static final String ENABLE_WAL_COMPRESSION = "hbase.regionserver.wal.enablecompression"; + /** Configuration name of HLog storage policy */ + public static final String WAL_STORAGE_POLICY = "hbase.wal.storage.policy"; + public static final String DEFAULT_WAL_STORAGE_POLICY = "NONE"; + /** place only one replica in SSD and the remaining in default storage */ + public static final String WAL_STORAGE_POLICY_ONE_SSD = "ONE_SSD"; + /** place all replica on SSD */ + public static final String WAL_STORAGE_POLICY_ALL_SSD = "ALL_SSD"; + /** Region in Transition metrics threshold time */ public static final String METRICS_RIT_STUCK_WARNING_THRESHOLD="hbase.metrics.rit.stuck.warning.threshold"; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java index 1fad93d..62ef364 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java @@ -82,6 +82,7 @@ import org.apache.hadoop.hbase.wal.WALKey; import org.apache.hadoop.hbase.wal.WALPrettyPrinter; import org.apache.hadoop.hbase.wal.WALProvider.Writer; import org.apache.hadoop.hbase.wal.WALSplitter; +import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.util.StringUtils; import org.htrace.NullScope; @@ -491,6 +492,7 @@ public class FSHLog implements WAL { throw new IllegalArgumentException("wal suffix must start with '" + WAL_FILE_NAME_DELIMITER + "' but instead was '" + suffix + "'"); } + FSUtils.setStoragePolicy(fs, conf, this.fullPathLogDir); this.logFileSuffix = (suffix == null) ? "" : URLEncoder.encode(suffix, "UTF8"); this.prefixPathStr = new Path(fullPathLogDir, logFilePrefix + WAL_FILE_NAME_DELIMITER).toString(); 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 7cda55d..58b6105 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 @@ -102,6 +102,44 @@ public abstract class FSUtils { super(); } + /* + * Sets storage policy for given path according to config setting + * @param fs the FileSystem + * @param conf the Configuration + * @param path the Path whose storage policy is to be set + */ + public static void setStoragePolicy(final FileSystem fs, final Configuration conf, + final Path path) { + String storagePolicy = conf.get(HConstants.WAL_STORAGE_POLICY, + HConstants.DEFAULT_WAL_STORAGE_POLICY).toUpperCase(); + if (!storagePolicy.equals(HConstants.DEFAULT_WAL_STORAGE_POLICY) && + fs instanceof DistributedFileSystem) { + DistributedFileSystem dfs = (DistributedFileSystem)fs; + Class dfsClass = dfs.getClass(); + Method m = null; + try { + m = dfsClass.getDeclaredMethod("setStoragePolicy", + new Class[] { Path.class, String.class }); + m.setAccessible(true); + } catch (NoSuchMethodException e) { + LOG.info("FileSystem doesn't support" + + " setStoragePolicy; --HDFS-7228 not available"); + } catch (SecurityException e) { + LOG.info("Doesn't have access to setStoragePolicy on " + + "FileSystems --HDFS-7228 not available", e); + m = null; // could happen on setAccessible() + } + if (m != null) { + try { + m.invoke(dfs, path, storagePolicy); + LOG.info("setting " + storagePolicy + " for " + path); + } catch (Exception e) { + LOG.warn("Unable to set " + storagePolicy + " for " + path, e); + } + } + } + } + /** * Compare of path component. Does not consider schema; i.e. if schemas different but path * starts with rootPath, then the function returns true