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

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

commit 7dd740c241baa07693174cb2979a5d3162d88155
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.
    
    (cherry picked from commit 24464ba428d9c93a18c3edf74be5c32759bdce1e)
---
 .../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 95ba7e7dae..293ada23ac 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
@@ -305,6 +305,10 @@ public class LedgerMetadataIndex implements Closeable {
      * Flushes all pending changes.
      */
     public void flush() throws IOException {
+        if (pendingLedgersUpdates.isEmpty()) {
+            return;
+        }
+
         LongWrapper key = LongWrapper.get();
 
         try {
@@ -328,6 +332,10 @@ public class LedgerMetadataIndex implements Closeable {
     }
 
     public void removeDeletedLedgers() throws IOException {
+        if (pendingDeletedLedgers.isEmpty()) {
+            return;
+        }
+
         LongWrapper key = LongWrapper.get();
 
         try {

Reply via email to