diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractFSWAL.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractFSWAL.java index 9b31834..87fe13e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractFSWAL.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractFSWAL.java @@ -34,8 +34,6 @@ import java.util.List; import java.util.Map; import java.util.OptionalLong; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -62,7 +60,6 @@ import org.apache.hadoop.hbase.log.HBaseMarkers; import org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl; import org.apache.hadoop.hbase.trace.TraceUtil; import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.hbase.util.CollectionUtils; import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.FSUtils; @@ -272,10 +269,9 @@ public abstract class AbstractFSWAL implements WAL { *

* TODO: Reuse FSWALEntry's rather than create them anew each time as we do SyncFutures here. *

- * TODO: Add a FSWalEntry and SyncFuture as thread locals on handlers rather than have them get * them from this Map? */ - private final ConcurrentMap syncFuturesByHandler; + private final ThreadLocal syncFuturesByHandler; /** * The class name of the runtime implementation, used as prefix for logging/tracing. @@ -429,9 +425,8 @@ public abstract class AbstractFSWAL implements WAL { .toNanos(conf.getInt("hbase.regionserver.hlog.slowsync.ms", DEFAULT_SLOW_SYNC_TIME_MS)); this.walSyncTimeoutNs = TimeUnit.MILLISECONDS .toNanos(conf.getLong("hbase.regionserver.hlog.sync.timeout", DEFAULT_WAL_SYNC_TIMEOUT_MS)); - int maxHandlersCount = conf.getInt(HConstants.REGION_SERVER_HANDLER_COUNT, 200); // Presize our map of SyncFutures by handler objects. - this.syncFuturesByHandler = new ConcurrentHashMap<>(maxHandlersCount); + this.syncFuturesByHandler = new ThreadLocal<>(); this.implClassName = getClass().getSimpleName(); } @@ -723,7 +718,7 @@ public abstract class AbstractFSWAL implements WAL { // SyncFuture reuse by thread, if TimeoutIOException happens, ringbuffer // still refer to it, so if this thread use it next time may get a wrong // result. - this.syncFuturesByHandler.remove(Thread.currentThread()); + this.syncFuturesByHandler.remove(); throw tioe; } catch (InterruptedException ie) { LOG.warn("Interrupted", ie); @@ -873,9 +868,12 @@ public abstract class AbstractFSWAL implements WAL { } protected final SyncFuture getSyncFuture(long sequence) { - return CollectionUtils - .computeIfAbsent(syncFuturesByHandler, Thread.currentThread(), SyncFuture::new) - .reset(sequence); + SyncFuture syncFuture = syncFuturesByHandler.get(); + if (syncFuture == null) { + syncFuture = new SyncFuture(); + } + syncFuture.reset(sequence); + return syncFuture; } protected final void requestLogRoll(boolean tooFewReplicas) {