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

chenhang 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 24464ba428 Skip sync the RocksDB when no changes (#3904)
24464ba428 is described below

commit 24464ba428d9c93a18c3edf74be5c32759bdce1e
Author: Hang Chen <[email protected]>
AuthorDate: Mon Jan 8 11:43:07 2024 +0800

    Skip sync the RocksDB when no changes (#3904)
    
    Co-authored-by: Matteo Merli <[email protected]>
    ### Motivation
    For the `LedgerMetadataIndex#removeDeletedLedgers` and 
`LedgerMetadataIndex#flush`, it will call ledgersDB sync whether the ledgersDB 
has changed or not. We can skip the sync call when nothing changed in the 
ledgersDB.
    
    ### Changes
    - Check whether pendingLedgersUpdates is empty in `flush()` and 
`pendingDeletedLedgers` is empty in removeDeletedLedgers
    - Move the `key.recycle()` in finally to cover keys leak when the ledgersDB 
operations throw an exception.
---
 .../apache/bookkeeper/bookie/storage/ldb/LedgerMetadataIndex.java | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/LedgerMetadataIndex.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/LedgerMetadataIndex.java
index 0f615ab675..b2fd42a6ba 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/LedgerMetadataIndex.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/LedgerMetadataIndex.java
@@ -300,6 +300,10 @@ public class LedgerMetadataIndex implements Closeable {
      * Flushes all pending changes.
      */
     public void flush() throws IOException {
+        if (pendingLedgersUpdates.isEmpty()) {
+            return;
+        }
+
         LongWrapper key = LongWrapper.get();
 
         try {
@@ -323,6 +327,10 @@ public class LedgerMetadataIndex implements Closeable {
     }
 
     public void removeDeletedLedgers() throws IOException {
+        if (pendingDeletedLedgers.isEmpty()) {
+            return;
+        }
+
         LongWrapper key = LongWrapper.get();
 
         try {

Reply via email to