Skip to content

Use BlockingQueue.drainTo() in Journal thread - #3544

Merged
eolivelli merged 3 commits into
apache:masterfrom
merlimat:journal-queue-drain
Oct 20, 2022
Merged

eolivelli merged 3 commits into
apache:masterfrom
merlimat:journal-queue-drain

Conversation

@merlimat

Copy link
Copy Markdown
Contributor

Motivation

Use BlockingQueue.drainTo() in the Journal thread to minimize the contention between this thread and the threads passing entries to the journal.

The drain method in the ArrayBlockingQueue method will use the mutex only once and take out all the items in one shot.

The logic in the journal dequeuing is already quite complicated. This change aims at not changing the whole logic, rather doing the minimal intervention.

@zymap

zymap commented Oct 18, 2022

Copy link
Copy Markdown
Member

rerun the failure tests

Error:  Failures: 
Error:  org.apache.bookkeeper.bookie.BookieJournalForceTest.testAckBeforeSyncWithJournalBufferedEntriesThreshold
Error:    Run 1: BookieJournalForceTest.testAckBeforeSyncWithJournalBufferedEntriesThreshold:251
Error:    Run 2: BookieJournalForceTest.testAckBeforeSyncWithJournalBufferedEntriesThreshold:251
Error:    Run 3: BookieJournalForceTest.testAckBeforeSyncWithJournalBufferedEntriesThreshold:251
[INFO] 
Warning:  Flakes: 
Warning:  org.apache.bookkeeper.bookie.StateManagerTest.testReadOnlyBookieTransitions
Error:    Run 1: StateManagerTest.testReadOnlyBookieTransitions:173->Object.wait:-2 » TestTimedOut
[INFO]   Run 2: PASS
[INFO] 
Warning:  org.apache.bookkeeper.bookie.UpgradeTest.testUpgradeCurrent
Error:    Run 1: UpgradeTest.testUpgradeCurrent:228->testUpgradeProceedure:179->Object.wait:-2 » TestTimedOut
[INFO]   Run 2: PASS

queue.drainTo(localQueueEntries);
}

if (!localQueueEntries.isEmpty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If new entries keep put into the queue, the localQueueEntries won't be empty, it won't go into line#1107 branch, and the flush won't be triggered.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I got the scenario here. I think every time the loop goes back to the top on the while (true) and we should always check first the localQueueEntries before attempting the poll()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We should check it before poll. But we shouldn't connect other logic with else if.
When there is no entry put in, the localQueueEntries will be empty. But if there have entries that continue to push, we will never go to other branches.
So the main problem is we never have a chance to go here

I have another question. I think this is only to replace the queue.take(); operation, so why not put them to the line 1100?
@merlimat

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good points. I actually think we should do it both before the poll() and the take().

@zymap @hangc0276 PTAL again

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eolivelli
eolivelli merged commit 16a4365 into apache:master Oct 20, 2022
@merlimat
merlimat deleted the journal-queue-drain branch October 20, 2022 15:21

@hangc0276 hangc0276 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants