You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 04:01:20 UTC

svn commit: r1181353 - /hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/BaseScanner.java

Author: nspiegelberg
Date: Tue Oct 11 02:01:20 2011
New Revision: 1181353

URL: http://svn.apache.org/viewvc?rev=1181353&view=rev
Log:
HBASE-2755 Duplicate assignment of a region after region server recovery

Summary:
After a region server recovery, some regions may get assigned to duplicate
region servers.

This is fixed now and patch committed to public trunk.

Test Plan:
All tests passing.

DiffCamp Revision: 147426
Reviewed By: jgray
CC: jgray, hbase@lists
Revert Plan:
OK

Modified:
    hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/BaseScanner.java

Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/BaseScanner.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/BaseScanner.java?rev=1181353&r1=1181352&r2=1181353&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/BaseScanner.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/BaseScanner.java Tue Oct 11 02:01:20 2011
@@ -192,7 +192,7 @@ abstract class BaseScanner extends Chore
         long startCode = getStartCode(values);
 
         // Note Region has been assigned.
-        checkAssigned(regionServer, region, info, serverAddress, startCode);
+        checkAssigned(regionServer, region, info, serverAddress, startCode, true);
         if (isSplitParent(info)) {
           splitParents.put(info, values);
         }
@@ -532,12 +532,15 @@ abstract class BaseScanner extends Chore
    * @param info
    * @param hostnameAndPort hostname ':' port as it comes out of .META.
    * @param startCode
+   * @param checkTwice should we check twice before adding a region
+   * to unassigned pool.
    * @throws IOException
    */
   protected void checkAssigned(final HRegionInterface regionServer,
     final MetaRegion meta, final HRegionInfo info,
-    final String hostnameAndPort, final long startCode)
+    final String hostnameAndPort, final long startCode, boolean checkTwice)
   throws IOException {
+    boolean tryAgain = false;
     String serverName = null;
     String sa = hostnameAndPort;
     long sc = startCode;
@@ -574,16 +577,31 @@ abstract class BaseScanner extends Chore
       // If we can't find the HServerInfo, then add it to the list of
       //  unassigned regions.
       if (storedInfo == null) {
-        // The current assignment is invalid
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("Current assignment of " + info.getRegionNameAsString() +
-            " is not valid; " + " serverAddress=" + sa +
-            ", startCode=" + sc + " unknown.");
+        if (checkTwice) {
+          tryAgain = true;
+        } else {
+          if (LOG.isDebugEnabled()) {
+            LOG.debug("Current assignment of " + info.getRegionNameAsString() +
+              " is not valid; " + " serverAddress=" + sa +
+              ", startCode=" + sc + " unknown.");
+          }
+          // Now get the region assigned
+          this.master.getRegionManager().setUnassigned(info, true);
         }
-        // Now get the region assigned
-        this.master.getRegionManager().setUnassigned(info, true);
       }
     }
+    if (tryAgain) {
+      // The current assignment is invalid. But we need to try again.
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Current assignment of " + info.getRegionNameAsString() +
+          " is not valid; " + " serverAddress=" + sa +
+          ", startCode=" + sc + " unknown; checking once more!");
+      }
+      // passing null for hostNameAndPort will force the function
+      // to reget the assignment from META and protect against
+      // double assignment race conditions (HBASE-2755).
+      checkAssigned(regionServer, meta, info, null, 0, false);
+    }
   }
 
   /**