adapters: pg-cdc: add snapshot transaction support#6670
Open
abhizer wants to merge 2 commits into
Open
Conversation
Group the initial COPY and WAL catchup into separate transactions during the snapshot phase. Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
Signed-off-by: feldera-bot <feldera-bot@feldera.com>
mythical-fred
approved these changes
Jul 17, 2026
mythical-fred
left a comment
There was a problem hiding this comment.
APPROVE. Nice piece of work: the initial-sync transaction split cleanly matches etl's copy/catchup lifecycle, and SnapshotPhase keeps the state machine small and testable.
What I checked:
- State machine (
SnapshotPhase). Copy → Catchup → Inactive, all guarded by a singleMutex<SnapshotPhase>; the four public transitions (start_copy,finish_copy,start_catchup,finish_catchup) each hold the lock only across trivial checks, so blocking a Tokio worker on thestd::sync::Mutexis not a concern.finish_catchup_after_etl_completionholds the guard while it also callsphase.finish_catchup()— that's a method on the innerSnapshotPhase(not a re-lock), so no double-lock. Good. - Startup path.
SnapshotTransactions::initialize()takes the store out ofstartup_storeonce and derives the initial phase from etl's persistedTableState. Thelock_phase()assert!(not Uninitialized)documents the invariant "etl callsstartup()before any write", which matches the destination trait contract. TheErroredbranch mapping toInactiveis the right call — restart-then-recover is thediscard_*_errorspath's job, not this state machine's. - Copy/catchup commit atomicity.
test_cdc_snapshot_transactions_cover_copy_and_catchupis the important test. It asserts (a) COPY rows are not visible until commit, (b) catchup rows are not visible until its commit, (c) steady-state CDC stays outside a connector transaction. The catchup row-count assertion allowsSNAPSHOT + CATCHUPorSNAPSHOT + CATCHUP + 1— mildly loose since etl may or may not have folded the anchor row into the same commit, but that's fine because the atomicity property is what's being checked. - Refactor of
discard_matching_table_errors. Went from "iterate every errored table id" to "look up the one target table". Correct simplification since this connector replicates exactly one table; any other errored table in the publication was irrelevant to us. Rollback loop unchanged in shape. TableStateMonitorrename + expanded duty. Now polls once per second for both (a) fatal errors and (b) idle catchup completion. Both branches are cheap and read-only against the store on the happy path. Reasonable.- Commit hygiene. Two commits, both signed off, no AI trailers.
- CI. Pending at post time; nothing to block on yet.
Two tiny nits, none blocking:
docs.feldera.com/docs/connectors/sources/postgresql-cdc.md— the new Transactions section calls the toolETL(uppercase), but the code, module docs, and connector logs consistently useetl(lowercase, matching the crate name). Worth aligning for docs consistency.SnapshotPhase::start_catchup(None, true)correctly returnsfalse(target table id unknown), but the reason is subtle enough that a one-line doc comment onstart_catchup(or adebug_assert!explaining whyNonecannot legitimately reach here after catchup has begun) would help the next reader.
Otherwise this is good to land once the CI you're waiting on clears.
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.
Add support for transactions during snapshot phase.