This is an automated email from the ASF dual-hosted git repository.
lushiji pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new c64dc8ab3a Using KeyValueStorage.Batch more rigorously (#4576)
c64dc8ab3a is described below
commit c64dc8ab3ae50216a284a6d1f95e417c1a68bc71
Author: StevenLuMT <[email protected]>
AuthorDate: Wed Apr 9 19:00:01 2025 +0800
Using KeyValueStorage.Batch more rigorously (#4576)
Every time use KeyValueStorage.Batch, close it in finally
---
.../bookie/storage/ldb/EntryLocationIndex.java | 27 +++++++++++-----------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
index 87f0af0771..a353b7cf7e 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
@@ -147,10 +147,10 @@ public class EntryLocationIndex implements Closeable {
}
public void addLocation(long ledgerId, long entryId, long location) throws
IOException {
- Batch batch = locationsDb.newBatch();
- addLocation(batch, ledgerId, entryId, location);
- batch.flush();
- batch.close();
+ try (Batch batch = locationsDb.newBatch()) {
+ addLocation(batch, ledgerId, entryId, location);
+ batch.flush();
+ }
}
public Batch newBatch() {
@@ -178,18 +178,17 @@ public class EntryLocationIndex implements Closeable {
log.debug("Update locations -- {}", Iterables.size(newLocations));
}
- Batch batch = newBatch();
- // Update all the ledger index pages with the new locations
- for (EntryLocation e : newLocations) {
- if (log.isDebugEnabled()) {
- log.debug("Update location - ledger: {} -- entry: {}",
e.ledger, e.entry);
- }
+ try (Batch batch = newBatch()) {
+ // Update all the ledger index pages with the new locations
+ for (EntryLocation e : newLocations) {
+ if (log.isDebugEnabled()) {
+ log.debug("Update location - ledger: {} -- entry: {}",
e.ledger, e.entry);
+ }
- addLocation(batch, e.ledger, e.entry, e.location);
+ addLocation(batch, e.ledger, e.entry, e.location);
+ }
+ batch.flush();
}
-
- batch.flush();
- batch.close();
}
public void delete(long ledgerId) throws IOException {