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

shenwenbing 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 a99f2e1a43 [fix] Keep entryLogMeta when entryLogFile deletion fails 
(#3965)
a99f2e1a43 is described below

commit a99f2e1a43b5d03b8e3aecd0dade9db2cf894b9e
Author: wenbingshen <[email protected]>
AuthorDate: Wed Jul 5 10:49:20 2023 +0800

    [fix] Keep entryLogMeta when entryLogFile deletion fails (#3965)
    
    * Keep entryLogMeta when entryLogFile deletion fails
    
    * addressed reviewer's comments
---
 .../bookkeeper/bookie/BookKeeperServerStats.java      |  1 +
 .../apache/bookkeeper/bookie/DefaultEntryLogger.java  |  3 ++-
 .../bookkeeper/bookie/GarbageCollectorThread.java     | 19 ++++++++++++++-----
 .../bookie/stats/GarbageCollectorStats.java           |  7 +++++++
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java
index 23ebec3f2b..59ffd99e0d 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java
@@ -148,6 +148,7 @@ public interface BookKeeperServerStats {
     String ACTIVE_ENTRY_LOG_SPACE_BYTES = "ACTIVE_ENTRY_LOG_SPACE_BYTES";
     String RECLAIMED_COMPACTION_SPACE_BYTES = 
"RECLAIMED_COMPACTION_SPACE_BYTES";
     String RECLAIMED_DELETION_SPACE_BYTES = "RECLAIMED_DELETION_SPACE_BYTES";
+    String RECLAIM_FAILED_TO_DELETE = "RECLAIM_FAILED_TO_DELETE";
     String THREAD_RUNTIME = "THREAD_RUNTIME";
     String MAJOR_COMPACTION_COUNT = "MAJOR_COMPACTION_TOTAL";
     String MINOR_COMPACTION_COUNT = "MINOR_COMPACTION_TOTAL";
diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java
index b6321c6f38..64c6508d67 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java
@@ -524,10 +524,11 @@ public class DefaultEntryLogger implements EntryLogger {
         } catch (FileNotFoundException e) {
             LOG.error("Trying to delete an entryLog file that could not be 
found: "
                     + entryLogId + ".log");
-            return false;
+            return true;
         }
         if (!entryLogFile.delete()) {
             LOG.warn("Could not delete entry log file {}", entryLogFile);
+            return false;
         }
         return true;
     }
diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java
index 1dc7c4b5a5..b966281282 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java
@@ -496,8 +496,11 @@ public class GarbageCollectorThread implements Runnable {
                     // ledgers anymore.
                     // We can remove this entry log file now.
                     LOG.info("Deleting entryLogId {} as it has no active 
ledgers!", entryLogId);
-                    removeEntryLog(entryLogId);
-                    
gcStats.getReclaimedSpaceViaDeletes().addCount(meta.getTotalSize());
+                    if (removeEntryLog(entryLogId)) {
+                        
gcStats.getReclaimedSpaceViaDeletes().addCount(meta.getTotalSize());
+                    } else {
+                        gcStats.getReclaimFailedToDelete().inc();
+                    }
                 } else if (modified) {
                     // update entryLogMetaMap only when the meta modified.
                     entryLogMetaMap.put(meta.getEntryLogId(), meta);
@@ -688,12 +691,15 @@ public class GarbageCollectorThread implements Runnable {
      *          Entry Log File Id
      * @throws EntryLogMetadataMapException
      */
-    protected void removeEntryLog(long entryLogId) throws 
EntryLogMetadataMapException {
+    protected boolean removeEntryLog(long entryLogId) throws 
EntryLogMetadataMapException {
         // remove entry log file successfully
         if (entryLogger.removeEntryLog(entryLogId)) {
             LOG.info("Removing entry log metadata for {}", entryLogId);
             entryLogMetaMap.remove(entryLogId);
+            return true;
         }
+
+        return false;
     }
 
     /**
@@ -754,8 +760,11 @@ public class GarbageCollectorThread implements Runnable {
                     // ledgers anymore.
                     // We can remove this entry log file now.
                     LOG.info("Deleting entryLogId {} as it has no active 
ledgers!", entryLogId);
-                    removeEntryLog(entryLogId);
-                    
gcStats.getReclaimedSpaceViaDeletes().addCount(entryLogMeta.getTotalSize());
+                    if (removeEntryLog(entryLogId)) {
+                        
gcStats.getReclaimedSpaceViaDeletes().addCount(entryLogMeta.getTotalSize());
+                    } else {
+                        gcStats.getReclaimFailedToDelete().inc();
+                    }
                 } else {
                     entryLogMetaMap.put(entryLogId, entryLogMeta);
                 }
diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/stats/GarbageCollectorStats.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/stats/GarbageCollectorStats.java
index 1c9475608f..f9f1e31fee 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/stats/GarbageCollectorStats.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/stats/GarbageCollectorStats.java
@@ -29,6 +29,7 @@ import static 
org.apache.bookkeeper.bookie.BookKeeperServerStats.MAJOR_COMPACTIO
 import static 
org.apache.bookkeeper.bookie.BookKeeperServerStats.MINOR_COMPACTION_COUNT;
 import static 
org.apache.bookkeeper.bookie.BookKeeperServerStats.RECLAIMED_COMPACTION_SPACE_BYTES;
 import static 
org.apache.bookkeeper.bookie.BookKeeperServerStats.RECLAIMED_DELETION_SPACE_BYTES;
+import static 
org.apache.bookkeeper.bookie.BookKeeperServerStats.RECLAIM_FAILED_TO_DELETE;
 import static 
org.apache.bookkeeper.bookie.BookKeeperServerStats.THREAD_RUNTIME;
 
 import java.util.function.Supplier;
@@ -71,6 +72,11 @@ public class GarbageCollectorStats {
         help = "Number of disk space bytes reclaimed via compacting entry log 
files"
     )
     private final Counter reclaimedSpaceViaCompaction;
+    @StatsDoc(
+            name = RECLAIM_FAILED_TO_DELETE,
+            help = "Number of reclaim failed counts when deleting entry log 
files"
+    )
+    private final Counter reclaimFailedToDelete;
     @StatsDoc(
         name = DELETED_LEDGER_COUNT,
         help = "Number of ledgers deleted by garbage collection"
@@ -107,6 +113,7 @@ public class GarbageCollectorStats {
         this.majorCompactionCounter = 
statsLogger.getCounter(MAJOR_COMPACTION_COUNT);
         this.reclaimedSpaceViaCompaction = 
statsLogger.getCounter(RECLAIMED_COMPACTION_SPACE_BYTES);
         this.reclaimedSpaceViaDeletes = 
statsLogger.getCounter(RECLAIMED_DELETION_SPACE_BYTES);
+        this.reclaimFailedToDelete = 
statsLogger.getCounter(RECLAIM_FAILED_TO_DELETE);
         this.gcThreadRuntime = statsLogger.getOpStatsLogger(THREAD_RUNTIME);
         this.deletedLedgerCounter = 
statsLogger.getCounter(DELETED_LEDGER_COUNT);
 

Reply via email to