This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new e10f3fe  Forget to close preAllocator log on shutdown (#2819)
e10f3fe is described below

commit e10f3fe6f8c0f044052519586137d32e5bb7ea56
Author: ZhangJian He <[email protected]>
AuthorDate: Sat Oct 23 01:18:58 2021 +0800

    Forget to close preAllocator log on shutdown (#2819)
    
    * Forget to close preAllocator log on shutdown
    
    * Fix synchronize problem
    
    * handle InterruptedException
---
 .../bookkeeper/bookie/EntryLoggerAllocator.java     | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLoggerAllocator.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLoggerAllocator.java
index 1874dfa..5b05e64 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLoggerAllocator.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLoggerAllocator.java
@@ -42,6 +42,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 import lombok.extern.slf4j.Slf4j;
 import org.apache.bookkeeper.bookie.EntryLogger.BufferedLogChannel;
@@ -182,6 +183,24 @@ class EntryLoggerAllocator {
         return logChannel;
     }
 
+
+    private synchronized void closePreAllocateLog() {
+        if (preallocatedLogId != -1) {
+            // if preallocate new log success, release the file channel
+            try {
+                BufferedLogChannel bufferedLogChannel = 
getPreallocationFuture().get(3, TimeUnit.SECONDS);
+                if (bufferedLogChannel != null) {
+                    bufferedLogChannel.close();
+                }
+            } catch (InterruptedException e) {
+                log.warn("interrupted while release preAllocate log");
+                Thread.currentThread().interrupt();
+            } catch (IOException | ExecutionException | TimeoutException e) {
+                log.warn("release preAllocate log failed, ignore error");
+            }
+        }
+    }
+
     /**
      * writes the given id to the "lastId" file in the given directory.
      */
@@ -208,6 +227,7 @@ class EntryLoggerAllocator {
      */
     void stop() {
         // wait until the preallocation finished.
+        allocatorExecutor.execute(this::closePreAllocateLog);
         allocatorExecutor.shutdown();
         try {
             if (!allocatorExecutor.awaitTermination(5, TimeUnit.SECONDS)) {
@@ -218,7 +238,6 @@ class EntryLoggerAllocator {
             Thread.currentThread().interrupt();
         }
         allocatorExecutor.shutdownNow();
-
         log.info("Stopped entry logger preallocator.");
     }
 

Reply via email to