8000 fix(offset): key batch tracking maps by identity, not timestamp range by minguyen9988 · Pull Request #1464 · Altinity/clickhouse-sink-connector · GitHub
[go: up one dir, main page]

Skip to content

fix(offset): key batch tracking maps by identity, not timestamp range - #1464

Merged
minguyen9988 merged 1 commit into
2.11.0from
fix-offset-batch-collision
Sep 19, 2026
Merged

minguyen9988 merged 1 commit into
2.11.0from
fix-offset-batch-collision

Conversation

@minguyen9988
@minguyen9988 minguyen9988 commented Sep 19, 2026 •
Copy link
Copy Markdown
Collaborator

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:

  • put overwrote the earlier batch entry (so it was silently untracked),
  • remove deleted the wrong entry,
  • the overlap check "skip the same batch" step (also range-based) treated a distinct sibling as itself.

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:

  • equalTimestampBatchesDoNotCollide - two same-range batches are two entries, not one.
  • siblingWithSameRangeStillBlocks - a distinct same-range sibling still blocks the commit.
  • aBatchDoesNotBlockItself / identityRemovalLeavesSibling.

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.

…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.
@minguyen9988 minguyen9988 changed the title WIP: DO NOT MERGE - fix(offset): key batch tracking maps by identity, not timestamp range fix(offset): key batch tracking maps by identity, not timestamp range Sep 19, 2026
@minguyen9988
minguyen9988 merged commit b5d1057 into 2.11.0 Sep 19, 2026
9 of 10 checks passed
@minguyen9988
minguyen9988 deleted the fix-offset-batch-collision branch September 19, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0