hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1387695 - /hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Date Wed, 19 Sep 2012 17:52:07 GMT
Author: tedyu
Date: Wed Sep 19 17:52:06 2012
New Revision: 1387695

URL: http://svn.apache.org/viewvc?rev=1387695&view=rev
Log:
HBASE-6838 Regionserver may generate identical scanner name (Chunhui)


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

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1387695&r1=1387694&r2=1387695&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Wed Sep 19 17:52:06 2012
@@ -281,7 +281,7 @@ public class  HRegionServer implements C
   // Compactions
   public CompactSplitThread compactSplitThread;
 
-  final Map<String, RegionScanner> scanners =
+  final ConcurrentHashMap<String, RegionScanner> scanners =
       new ConcurrentHashMap<String, RegionScanner>();
 
   /**
@@ -2818,11 +2818,18 @@ public class  HRegionServer implements C
   }
 
   protected long addScanner(RegionScanner s) throws LeaseStillHeldException {
-    long scannerId = nextLong();
-    String scannerName = String.valueOf(scannerId);
-    scanners.put(scannerName, s);
-    this.leases.createLease(scannerName, this.scannerLeaseTimeoutPeriod, new ScannerListener(
-        scannerName));
+    long scannerId = -1;
+    while (true) {
+      scannerId = rand.nextLong();
+      if (scannerId == -1) continue;
+      String scannerName = String.valueOf(scannerId);
+      RegionScanner existing = scanners.putIfAbsent(scannerName, s);
+      if (existing == null) {
+        this.leases.createLease(scannerName, this.scannerLeaseTimeoutPeriod,
+            new ScannerListener(scannerName));
+        break;
+      }
+    }
     return scannerId;
   }
 



Mime
View raw message