HBASE-15563 'counter' may overflow in BoundedGroupingStrategy (Matt Warhaftig)
This commit is contained in:
parent
686a31fbde
commit
3a7552a9f3
|
@ -46,7 +46,7 @@ public class BoundedGroupingStrategy implements RegionGroupingStrategy{
|
||||||
String idStr = Bytes.toString(identifier);
|
String idStr = Bytes.toString(identifier);
|
||||||
String groupName = groupNameCache.get(idStr);
|
String groupName = groupNameCache.get(idStr);
|
||||||
if (null == groupName) {
|
if (null == groupName) {
|
||||||
groupName = groupNames[counter.getAndIncrement() % groupNames.length];
|
groupName = groupNames[getAndIncrAtomicInteger(counter, groupNames.length)];
|
||||||
String extantName = groupNameCache.putIfAbsent(idStr, groupName);
|
String extantName = groupNameCache.putIfAbsent(idStr, groupName);
|
||||||
if (extantName != null) {
|
if (extantName != null) {
|
||||||
return extantName;
|
return extantName;
|
||||||
|
@ -55,6 +55,18 @@ public class BoundedGroupingStrategy implements RegionGroupingStrategy{
|
||||||
return groupName;
|
return groupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Non-blocking incrementing & resetting of AtomicInteger.
|
||||||
|
private int getAndIncrAtomicInteger(AtomicInteger atomicInt, int reset) {
|
||||||
|
for (;;) {
|
||||||
|
int current = atomicInt.get();
|
||||||
|
int next = (current + 1);
|
||||||
|
if (next == reset) {
|
||||||
|
next = 0;
|
||||||
|
}
|
||||||
|
if (atomicInt.compareAndSet(current, next)) return current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Configuration config, String providerId) {
|
public void init(Configuration config, String providerId) {
|
||||||
int regionGroupNumber = config.getInt(NUM_REGION_GROUPS, DEFAULT_NUM_REGION_GROUPS);
|
int regionGroupNumber = config.getInt(NUM_REGION_GROUPS, DEFAULT_NUM_REGION_GROUPS);
|
||||||
|
|
Loading…
Reference in New Issue