Repository navigation
Keep _version monotonic in binlog order so a late DELETE/UPDATE is not lost (#1552) - #1553
Open
koenverwimp wants to merge 2 commits into
Open
koenverwimp wants to merge 2 commits into
koenverwimp wants to merge 2 commits into
Conversation
… and snapshot-window changes were lost)
…ource has GTIDs With gtid_mode=ON the snowflake id (timestamp << 22 | gtid) replaced the ts*1e6+counter version: another numeric domain, not comparable with the rows written before, and not monotonic when the source timestamp steps back.
Collaborator
|
please test with the latest 2.11.0, this has been solved |
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.
Fixes #1552 (related: #800, #1346).
Problem
Since 2.10.x the lightweight connector versions a row as
source ts_ms * 1e6 + intra-second counter. The MySQL source timestamp is the binlog event header time: the second in which the statement started, not the commit order. A transaction started in second S can commit after one started in S+1; the S+1 event resets the counter, so the late event of second S getsS + small counter, lower than everything already written for S. When that late event is the DELETE (or UPDATE) of a row inserted earlier in S, ReplacingMergeTree keeps the INSERT and the row stays in ClickHouse forever. We found 633 such ghost rows in 23 tables on a production replica (queue-like tables where a row lives milliseconds). The initial snapshot has the same problem (#800): rows are stamped with the processing time at which their table was read, so every change made between snapshot start and that moment ranks below the snapshot row.With
gtid_mode=ONthe problem comes back in another form:ClickHouseStruct.calculateVersionswitches toSnowFlakeId(ts_ms, gtid), a different numeric domain than the rows written before, and again not monotonic when the source timestamp steps back (the GTID only occupies the low 22 bits).Fix
DebeziumChangeEventCapture.monotonicVersionTs: within a forward binlog stream (file index + position increasing) the version timestamp never goes below the one used for the previous record. Records without binlog coordinates, and re-deliveries whose coordinates are before the highest ones seen (in-process rewind), keep the current behaviour, so Delete re-insert version mismatch #1346 stays fixed. Unit testMonotonicVersionTsTest(6 cases; 3 fail without the clamp).ClickHouseStruct.calculateVersion: the lightweight sequence number wins over the GTID-based version, so switching the source togtid_mode=ONkeeps the same formula and domain. Unit testSequenceNumberBeatsGtidVersionTest. The Kafka Connect path (no sequence number) is unchanged.The emitted formula stays
ts_ms * 1e6 + counter, so existing data keeps comparing correctly and upgrades/downgrades remain safe. Running in production since 2026-10-02 on two connectors (MySQL 8.0 / Aurora, with GTIDs on): a full MySQL-vs-ClickHouse comparison of 2,731 tables afterwards showed no differences.A more robust long-term option would be to derive the version from the binlog position itself, or from the commit timestamp in the GTID event (
immediate_commit_timestamp, which the binlog library already parses but Debezium does not expose), instead of the event header time.