sijie 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_r156465690
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java
 ##########
 @@ -1079,24 +1109,26 @@ private Header getHeaderForLogId(long entryLogId) 
throws IOException {
     }
 
     private BufferedReadChannel getChannelForLogId(long entryLogId) throws 
IOException {
-        BufferedReadChannel fc = getFromChannels(entryLogId);
-        if (fc != null) {
-            return fc;
-        }
-        File file = findFile(entryLogId);
-        // get channel is used to open an existing entry log file
-        // it would be better to open using read mode
-        FileChannel newFc = new RandomAccessFile(file, "r").getChannel();
-        FileChannel oldFc = logid2FileChannel.putIfAbsent(entryLogId, newFc);
-        if (null != oldFc) {
-            newFc.close();
-            newFc = oldFc;
+        BufferedReadChannel brc = getFromChannels(entryLogId);
+        if (brc != null) {
+            return brc;
         }
+
+        // logid2FileChannel cache will load fileChannel automatically
+        FileChannel fc = null;
+        try {
+            fc = logid2FileChannel.get(entryLogId);
+        } catch (ExecutionException e){
+            LOG.error("ExecutionException found in get fileChannel for log {} 
in logid2FileChannel cache", entryLogId);
+            // throw exception to avoid pass null to BufferedReadChannel
+            throw new IOException(e);
 
 Review comment:
   ExecutionException wrap the actual cause on loading the file channel. so you 
need to unwrap this.
   ```
   if (e.getCause() instanceof IOException) {
       throw (IOException) e.getCause();
   } else {
       throw new IOException("Encountered unknown exception on opening read 
channel for entry log " + entryLogId, e.getCause());
   }
   ```

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to