HBASE-16146 Remove thread local usage in Counter
This commit is contained in:
parent
b47ded3b42
commit
4f29c23038
|
@ -108,25 +108,12 @@ public class Counter {
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class IndexHolder {
|
|
||||||
int index = hash();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ThreadLocal<IndexHolder> indexHolderThreadLocal =
|
|
||||||
new ThreadLocal<IndexHolder>() {
|
|
||||||
@Override
|
|
||||||
protected IndexHolder initialValue() {
|
|
||||||
return new IndexHolder();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public void add(long delta) {
|
public void add(long delta) {
|
||||||
Container container = containerRef.get();
|
Container container = containerRef.get();
|
||||||
Cell[] cells = container.cells;
|
Cell[] cells = container.cells;
|
||||||
int mask = cells.length - 1;
|
int mask = cells.length - 1;
|
||||||
|
|
||||||
IndexHolder indexHolder = indexHolderThreadLocal.get();
|
int baseIndex = hash();
|
||||||
int baseIndex = indexHolder.index;
|
|
||||||
if(cells[baseIndex & mask].add(delta)) {
|
if(cells[baseIndex & mask].add(delta)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -139,8 +126,6 @@ public class Counter {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
indexHolder.index = index;
|
|
||||||
|
|
||||||
if(index - baseIndex >= cells.length &&
|
if(index - baseIndex >= cells.length &&
|
||||||
cells.length < MAX_CELLS_LENGTH &&
|
cells.length < MAX_CELLS_LENGTH &&
|
||||||
container.demoted.compareAndSet(false, true)) {
|
container.demoted.compareAndSet(false, true)) {
|
||||||
|
@ -181,10 +166,6 @@ public class Counter {
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
|
||||||
indexHolderThreadLocal.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
Cell[] cells = containerRef.get().cells;
|
Cell[] cells = containerRef.get().cells;
|
||||||
|
|
|
@ -2011,7 +2011,6 @@ public class RpcServer implements RpcServerInterface, ConfigurationObserver {
|
||||||
LOG.trace(ignored);
|
LOG.trace(ignored);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rpcCount.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserGroupInformation createUser(ConnectionHeader head) {
|
private UserGroupInformation createUser(ConnectionHeader head) {
|
||||||
|
|
Loading…
Reference in New Issue