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

chenhang pushed a commit to branch branch-4.14
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git

commit 48d3f139fd860f897eec5a77e4f14579a17b46c2
Author: Zhangao <[email protected]>
AuthorDate: Fri Apr 7 15:08:42 2023 +0800

    Execute clean indexes in finally (#3772)
    
    Execute clean indexes in finally (#3772)
    
    (cherry picked from commit 04e572b9bccd1502c0f2c4a87f23d760d4d0d9b5)
---
 .../ldb/SingleDirectoryDbLedgerStorage.java        | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
index ba8d949a83..8e970cae73 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
@@ -646,21 +646,6 @@ public class SingleDirectoryDbLedgerStorage implements 
CompactableLedgerStorage
 
             ledgerIndex.flush();
 
-            cleanupExecutor.execute(() -> {
-                // There can only be one single cleanup task running because 
the cleanupExecutor
-                // is single-threaded
-                try {
-                    if (log.isDebugEnabled()) {
-                        log.debug("Removing deleted ledgers from db indexes");
-                    }
-
-                    entryLocationIndex.removeOffsetFromDeletedLedgers();
-                    ledgerIndex.removeDeletedLedgers();
-                } catch (Throwable t) {
-                    log.warn("Failed to cleanup db indexes", t);
-                }
-            });
-
             lastCheckpoint = thisCheckpoint;
 
             // Discard all the entry from the write cache, since they're now 
persisted
@@ -682,6 +667,20 @@ public class SingleDirectoryDbLedgerStorage implements 
CompactableLedgerStorage
             // Wrap unchecked exceptions
             throw new IOException(e);
         } finally {
+            cleanupExecutor.execute(() -> {
+                // There can only be one single cleanup task running because 
the cleanupExecutor
+                // is single-threaded
+                try {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Removing deleted ledgers from db indexes");
+                    }
+
+                    entryLocationIndex.removeOffsetFromDeletedLedgers();
+                    ledgerIndex.removeDeletedLedgers();
+                } catch (Throwable t) {
+                    log.warn("Failed to cleanup db indexes", t);
+                }
+            });
             try {
                 isFlushOngoing.set(false);
             } finally {

Reply via email to