You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2018/09/28 01:31:19 UTC
[3/3] hbase git commit: HBASE-21228 Memory leak since AbstractFSWAL
caches Thread object and never clean later
HBASE-21228 Memory leak since AbstractFSWAL caches Thread object and never clean later
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/ff29edc8
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/ff29edc8
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/ff29edc8
Branch: refs/heads/branch-1.2
Commit: ff29edc856c29fb6691f9c1798c344733383c7ee
Parents: 8273dfa
Author: Allan Yang <al...@apache.org>
Authored: Thu Sep 27 16:44:46 2018 +0800
Committer: Andrew Purtell <ap...@apache.org>
Committed: Thu Sep 27 17:51:52 2018 -0700
----------------------------------------------------------------------
.../hadoop/hbase/regionserver/wal/FSHLog.java | 26 +++++++++-----------
1 file changed, 12 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/ff29edc8/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java
index 4b81dda..b4c8e5f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java
@@ -190,12 +190,11 @@ public class FSHLog implements WAL {
private final RingBufferEventHandler ringBufferEventHandler;
/**
- * Map of {@link SyncFuture}s keyed by Handler objects. Used so we reuse SyncFutures.
- * TODO: Reus 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?
+ * Map of {@link SyncFuture}s owned by Thread objects. Used so we reuse SyncFutures.
+ * Thread local is used so JVM can GC the terminated thread for us. See HBASE-21228
+ * <p>
*/
- private final Map<Thread, SyncFuture> syncFuturesByHandler;
+ private final ThreadLocal<SyncFuture> cachedSyncFutures;
/**
* The highest known outstanding unsync'd WALEdit sequence number where sequence number is the
@@ -569,8 +568,12 @@ public class FSHLog implements WAL {
maxHandlersCount);
this.disruptor.handleExceptionsWith(new RingBufferExceptionHandler());
this.disruptor.handleEventsWith(new RingBufferEventHandler [] {this.ringBufferEventHandler});
- // Presize our map of SyncFutures by handler objects.
- this.syncFuturesByHandler = new ConcurrentHashMap<Thread, SyncFuture>(maxHandlersCount);
+ this.cachedSyncFutures = new ThreadLocal<SyncFuture>() {
+ @Override
+ protected SyncFuture initialValue() {
+ return new SyncFuture();
+ }
+ };
// Starting up threads in constructor is a no no; Interface should have an init call.
this.disruptor.start();
}
@@ -1409,7 +1412,7 @@ public class FSHLog 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.cachedSyncFutures.remove();
throw tioe;
} catch (InterruptedException ie) {
LOG.warn("Interrupted", ie);
@@ -1427,12 +1430,7 @@ public class FSHLog implements WAL {
}
private SyncFuture getSyncFuture(final long sequence, Span span) {
- SyncFuture syncFuture = this.syncFuturesByHandler.get(Thread.currentThread());
- if (syncFuture == null) {
- syncFuture = new SyncFuture();
- this.syncFuturesByHandler.put(Thread.currentThread(), syncFuture);
- }
- return syncFuture.reset(sequence, span);
+ return cachedSyncFutures.get().reset(sequence);
}
private void postSync(final long timeInNanos, final int handlerSyncs) {