Skip to content

Commit

Permalink
Skip sync the RocksDB when no changes (apache#3904)
Browse files Browse the repository at this point in the history
Co-authored-by: Matteo Merli <mmerli@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 24464ba)
  • Loading branch information
hangc0276 committed Jan 18, 2024
1 parent 3c9f7b8 commit 0e375de
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,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 {
Expand All @@ -320,6 +324,10 @@ public void flush() throws IOException {
}

public void removeDeletedLedgers() throws IOException {
if (pendingDeletedLedgers.isEmpty()) {
return;
}

LongWrapper key = LongWrapper.get();

try {
Expand Down

0 comments on commit 0e375de

Please sign in to comment.