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 5e0be7312a6..b18e1487669 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 @@ -910,6 +910,16 @@ public final class HConstants { public static final String ENABLE_WAL_COMPRESSION = "hbase.regionserver.wal.enablecompression"; + /** Configuration name of WAL storage policy + * Valid values are: + * NONE: no preference in destination of replicas + * ONE_SSD: place only one replica in SSD and the remaining in default storage + * and ALL_SSD: place all replica on SSD + * + * See http://hadoop.apache.org/docs/r2.6.0/hadoop-project-dist/hadoop-hdfs/ArchivalStorage.html*/ + public static final String WAL_STORAGE_POLICY = "hbase.wal.storage.policy"; + public static final String DEFAULT_WAL_STORAGE_POLICY = "NONE"; + /** 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 4a247c9c519..c482fa55d62 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 @@ -492,6 +492,8 @@ 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, HConstants.WAL_STORAGE_POLICY, + HConstants.DEFAULT_WAL_STORAGE_POLICY); 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 ef1a0ce15d1..94f149575da 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 @@ -100,6 +100,45 @@ public abstract class FSUtils { super(); } + /* + * Sets storage policy for given path according to config setting + * @param fs + * @param conf + * @param path the Path whose storage policy is to be set + * @param policyKey + * @param defaultPolicy + */ + public static void setStoragePolicy(final FileSystem fs, final Configuration conf, + final Path path, final String policyKey, final String defaultPolicy) { + String storagePolicy = conf.get(policyKey, defaultPolicy).toUpperCase(); + if (!storagePolicy.equals(defaultPolicy) && + 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("set " + 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