Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use BlockingQueue.drainTo() in Journal thread #3544

Merged
merged 3 commits into from
Oct 20, 2022

Conversation

merlimat
Copy link
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
Copy link
Member

zymap commented Oct 18, 2022

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
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
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
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
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

Copy link
Contributor

@eolivelli eolivelli left a comment

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
Copy link
Contributor

@hangc0276 hangc0276 left a comment

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