Skip to content

Commit

Permalink
Recycle LongWrapper finally (#4007)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonHxy authored Jul 10, 2023
1 parent fb0d3d6 commit 528f373
Showing 1 changed file with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,38 +299,44 @@ public void setMasterKey(long ledgerId, byte[] masterKey) throws IOException {
public void flush() throws IOException {
LongWrapper key = LongWrapper.get();

int updatedLedgers = 0;
Entry<Long, LedgerData> entry;
while ((entry = pendingLedgersUpdates.poll()) != null) {
key.set(entry.getKey());
byte[] value = entry.getValue().toByteArray();
ledgersDb.put(key.array, value);
++updatedLedgers;
}
try {
int updatedLedgers = 0;
Entry<Long, LedgerData> entry;
while ((entry = pendingLedgersUpdates.poll()) != null) {
key.set(entry.getKey());
byte[] value = entry.getValue().toByteArray();
ledgersDb.put(key.array, value);
++updatedLedgers;
}

if (log.isDebugEnabled()) {
log.debug("Persisting updates to {} ledgers", updatedLedgers);
}
if (log.isDebugEnabled()) {
log.debug("Persisting updates to {} ledgers", updatedLedgers);
}

ledgersDb.sync();
key.recycle();
ledgersDb.sync();
} finally {
key.recycle();
}
}

public void removeDeletedLedgers() throws IOException {
LongWrapper key = LongWrapper.get();

int deletedLedgers = 0;
for (Long ledgerId : pendingDeletedLedgers) {
key.set(ledgerId);
ledgersDb.delete(key.array);
}
try {
int deletedLedgers = 0;
for (Long ledgerId : pendingDeletedLedgers) {
key.set(ledgerId);
ledgersDb.delete(key.array);
}

if (log.isDebugEnabled()) {
log.debug("Persisting deletes of ledgers {}", deletedLedgers);
}
if (log.isDebugEnabled()) {
log.debug("Persisting deletes of ledgers {}", deletedLedgers);
}

ledgersDb.sync();
key.recycle();
ledgersDb.sync();
} finally {
key.recycle();
}
}

private ReentrantLock lockForLedger(long ledgerId) {
Expand Down

0 comments on commit 528f373

Please sign in to comment.