ivankelly commented on a change in pull request #832: Issue 620: Close the 
fileChannels for read when they are idle
URL: https://github.com/apache/bookkeeper/pull/832#discussion_r171810861

 File path: 
 @@ -330,54 +350,47 @@ private int readFromLogChannel(long entryLogId, 
BufferedReadChannel channel, Byt
      * A thread-local variable that wraps a mapping of log ids to 
      * These channels should be used only for reading. logChannel is the one
      * that is used for writes.
+     * We use this Guava cache to store the BufferedReadChannel.
+     * When the BufferedReadChannel is removed, the underlying fileChannel's 
refCnt decrease 1,
+     * temporally use 1h to relax replace after reading.
-    private final ThreadLocal<Map<Long, BufferedReadChannel>> logid2Channel =
-            new ThreadLocal<Map<Long, BufferedReadChannel>>() {
+    private final ThreadLocal<Cache<Long, EntryLogBufferedReadChannel>> 
logid2ReadChannel =
+            new ThreadLocal<Cache<Long, EntryLogBufferedReadChannel>>() {
-        public Map<Long, BufferedReadChannel> initialValue() {
+        public Cache<Long, EntryLogBufferedReadChannel> initialValue() {
             // Since this is thread local there only one modifier
             // We dont really need the concurrency, but we need to use
             // the weak values. Therefore using the concurrency level of 1
-            return new MapMaker().concurrencyLevel(1)
-                .weakValues()
-                .makeMap();
+            return CacheBuilder.newBuilder().concurrencyLevel(1)
+                    .expireAfterAccess(readChannelCacheExpireTimeMs, 
+                    //decrease the refCnt
+                    .removalListener(removal -> ((EntryLogBufferedReadChannel) 
 Review comment:
   >  ```.removalListener((RemovalListener<String, 
EntryLogBufferedReadChannel>) notification -> notification.getValue.release)```
   Another option would be to define the parameter type in the lambda.
   .removalListener((RemovalNotification<String, EntryLogBufferedReadChannel> 
notification) -> notification.getValue().release())
   I'm fine with any of these, I only commented originally because I thought 
nothing was needed at all.
   > because it is not pure RemovalListener<K, V>.
   @sijie What is because it's not pure? I'm not sure of the context.

This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

Reply via email to