From 24464ba428d9c93a18c3edf74be5c32759bdce1e Mon Sep 17 00:00:00 2001 From: Hang Chen Date: Mon, 8 Jan 2024 11:43:07 +0800 Subject: [PATCH] Skip sync the RocksDB when no changes (#3904) Co-authored-by: Matteo Merli ### 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. --- .../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 0f615ab6752..b2fd42a6ba8 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 void setMasterKey(long ledgerId, byte[] masterKey) throws IOException { * Flushes all pending changes. */ public void flush() throws IOException { + if (pendingLedgersUpdates.isEmpty()) { + return; + } + LongWrapper key = LongWrapper.get(); try { @@ -323,6 +327,10 @@ public void flush() throws IOException { } public void removeDeletedLedgers() throws IOException { + if (pendingDeletedLedgers.isEmpty()) { + return; + } + LongWrapper key = LongWrapper.get(); try {