hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject hbase git commit: HBASE-19260 Add lock back to avoid parallel accessing meta to locate region
Date Fri, 17 Nov 2017 22:04:49 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-2 e0c4f374b -> 50c3bf9fe


HBASE-19260 Add lock back to avoid parallel accessing meta to locate region


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

Branch: refs/heads/branch-2
Commit: 50c3bf9feb043ab1c84cbb6eefa19483de897798
Parents: e0c4f37
Author: Michael Stack <stack@apache.org>
Authored: Fri Nov 17 14:03:56 2017 -0800
Committer: Michael Stack <stack@apache.org>
Committed: Fri Nov 17 14:04:41 2017 -0800

----------------------------------------------------------------------
 .../hbase/client/ConnectionImplementation.java  | 45 +++++++++++---------
 1 file changed, 26 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/50c3bf9f/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java
index 47e8dc8..5d71d9c 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java
@@ -47,6 +47,7 @@ import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -212,6 +213,9 @@ class ConnectionImplementation implements ClusterConnection, Closeable
{
    */
   private final String alternateBufferedMutatorClassName;
 
+  /** lock guards against multiple threads trying to query the meta region at the same time
*/
+  private final ReentrantLock userRegionLock = new ReentrantLock();
+
   /**
    * constructor
    * @param conf Configuration object
@@ -788,12 +792,10 @@ class ConnectionImplementation implements ClusterConnection, Closeable
{
     }
 
     int maxAttempts = (retry ? numTries : 1);
-
     for (int tries = 0; true; tries++) {
       if (tries >= maxAttempts) {
         throw new NoServerForRegionException("Unable to find region for "
-            + Bytes.toStringBinary(row) + " in " + tableName +
-            " after " + tries + " tries.");
+            + Bytes.toStringBinary(row) + " in " + tableName + " after " + tries + " tries.");
       }
       if (useCache) {
         RegionLocations locations = getCachedLocation(tableName, row);
@@ -809,7 +811,14 @@ class ConnectionImplementation implements ClusterConnection, Closeable
{
 
       // Query the meta region
       long pauseBase = this.pause;
+      userRegionLock.lock();
       try {
+        if (useCache) {// re-check cache after get lock
+          RegionLocations locations = getCachedLocation(tableName, row);
+          if (locations != null && locations.getRegionLocation(replicaId) != null)
{
+            return locations;
+          }
+        }
         Result regionInfoRow = null;
         s.resetMvccReadPoint();
         s.setOneRowLimit();
@@ -842,23 +851,20 @@ class ConnectionImplementation implements ClusterConnection, Closeable
{
             "hbase:meta might be damaged.");
         }
         if (regionInfo.isSplit()) {
-          throw new RegionOfflineException("the only available region for" +
-            " the required row is a split parent," +
-            " the daughters should be online soon: " +
-            regionInfo.getRegionNameAsString());
+          throw new RegionOfflineException(
+              "the only available region for the required row is a split parent,"
+                  + " the daughters should be online soon: " + regionInfo.getRegionNameAsString());
         }
         if (regionInfo.isOffline()) {
-          throw new RegionOfflineException("the region is offline, could" +
-            " be caused by a disable table call: " +
-            regionInfo.getRegionNameAsString());
+          throw new RegionOfflineException("the region is offline, could"
+              + " be caused by a disable table call: " + regionInfo.getRegionNameAsString());
         }
 
         ServerName serverName = locations.getRegionLocation(replicaId).getServerName();
         if (serverName == null) {
-          throw new NoServerForRegionException("No server address listed " +
-            "in " + TableName.META_TABLE_NAME + " for region " +
-            regionInfo.getRegionNameAsString() + " containing row " +
-            Bytes.toStringBinary(row));
+          throw new NoServerForRegionException("No server address listed in "
+              + TableName.META_TABLE_NAME + " for region " + regionInfo.getRegionNameAsString()
+              + " containing row " + Bytes.toStringBinary(row));
         }
 
         if (isDeadServer(serverName)){
@@ -885,11 +891,10 @@ class ConnectionImplementation implements ClusterConnection, Closeable
{
         }
         if (tries < maxAttempts - 1) {
           if (LOG.isDebugEnabled()) {
-            LOG.debug("locateRegionInMeta parentTable=" +
-                TableName.META_TABLE_NAME + ", metaLocation=" +
-              ", attempt=" + tries + " of " +
-              maxAttempts + " failed; retrying after sleep of " +
-              ConnectionUtils.getPauseTime(pauseBase, tries) + " because: " + e.getMessage());
+            LOG.debug("locateRegionInMeta parentTable=" + TableName.META_TABLE_NAME
+                + ", metaLocation=" + ", attempt=" + tries + " of " + maxAttempts
+                + " failed; retrying after sleep of "
+                + ConnectionUtils.getPauseTime(pauseBase, tries) + " because: " + e.getMessage());
           }
         } else {
           throw e;
@@ -899,6 +904,8 @@ class ConnectionImplementation implements ClusterConnection, Closeable
{
             e instanceof NoServerForRegionException)) {
           relocateRegion(TableName.META_TABLE_NAME, metaKey, replicaId);
         }
+      } finally {
+        userRegionLock.unlock();
       }
       try{
         Thread.sleep(ConnectionUtils.getPauseTime(pauseBase, tries));


Mime
View raw message