commit 1f54e596cf0299295185673142d656a06a4f3832 Author: Enis Soztutar Date: Thu Jun 23 13:31:57 2016 -0700 HBASE-16095 Add priority to TableDescriptor and priority region open thread pool (v0) diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java index 13f1bd9..43f1e6c 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java @@ -191,6 +191,13 @@ public class HTableDescriptor implements Comparable { /** Default durability for HTD is USE_DEFAULT, which defaults to HBase-global default value */ private static final Durability DEFAULT_DURABLITY = Durability.USE_DEFAULT; + public static final String PRIORITY = "PRIORITY"; + private static final Bytes PRIORITY_KEY = + new Bytes(Bytes.toBytes(PRIORITY)); + + /** Relative priority of the table used for rpc scheduling */ + private static final int DEFAULT_PRIORITY = HConstants.NORMAL_QOS; + /* * The below are ugly but better than creating them each time till we * replace booleans being saved as Strings with plain booleans. Need a @@ -245,6 +252,7 @@ public class HTableDescriptor implements Comparable { DEFAULT_VALUES.put(DURABILITY, DEFAULT_DURABLITY.name()); //use the enum name DEFAULT_VALUES.put(REGION_REPLICATION, String.valueOf(DEFAULT_REGION_REPLICATION)); DEFAULT_VALUES.put(NORMALIZATION_ENABLED, String.valueOf(DEFAULT_NORMALIZATION_ENABLED)); + DEFAULT_VALUES.put(PRIORITY, String.valueOf(DEFAULT_PRIORITY)); for (String s : DEFAULT_VALUES.keySet()) { RESERVED_KEYWORDS.add(new Bytes(Bytes.toBytes(s))); } @@ -1110,9 +1118,13 @@ public class HTableDescriptor implements Comparable { * Returns the configured replicas per region */ public int getRegionReplication() { - byte[] val = getValue(REGION_REPLICATION_KEY); + return getIntValue(REGION_MEMSTORE_REPLICATION_KEY, DEFAULT_REGION_REPLICATION); + } + + private int getIntValue(Bytes key, int defaultVal) { + byte[] val = getValue(key); if (val == null || val.length == 0) { - return DEFAULT_REGION_REPLICATION; + return defaultVal; } return Integer.parseInt(Bytes.toString(val)); } @@ -1152,6 +1164,15 @@ public class HTableDescriptor implements Comparable { return this; } + public HTableDescriptor setPriority(int priority) { + setValue(PRIORITY_KEY, Integer.toString(priority)); + return this; + } + + public int getPriority() { + return getIntValue(PRIORITY_KEY, DEFAULT_PRIORITY); + } + /** * Returns all the column family names of the current table. The map of * HTableDescriptor contains mapping of family name to HColumnDescriptors. diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/executor/EventType.java hbase-client/src/main/java/org/apache/hadoop/hbase/executor/EventType.java index a7759c5..9b7751d 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/executor/EventType.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/executor/EventType.java @@ -137,6 +137,12 @@ public enum EventType { * Master asking RS to close meta. */ M_RS_CLOSE_META (25, ExecutorType.RS_CLOSE_META), + /** + * Messages originating from Master to RS.
+ * M_RS_OPEN_PRIORITY_REGION
+ * Master asking RS to open a priority region. + */ + M_RS_OPEN_PRIORITY_REGION (26, ExecutorType.RS_OPEN_PRIORITY_REGION), /** * Messages originating from Client to Master.
diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/executor/ExecutorType.java hbase-client/src/main/java/org/apache/hadoop/hbase/executor/ExecutorType.java index 5a16149..e9b0ad5 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/executor/ExecutorType.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/executor/ExecutorType.java @@ -47,7 +47,8 @@ public enum ExecutorType { RS_PARALLEL_SEEK (26), RS_LOG_REPLAY_OPS (27), RS_REGION_REPLICA_FLUSH_OPS (28), - RS_COMPACTED_FILES_DISCHARGER (29); + RS_COMPACTED_FILES_DISCHARGER (29), + RS_OPEN_PRIORITY_REGION (30); ExecutorType(int value) {} diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 45a1095..24c6a57 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1734,6 +1734,8 @@ public class HRegionServer extends HasThread implements conf.getInt("hbase.regionserver.executor.openregion.threads", 3)); this.service.startExecutorService(ExecutorType.RS_OPEN_META, conf.getInt("hbase.regionserver.executor.openmeta.threads", 1)); + this.service.startExecutorService(ExecutorType.RS_OPEN_PRIORITY_REGION, + conf.getInt("hbase.regionserver.executor.openpriorityregion.threads", 3)); this.service.startExecutorService(ExecutorType.RS_CLOSE_REGION, conf.getInt("hbase.regionserver.executor.closeregion.threads", 3)); this.service.startExecutorService(ExecutorType.RS_CLOSE_META, diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/OpenPriorityRegionHandler.java hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/OpenPriorityRegionHandler.java new file mode 100644 index 0000000..9f7b0d6 --- /dev/null +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/OpenPriorityRegionHandler.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.regionserver; + +import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.Server; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.executor.EventType; +import org.apache.hadoop.hbase.regionserver.handler.OpenRegionHandler; + +/** + * Handles opening of a high priority region on a region server. + *

+ * This is executed after receiving an OPEN RPC from the master or client. + */ +@InterfaceAudience.Private +public class OpenPriorityRegionHandler extends OpenRegionHandler { + protected OpenPriorityRegionHandler(Server server, RegionServerServices rsServices, + HRegionInfo regionInfo, HTableDescriptor htd, long masterSystemTime) { + super(server, rsServices, regionInfo, htd, masterSystemTime, + EventType.M_RS_OPEN_PRIORITY_REGION); + } +} diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java index c3626fd..4c6f89e 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java @@ -1725,8 +1725,14 @@ public class RSRpcServices implements HBaseRPCErrorHandler, } else { regionServer.updateRegionFavoredNodesMapping(region.getEncodedName(), regionOpenInfo.getFavoredNodesList()); - regionServer.service.submit(new OpenRegionHandler( - regionServer, regionServer, region, htd, masterSystemTime)); + + if (htd.getPriority() >= HConstants.ADMIN_QOS) { + regionServer.service.submit(new OpenPriorityRegionHandler( + regionServer, regionServer, region, htd, masterSystemTime)); + } else { + regionServer.service.submit(new OpenRegionHandler( + regionServer, regionServer, region, htd, masterSystemTime)); + } } }