From 755998e92dfdd9e18df3cd40de51f96d4685e20e Mon Sep 17 00:00:00 2001 From: Andrew Purtell Date: Wed, 27 Aug 2014 21:43:59 -0700 Subject: [PATCH] HBASE-11841 [0.98] Option for disabling location prefetch --- .../hadoop/hbase/client/HConnectionManager.java | 26 +++++----------------- .../java/org/apache/hadoop/hbase/HConstants.java | 10 +++++++++ hbase-common/src/main/resources/hbase-default.xml | 11 +++++++++ .../hadoop/hbase/client/TestFromClientSide.java | 12 ++++++++++ 4 files changed, 39 insertions(+), 20 deletions(-) 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(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 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. */ 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. hbase.client.localityCheck.threadPoolSize 2 + + hbase.client.prefetch + true + Toggles region location prefetching on or off. + + + hbase.client.prefetch.limit + 10 + The maximum number of region locations that will be + prefetched at one time. + 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 -- 1.8.5.2 (Apple Git-48)