Skip to content

Commit

Permalink
Skip sync the RocksDB when no changes (#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.
  • Loading branch information
hangc0276 committed Jan 8, 2024
1 parent 787d9b2 commit 24464ba
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -323,6 +327,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 24464ba

Please sign in to comment.