You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by je...@apache.org on 2015/08/25 18:03:25 UTC

hbase git commit: HBASE-14275 Backport to 0.98 HBASE-10785 Metas own location should be cached

Repository: hbase
Updated Branches:
  refs/heads/0.98 da8f48472 -> c0abda2e1


HBASE-14275 Backport to 0.98 HBASE-10785 Metas own location should be cached


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/c0abda2e
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/c0abda2e
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/c0abda2e

Branch: refs/heads/0.98
Commit: c0abda2e110772c58b5520789ffd53f287b399cf
Parents: da8f484
Author: Jerry He <je...@apache.org>
Authored: Tue Aug 25 09:02:20 2015 -0700
Committer: Jerry He <je...@apache.org>
Committed: Tue Aug 25 09:02:20 2015 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/client/HConnectionManager.java | 37 +++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/c0abda2e/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 a85bda6..c558364 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
@@ -614,6 +614,7 @@ public class HConnectionManager {
     ClusterStatusListener clusterStatusListener;
 
     private final Object userRegionLock = new Object();
+    private final Object metaRegionLock = new Object();
 
     // We have a single lock for master & zk to prevent deadlocks. Having
     //  one lock for ZK and one lock for master is not possible:
@@ -1158,7 +1159,7 @@ public class HConnectionManager {
       }
 
       if (tableName.equals(TableName.META_TABLE_NAME)) {
-        return this.registry.getMetaRegionLocation();
+        return locateMeta(tableName, useCache);
       } else {
         // Region not in the cache - have to go to the meta RS
         return locateRegionInMeta(TableName.META_TABLE_NAME, tableName, row,
@@ -1166,6 +1167,40 @@ public class HConnectionManager {
       }
     }
 
+    private HRegionLocation locateMeta(final TableName tableName,
+        boolean useCache) throws IOException {
+      // HBASE-10785: We cache the location of the META itself, so that we are not overloading
+      // zookeeper with one request for every region lookup. We cache the META with empty row
+      // key in MetaCache.
+      byte[] metaCacheKey = HConstants.EMPTY_START_ROW; // use byte[0] as the row for meta
+      HRegionLocation location = null;
+      if (useCache) {
+        location = getCachedLocation(tableName, metaCacheKey);
+        if (location != null) {
+          return location;
+        }
+      }
+
+      // only one thread should do the lookup.
+      synchronized (metaRegionLock) {
+        // Check the cache again for a hit in case some other thread made the
+        // same query while we were waiting on the lock.
+        if (useCache) {
+          location = getCachedLocation(tableName, metaCacheKey);
+          if (location != null) {
+            return location;
+          }
+        }
+
+        // Look up from zookeeper
+        location = this.registry.getMetaRegionLocation();
+        if (location != null) {
+          cacheLocation(tableName, null, location);
+        }
+      }
+      return location;
+    }
+
     /*
      * Search hbase:meta for the HRegionLocation info that contains the table and
      * row we're seeking. It will prefetch certain number of regions info and