Write journal entry length prefix and payload in a single BufferedChannel write#4833
Open
merlimat wants to merge 1 commit into
Open
Write journal entry length prefix and payload in a single BufferedChannel write#4833merlimat wants to merge 1 commit into
merlimat wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
On the journal append path, each entry is written to the
BufferedChannelas two separate calls — the 4-byte length prefix and then the payload:Each
write()acquires the channel monitor, so every journal entry pays two lock acquisitions on a monitor that is also contended by the force-write thread (forceWrite()takes the same lock to resetunpersistedBytes), plus two rounds of position/unpersisted-bytes accounting.Changes
BufferedChannel.write(ByteBuf src1, ByteBuf src2)overload that copies both buffers into the write buffer under a single lock acquisition, with a single position/unpersisted-bytes update. The two source buffers are passed as separate arguments — deliberately avoiding aCompositeByteBuf, which would add a per-entry allocation and component bookkeeping.write()is refactored onto the same internal helpers, with identical behavior.Journalnow writes the length prefix and entry payload with one call.SlowBufferedChannel(test injection hook) overrides the new method so the configured add-delay still applies.testWriteTwoBufferscovers boundary crossings: payloads that fit, exactly fill, straddle the write-buffer capacity, and exceed it (multiple internal flushes in one call), verifyingposition()and the resulting file contents.Verified:
BufferedChannelTest(9/9, including the new test),BookieJournalTest,BookieWriteToJournalTest,BookieJournalForceTest,BookieJournalPageCacheFlushTest,BookieJournalNoSyncTest,BookieJournalMaxMemoryTest(30/30), and module checkstyle.