Repository navigation
fix(Spanner): Live: order SQL Server change events by LSN - #4654
Vaibhavch9876 wants to merge 3 commits into
Conversation
Datastream's SQL Server change-table events do not carry their own commit time as source_timestamp, so timestamp-first ordering could treat a newer UPDATE/DELETE as older than the row's INSERT and skip it, leaving deleted rows and stale values in Spanner. Compare LSNs when both events have one and keep timestamp-then-LSN only when an LSN is empty (backfill).
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue in SQL Server live migrations where events were being processed out of order, leading to stale data or skipped updates in Spanner. By shifting the primary ordering mechanism from timestamps to LSNs, the system now correctly sequences change events even when Datastream timestamps are inconsistent or misleading. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates the SqlServerChangeEventSequence class to prioritize LSN comparison over timestamp comparison when both events contain an LSN. This change ensures correct ordering of CDC events, preventing newer UPDATE or DELETE events from being incorrectly skipped due to Datastream's timestamp assignment behavior. A corresponding unit test, lsnWinsOverTimestampForCdcEvents, has been added to verify this logic. There are no review comments, and I have no additional feedback to provide.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4654 +/- ##
============================================
+ Coverage 59.69% 65.22% +5.53%
+ Complexity 8678 3969 -4709
============================================
Files 1122 569 -553
Lines 72738 34824 -37914
Branches 8854 4005 -4849
============================================
- Hits 43418 22714 -20704
+ Misses 26419 10974 -15445
+ Partials 2901 1136 -1765
🚀 New features to boost your workflow:
|
Only let the LSN decide when both events have different LSNs; equal or empty LSNs keep the existing timestamp-then-LSN order (fixes SqlServerChangeEventSequenceTest.canOrderBasedOnTimestamp).
Backfill events carry an LSN in a different format ("0000002E:00001890:0002")
that sorts after later CDC LSNs as a string, which made CDC UPDATE/DELETE after a
backfill look older (SQL Server live ITs). Order by LSN only when both events
have a CDC (plain hex) LSN; otherwise keep timestamp-then-LSN.
SQL Server live migration could skip UPDATE/DELETE events and leave deleted rows and stale values in Spanner. Datastream's SQL Server change-table events don't carry each event's own commit time as source_timestamp, so ordering by timestamp first could treat a newer UPDATE/DELETE as older than the row's INSERT.
SqlServerChangeEventSequence.compareTonow compares LSNs when both events have one, and keeps timestamp-then-LSN only when an LSN is empty (backfill events).Testing: added a unit test for an INSERT with a later timestamp but smaller LSN than its UPDATE/DELETE; in a 1K changes/s, 30-min load test the source and Spanner row counts now match exactly (405,131 = 405,131; previously 101,211 extra rows).
Fixes: b/591679245