You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by ch...@apache.org on 2024/01/18 13:21:33 UTC

(bookkeeper) 19/23: Skip sync the RocksDB when no changes (#3904)

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

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

commit 0e375de9e44ed18a5de5367afec11d6138884259
Author: Hang Chen <ch...@apache.org>
AuthorDate: Mon Jan 8 11:43:07 2024 +0800

    Skip sync the RocksDB when no changes (#3904)
    
    Co-authored-by: Matteo Merli <mm...@apache.org>
    ### 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 bf3c01e662..9b50479b7d 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
@@ -297,6 +297,10 @@ public class LedgerMetadataIndex implements Closeable {
      * Flushes all pending changes.
      */
     public void flush() throws IOException {
+        if (pendingLedgersUpdates.isEmpty()) {
+            return;
+        }
+
         LongWrapper key = LongWrapper.get();
 
         try {
@@ -320,6 +324,10 @@ public class LedgerMetadataIndex implements Closeable {
     }
 
     public void removeDeletedLedgers() throws IOException {
+        if (pendingDeletedLedgers.isEmpty()) {
+            return;
+        }
+
         LongWrapper key = LongWrapper.get();
 
         try {