fix(server): flush trailing duplicate batch when last mutation is ignored - #2408
Open
cauchy1988 wants to merge 1 commit into
Open
cauchy1988 wants to merge 1 commit into
cauchy1988 wants to merge 1 commit into
Conversation
…ored pegasus_mutation_duplicator::duplicate() iterates the mutation set (sorted by timestamp), accumulating entries into a batch and flushing it when the batch-byte threshold is reached or the last mutation is seen. Mutations whose rpc code is RPC_RRDB_RRDB_DUPLICATE or RPC_RRDB_RRDB_BULK_LOAD are intentionally not duplicated. The ignored-code path used `continue`, which skipped the batch-flush check too. So when the LAST mutation in the set was an ignored code, the in-progress batch of valid mutations was never moved to _inflights and was silently dropped. Because the caller has already advanced last_decree past the whole set, those mutations were never re-read and never duplicated — silent data loss (reported in apache#2284, with duplicate_log_batch_bytes > 0). Fix: - Replace `continue` with if/else so the flush check always runs. - Flush only when the batch is non-empty (an ignored mutation with an empty trailing batch is a no-op). - Compute the batch's routing hash from the last ENTRY in the batch (always a duplicatable code), not the current (possibly ignored) mutation: get_hash_from_request LOG_FATAL-aborts on DUPLICATE/BULK_LOAD. Added a regression test (duplicate_ignored_last_mutation) that fails before the fix (the trailing batch is dropped, nothing is shipped) and passes after. Closes apache#2284 Co-Authored-By: Claude <noreply@anthropic.com>
cauchy1988
force-pushed
the
fix/duplication-ignored-last-mutation
branch
from
June 14, 2026 06:54
fc68cb0 to
bc7e62d
Compare
This branch has not been deployed
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.
Problem
pegasus_mutation_duplicator::duplicate()iterates the mutation set (sorted by timestamp), accumulating entries into a batch and flushing it when the batch-byte threshold is reached or the last mutation is seen. Mutations whose rpc code isRPC_RRDB_RRDB_DUPLICATEorRPC_RRDB_RRDB_BULK_LOADare intentionally not duplicated.The ignored-code path used
continue, which also skipped the batch-flush check. So when the last mutation in the set was an ignored code, the in-progress batch of valid mutations was never moved to_inflightsand was silently dropped. Because the caller has already advancedlast_decreepast the whole set, those mutations were never re-read and never duplicated — silent data loss (reported in #2284, withduplicate_log_batch_bytes > 0).Fix
continuewithif/elseso the flush check always runs — the trailing batch is now flushed even when the last mutation is ignored.cb(0)path covered by the existingduplicate_duplicatetest).PUT/REMOVE/MULTI_*), not the current (possibly ignored) mutation —get_hash_from_requestwouldLOG_FATAL-abort onDUPLICATE/BULK_LOAD.Testing
Added regression test
duplicate_ignored_last_mutation: 3 validPUTs followed by an ignoredBULK_LOADwith the highest timestamp (iterated last). It fails before the fix (mail_boxempty — the trailing PUT batch is dropped) and passes after.Full duplicator suite passes (16/16):
Existing tests (
duplicate,duplicate_failed,duplicate_isolated_hashkeys,duplicate_duplicate,get_hash_from_request,read_after_get_hash_key,create_duplicator) all still pass — no regression.Closes #2284