From 7b0acc292e1854b09c6cedc4dae1f6dae07779bf Mon Sep 17 00:00:00 2001 From: Gary Helmling Date: Wed, 21 Sep 2016 17:43:41 -0700 Subject: [PATCH] HBASE-16146 Remove thread local usage in Counter --- .../org/apache/hadoop/hbase/util/Counter.java | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Counter.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Counter.java index d4cfe26efbc..0d3a5c64230 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Counter.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Counter.java @@ -110,25 +110,12 @@ public class Counter { return h; } - private static class IndexHolder { - int index = hash(); - } - - private final ThreadLocal indexHolderThreadLocal = - new ThreadLocal() { - @Override - protected IndexHolder initialValue() { - return new IndexHolder(); - } - }; - public void add(long delta) { Container container = containerRef.get(); Cell[] cells = container.cells; int mask = cells.length - 1; - IndexHolder indexHolder = indexHolderThreadLocal.get(); - int baseIndex = indexHolder.index; + int baseIndex = hash(); if(cells[baseIndex & mask].add(delta)) { return; } @@ -141,8 +128,6 @@ public class Counter { index++; } - indexHolder.index = index; - if(index - baseIndex >= cells.length && cells.length < MAX_CELLS_LENGTH && container.demoted.compareAndSet(false, true)) { @@ -183,10 +168,6 @@ public class Counter { return sum; } - public void destroy() { - indexHolderThreadLocal.remove(); - } - @Override public String toString() { Cell[] cells = containerRef.get().cells;