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
This commit is contained in:
Zhihong Yu 2012-09-19 17:52:06 +00:00
parent a5583054a5
commit 17a2e1663a
1 changed files with 13 additions and 6 deletions

View File

@ -281,7 +281,7 @@ public class HRegionServer implements ClientProtocol,
// Compactions // Compactions
public CompactSplitThread compactSplitThread; public CompactSplitThread compactSplitThread;
final Map<String, RegionScanner> scanners = final ConcurrentHashMap<String, RegionScanner> scanners =
new ConcurrentHashMap<String, RegionScanner>(); new ConcurrentHashMap<String, RegionScanner>();
/** /**
@ -2818,11 +2818,18 @@ public class HRegionServer implements ClientProtocol,
} }
protected long addScanner(RegionScanner s) throws LeaseStillHeldException { protected long addScanner(RegionScanner s) throws LeaseStillHeldException {
long scannerId = nextLong(); long scannerId = -1;
String scannerName = String.valueOf(scannerId); while (true) {
scanners.put(scannerName, s); scannerId = rand.nextLong();
this.leases.createLease(scannerName, this.scannerLeaseTimeoutPeriod, new ScannerListener( if (scannerId == -1) continue;
scannerName)); 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; return scannerId;
} }