Skip to content

[MSSQL] Ensure consistent ordering of CDC operations - #742

Open
Rentacookie wants to merge 8 commits into
mainfrom
fix/mssql-operation-sequence-order
Open

[MSSQL] Ensure consistent ordering of CDC operations#742
Rentacookie wants to merge 8 commits into
mainfrom
fix/mssql-operation-sequence-order

Conversation

@Rentacookie

@Rentacookie Rentacookie commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes an issue that was discovered where deferred updates could result in missing row updates.
Deferred updates are recorded in the CDC tables as a paired DELETE and INSERT operation, with the 2 operations having the same sequence number in the same transaction. This caused problems with the ordering of operations in the same transaction and the INSERT could be processed before the DELETE causing the replicated row to disappear.

Changes

  • Use operation as a tie breaker when ordering CDC results within a transaction.
  • Identify deferred updates and process them as normal updates, which reduces bucket operation.
  • Replaced previous optimistic transaction count estimate with an accurate count. The transactions replicated metric should now be more accurate.
  • Switched to streaming for the CDC Polling query

Testing

Added new CDCPoller.test.ts unit tests which helped diagnose the main issue and confirms the fixes.

AI Disclosure

Used Clause Opus 5 to replicate the issue with tests and implement then implement the fix. Also reviewed and verified changeds with GPT 5.6.

- Ensure correct ordering of CDC results
- Handle deferred updates
- Correctly count processed transactions in each polling cycle
- Improved logging
- Added tests
@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d34145f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@powersync/service-module-mssql Minor
@powersync/service-schema Patch
@powersync/service-image Patch
@powersync/service-core Patch
@powersync/service-module-convex Patch
@powersync/service-module-core Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
test-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread modules/module-mssql/src/replication/CDCPoller.ts
Comment thread modules/module-mssql/src/replication/CDCPoller.ts Outdated
Comment thread modules/module-mssql/src/replication/CDCPoller.ts Outdated
Comment thread modules/module-mssql/src/replication/CDCPoller.ts Outdated
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.

2 participants