Repository: hbase Updated Branches: refs/heads/0.98 c47fef060 -> 4a3ddc7cb
HBASE-11841 [0.98] Option for disabling location prefetch Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/4a3ddc7c Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/4a3ddc7c Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/4a3ddc7c Branch: refs/heads/0.98 Commit: 4a3ddc7cb744759609809eef85690cd58127c85a Parents: c47fef0 Author: Andrew Purtell <[email protected]> Authored: Thu Aug 28 11:18:34 2014 -0700 Committer: Andrew Purtell <[email protected]> Committed: Thu Aug 28 11:18:34 2014 -0700 ---------------------------------------------------------------------- .../hadoop/hbase/client/HConnectionManager.java | 26 +++++--------------- .../org/apache/hadoop/hbase/HConstants.java | 10 ++++++++ .../src/main/resources/hbase-default.xml | 11 +++++++++ .../hadoop/hbase/client/TestFromClientSide.java | 12 +++++++++ 4 files changed, 39 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/4a3ddc7c/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java index 65a41eb..7b1ad7d 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -508,24 +508,6 @@ public class HConnectionManager { } /** - * It's provided for unit test cases which verify the behavior of region - * location cache prefetch. - * @return true if the region where the table and row reside is cached. - * @throws ZooKeeperConnectionException - */ - static boolean isRegionCached(Configuration conf, - final TableName tableName, - final byte[] row) - throws IOException { - return execute(new HConnectable<Boolean>(conf) { - @Override - public Boolean connect(HConnection connection) { - return ((HConnectionImplementation) connection).isRegionCached(tableName, row); - } - }); - } - - /** * This convenience method invokes the given {@link HConnectable#connect} * implementation using a {@link HConnection} instance that lasts just for the * duration of the invocation. @@ -570,6 +552,7 @@ public class HConnectionManager { private final int numTries; final int rpcTimeout; private NonceGenerator nonceGenerator = null; + private final boolean usePrefetch; private final int prefetchRegionLimit; private volatile boolean closed; @@ -720,6 +703,8 @@ public class HConnectionManager { this.nonceGenerator = new NoNonceGenerator(); } + this.usePrefetch = conf.getBoolean(HConstants.HBASE_CLIENT_PREFETCH, + HConstants.DEFAULT_HBASE_CLIENT_PREFETCH); this.prefetchRegionLimit = conf.getInt( HConstants.HBASE_CLIENT_PREFETCH_LIMIT, HConstants.DEFAULT_HBASE_CLIENT_PREFETCH_LIMIT); @@ -1203,7 +1188,7 @@ public class HConnectionManager { // region at the same time. The first will load the meta region and // the second will use the value that the first one found. if (useCache) { - if (TableName.META_TABLE_NAME.equals(parentTable) && + if (TableName.META_TABLE_NAME.equals(parentTable) && usePrefetch && getRegionCachePrefetch(tableName)) { synchronized (regionLockObject) { // Check the cache again for a hit in case some other thread made the @@ -2456,7 +2441,8 @@ public class HConnectionManager { @Override public boolean getRegionCachePrefetch(TableName tableName) { - return !regionCachePrefetchDisabledTables.contains(Bytes.mapKey(tableName.getName())); + return usePrefetch && + !regionCachePrefetchDisabledTables.contains(Bytes.mapKey(tableName.getName())); } @Override http://git-wip-us.apache.org/repos/asf/hbase/blob/4a3ddc7c/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java ---------------------------------------------------------------------- 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 cba4471..c80fa1c 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 @@ -646,6 +646,16 @@ public final class HConstants { public static int DEFAULT_HBASE_CLIENT_RETRIES_NUMBER = 31; /** + * Parameter name for client region location prefetch toggle. + */ + public static String HBASE_CLIENT_PREFETCH = "hbase.client.prefetch"; + + /** + * Default value of {@link #HBASE_CLIENT_PREFETCH}. + */ + public static boolean DEFAULT_HBASE_CLIENT_PREFETCH = true; + + /** * Parameter name for client prefetch limit, used as the maximum number of regions * info that will be prefetched. */ http://git-wip-us.apache.org/repos/asf/hbase/blob/4a3ddc7c/hbase-common/src/main/resources/hbase-default.xml ---------------------------------------------------------------------- diff --git a/hbase-common/src/main/resources/hbase-default.xml b/hbase-common/src/main/resources/hbase-default.xml index 463f434..f285cf7 100644 --- a/hbase-common/src/main/resources/hbase-default.xml +++ b/hbase-common/src/main/resources/hbase-default.xml @@ -515,6 +515,17 @@ possible configurations would overwhelm and obscure the important. <name>hbase.client.localityCheck.threadPoolSize</name> <value>2</value> </property> + <property> + <name>hbase.client.prefetch</name> + <value>true</value> + <description>Toggles region location prefetching on or off.</description> + </property> + <property> + <name>hbase.client.prefetch.limit</name> + <value>10</value> + <description>The maximum number of region locations that will be + prefetched at one time.</description> + </property> <!--Miscellaneous configuration--> <property> http://git-wip-us.apache.org/repos/asf/hbase/blob/4a3ddc7c/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index b4f3de8..7a44e5a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -63,6 +63,7 @@ import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; +import org.apache.hadoop.hbase.client.HConnectionManager.HConnectionImplementation; import org.apache.hadoop.hbase.client.metrics.ScanMetrics; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; import org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint; @@ -449,6 +450,17 @@ public class TestFromClientSide { LOG.info("Finishing testRegionCachePreWarm"); } + @Test + public void testPrefetchDisableToggle() throws Exception { + final TableName TABLENAME = TableName.valueOf("testPrefetchDisableToggle"); + Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); + conf.setBoolean(HConstants.HBASE_CLIENT_PREFETCH, false); + // We have to create a connection for the test because we are changing a + // setting normally picked up from the site configuration + HConnection connection = HConnectionManager.createConnection(conf); + assertFalse("The table is not disabled for region cache prefetch", + ((HConnectionImplementation)connection).getRegionCachePrefetch(TABLENAME)); + } /** * Verifies that getConfiguration returns the same Configuration object used
