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

yong 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 098ceac  Skip update entryLogMetaMap if not modified (#2964)
098ceac is described below

commit 098ceaca63e934d4ef9b56e46af7f0c24b5d6a5b
Author: Hang Chen <[email protected]>
AuthorDate: Fri Feb 11 11:10:28 2022 +0800

    Skip update entryLogMetaMap if not modified (#2964)
    
    ### Motivation
    After we support RocksDB backend entryMetaMap, we should avoid updating the 
entryMetaMap if unnecessary.
    
    In `doGcEntryLogs` method, it iterate through the entryLogMetaMap and 
update the meta if ledgerNotExists. We should check whether the meta has been 
modified in `removeIfLedgerNotExists`. If not modified, we can avoid update the 
 entryLogMetaMap.
    
    ### Modification
     1. Add a flag to represent whether the meta has been modified in 
`removeIfLedgerNotExists` method. If not, skip update the entryLogMetaMap.
---
 .../bookkeeper/bookie/GarbageCollectorThread.java     | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

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 bf00566..8e46a63 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
@@ -45,6 +45,7 @@ import org.apache.bookkeeper.meta.LedgerManager;
 import org.apache.bookkeeper.stats.StatsLogger;
 import org.apache.bookkeeper.util.MathUtils;
 import org.apache.bookkeeper.util.SafeRunnable;
+import org.apache.commons.lang3.mutable.MutableBoolean;
 import org.apache.commons.lang3.mutable.MutableLong;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -438,9 +439,7 @@ public class GarbageCollectorThread extends SafeRunnable {
         // Loop through all of the entry logs and remove the non-active 
ledgers.
         entryLogMetaMap.forEach((entryLogId, meta) -> {
             try {
-                removeIfLedgerNotExists(meta);
-                // update entryMetadta to persistent-map
-                entryLogMetaMap.put(meta.getEntryLogId(), meta);
+                boolean modified = removeIfLedgerNotExists(meta);
                 if (meta.isEmpty()) {
                     // This means the entry log is not associated with any 
active
                     // ledgers anymore.
@@ -448,6 +447,9 @@ public class GarbageCollectorThread extends SafeRunnable {
                     LOG.info("Deleting entryLogId {} as it has no active 
ledgers!", entryLogId);
                     removeEntryLog(entryLogId);
                     
gcStats.getReclaimedSpaceViaDeletes().add(meta.getTotalSize());
+                } else if (modified) {
+                    // update entryLogMetaMap only when the meta modified.
+                    entryLogMetaMap.put(meta.getEntryLogId(), meta);
                 }
             } catch (EntryLogMetadataMapException e) {
                 // Ignore and continue because ledger will not be cleaned up
@@ -462,16 +464,23 @@ public class GarbageCollectorThread extends SafeRunnable {
         this.numActiveEntryLogs = entryLogMetaMap.size();
     }
 
-    private void removeIfLedgerNotExists(EntryLogMetadata meta) throws 
EntryLogMetadataMapException {
+    private boolean removeIfLedgerNotExists(EntryLogMetadata meta) throws 
EntryLogMetadataMapException {
+        MutableBoolean modified = new MutableBoolean(false);
         meta.removeLedgerIf((entryLogLedger) -> {
             // Remove the entry log ledger from the set if it isn't active.
             try {
-                return !ledgerStorage.ledgerExists(entryLogLedger);
+                boolean exist = ledgerStorage.ledgerExists(entryLogLedger);
+                if (!exist) {
+                    modified.setTrue();
+                }
+                return !exist;
             } catch (IOException e) {
                 LOG.error("Error reading from ledger storage", e);
                 return false;
             }
         });
+
+        return modified.getValue();
     }
 
     /**

Reply via email to