Skip to content

Commit

Permalink
Fix bug of negative JournalQueueSize (apache#4077)
Browse files Browse the repository at this point in the history
### Motivation

While shouldRolloverJournal is true,the QueueEntry qe is not added to the toFlush queue but we decrease the JournalQueueSize incorrectly.

### Changes

Decrease the JournalQueueSize after correct NonNull check of qe.

(cherry picked from commit 85d7bb3)
  • Loading branch information
XLzed authored and hangc0276 committed Jan 18, 2024
1 parent 636d8a3 commit d9a11ef
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1033,15 +1033,9 @@ journalFormatVersionToWrite, getBufferedChannelBuilder(),
if (localQueueEntriesLen > 0) {
qe = localQueueEntries[localQueueEntriesIdx];
localQueueEntries[localQueueEntriesIdx++] = null;
journalStats.getJournalQueueSize().dec();
journalStats.getJournalQueueStats()
.registerSuccessfulEvent(MathUtils.elapsedNanos(qe.enqueueTime), TimeUnit.NANOSECONDS);
}
} else {
journalStats.getJournalQueueSize().dec();
journalStats.getJournalQueueStats()
.registerSuccessfulEvent(MathUtils.elapsedNanos(qe.enqueueTime), TimeUnit.NANOSECONDS);
}

if (numEntriesToFlush > 0) {
boolean shouldFlush = false;
// We should issue a forceWrite if any of the three conditions below holds good
Expand Down Expand Up @@ -1161,6 +1155,11 @@ journalFormatVersionToWrite, getBufferedChannelBuilder(),
if (qe == null) { // no more queue entry
continue;
}

journalStats.getJournalQueueSize().dec();
journalStats.getJournalQueueStats()
.registerSuccessfulEvent(MathUtils.elapsedNanos(qe.enqueueTime), TimeUnit.NANOSECONDS);

if ((qe.entryId == BookieImpl.METAENTRY_ID_LEDGER_EXPLICITLAC)
&& (journalFormatVersionToWrite < JournalChannel.V6)) {
/*
Expand Down

0 comments on commit d9a11ef

Please sign in to comment.