Fix doubly-wrapped log entries after sparse write and recovery#601
Merged
michaelklishin merged 1 commit intomainfrom Mar 26, 2026
Merged
Fix doubly-wrapped log entries after sparse write and recovery#601michaelklishin merged 1 commit intomainfrom
michaelklishin merged 1 commit intomainfrom
Conversation
When a follower receives a pre-snapshot chunk, it uses `ra_log:write_sparse/3`
to write the entries to the WAL. However, `write_sparse/3` was passing the
entire `log_entry()` tuple `{Idx, Term, Cmd}` as the payload to the WAL,
instead of just the `Cmd`.
When the node is restarted, the WAL recovery process reads the payload and
wraps it in a new `{Idx, Term, Payload}` tuple. Because the payload was
already a full `log_entry()` tuple, the recovered entry became doubly-wrapped:
`{Idx, Term, {Idx, Term, Cmd}}`.
This caused a `badmatch` error in `rabbit_jms_machine:exec_read/3` when
`rabbit_jms_queue_client` attempted to read messages for delivery. The
`ra_server:transform_for_partial_read/3` function failed to strip the Raft
metadata because the doubly-wrapped entry did not match the expected
`{'$usr', ...}` pattern, causing raw Raft metadata to be returned instead
of the expected JMS message.
This commit fixes the issue by passing only the `Cmd` to the WAL in
`write_sparse/3`, matching the behavior of normal appends. A test case
has been added to verify that sparse writes survive recovery without
being doubly-wrapped.
michaelklishin
approved these changes
Mar 26, 2026
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.
When a follower receives a pre-snapshot chunk, it uses
ra_log:write_sparse/3to write the entries to the WAL. However,write_sparse/3was passing the entirelog_entry()tuple{Idx, Term, Cmd}as the payload to the WAL, instead of just theCmd.When the node is restarted, the WAL recovery process reads the payload and wraps it in a new
{Idx, Term, Payload}tuple. Because the payload was already a fulllog_entry()tuple, the recovered entry became doubly-wrapped:{Idx, Term, {Idx, Term, Cmd}}.This caused a
badmatcherror inrabbit_jms_machine:exec_read/3whenrabbit_jms_queue_clientattempted to read messages for delivery. Thera_server:transform_for_partial_read/3function failed to strip the Raft metadata because the doubly-wrapped entry did not match the expected{'$usr', ...}pattern, causing raw Raft metadata to be returned instead of the expected JMS message.This commit fixes the issue by passing only the
Cmdto the WAL inwrite_sparse/3, matching the behavior of normal appends. A test case has been added to verify that sparse writes survive recovery without being doubly-wrapped.