hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1576930 - /hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Date Wed, 12 Mar 2014 21:34:33 GMT
Author: stack
Date: Wed Mar 12 21:34:33 2014
New Revision: 1576930

URL: http://svn.apache.org/r1576930
Log:
HBASE-10679 Both clients get wrong scan results if the first scanner expires and the second
scanner is created with the same scannerId on the same region

Modified:
    hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java

Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1576930&r1=1576929&r2=1576930&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Wed Mar 12 21:34:33 2014
@@ -42,6 +42,7 @@ import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ConcurrentSkipListMap;
@@ -251,6 +252,8 @@ public class HRegionServer implements Cl
 
   private final Random rand;
 
+  private final AtomicLong scannerIdGen = new AtomicLong(0L);
+
   /*
    * Strings to be used in forming the exception message for
    * RegionsAlreadyInTransitionException.
@@ -2708,18 +2711,16 @@ public class HRegionServer implements Cl
   }
 
   protected long addScanner(RegionScanner s, HRegion r) throws LeaseStillHeldException {
-    long scannerId = -1;
-    while (true) {
-      scannerId = Math.abs(rand.nextLong() << 24) ^ startcode;
-      String scannerName = String.valueOf(scannerId);
-      RegionScannerHolder existing =
-        scanners.putIfAbsent(scannerName, new RegionScannerHolder(s, r));
-      if (existing == null) {
-        this.leases.createLease(scannerName, this.scannerLeaseTimeoutPeriod,
-          new ScannerListener(scannerName));
-        break;
-      }
-    }
+    long scannerId = this.scannerIdGen.incrementAndGet();
+    String scannerName = String.valueOf(scannerId);
+
+    RegionScannerHolder existing =
+      scanners.putIfAbsent(scannerName, new RegionScannerHolder(s, r));
+    assert existing == null : "scannerId must be unique within regionserver's whole lifecycle!";
+
+    this.leases.createLease(scannerName, this.scannerLeaseTimeoutPeriod,
+        new ScannerListener(scannerName));
+
     return scannerId;
   }
 



Mime
View raw message