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
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 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;
}