Repository navigation
fix(offset): key batch tracking maps by identity, not timestamp range - #1464
Merged
Merged
Conversation
…stamp range DebeziumOffsetManagement keyed inFlightBatches and completedBatches by the batch (minTs,maxTs) timestamp range. Two DISTINCT batches routinely share a range - a single multi-row statement split across batches, or two batches whose rows all fall in the same millisecond. Keying by the range collided them: put overwrote the earlier batch entry, remove deleted the wrong one, and the overlap check "skip the same batch" step (also range-based) treated a distinct sibling as itself. An unwritten older batch therefore stopped blocking the offset commit, so the committed binlog position could advance past rows not yet in ClickHouse and lose them on a crash. Fix: introduce BatchKey, an identity wrapper over the batch List (equals/hashCode by System.identityHashCode), and key both maps by it. The overlap check now skips the current batch by identity (==) and compares timestamp ranges only to decide overlap. addToBatchTimestamps/checkIfBatchCanBeCommitted/acknowledgeRecords and the unused accessors are retyped accordingly; timestamp ranges are still derived for the overlap comparison, never used as a key. Tests (OffsetBatchIdentityTest): two same-range batches are tracked as two entries; a distinct same-range sibling still blocks the commit; a batch does not block itself; identity removal leaves the sibling. Mutation-checked: making BatchKey compare by range reproduces the collision and fails 3 of the 4 tests. HandedOffBatchVisibilityTest still passes. Spec 09.01 updated to the identity-key design and its corrected source path.
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
DebeziumOffsetManagement keyed inFlightBatches and completedBatches by the batch (minTs,maxTs) timestamp range (ConcurrentHashMap<Pair<Long,Long>, ...>). Two DISTINCT batches routinely share a range - a single multi-row statement split across batches, or two batches whose rows all fall in the same millisecond. Keying by the range collided them:
The net effect: an unwritten older batch stopped blocking the offset commit, so the committed binlog position could advance past rows not yet in ClickHouse and lose them on a crash.
Fix
Introduce BatchKey, an identity wrapper over the batch List (equals/hashCode by System.identityHashCode), and key both maps by it. The overlap check now skips the current batch by identity (==) and compares timestamp ranges only to decide overlap. Timestamp ranges are still derived for the overlap comparison - never used as a map key.
Tests
OffsetBatchIdentityTest:
Mutation-checked: making BatchKey compare by range reproduces the collision and fails 3 of the 4 tests. HandedOffBatchVisibilityTest still passes. Spec 09.01 updated to the identity-key design and its corrected source path. Built/tested on JDK 17.