From 17a2e1663ac6d9f1928922574665805e96b8c610 Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Wed, 19 Sep 2012 17:52:06 +0000 Subject: [PATCH] HBASE-6838 Regionserver may generate identical scanner name (Chunhui) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1387695 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/regionserver/HRegionServer.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index d45387b3553..c14665597c3 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -281,7 +281,7 @@ public class HRegionServer implements ClientProtocol, // Compactions public CompactSplitThread compactSplitThread; - final Map scanners = + final ConcurrentHashMap scanners = new ConcurrentHashMap(); /** @@ -2818,11 +2818,18 @@ public class HRegionServer implements ClientProtocol, } 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; }