-
Notifications
You must be signed in to change notification settings - Fork 957
mongodb_cdc, postgres_cdc: respect nacks and marshal failures in ack paths (CON-504) #4676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
squiidz
wants to merge
7
commits into
main
Choose a base branch
from
con-504-mongodb-postgres-ack-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−21
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d01137a
mongodb_cdc: don't resolve snapshot checkpoints on nack
squiidz 7ed6bc5
postgres_cdc: restart the stream on marshal failure instead of skippi…
squiidz b6fed39
postgres_cdc: integration test that marshal failures stop the stream
squiidz 0d016a2
mongodb_cdc: nacks resolve snapshot checkpoints (auto_replay_nacks of…
squiidz 00c7cdd
mongodb_cdc: name the misrouted-ack invariant in the snapshot token g…
squiidz 2e245cf
mongodb_cdc: persist streaming tokens surfaced by snapshot acks
squiidz dd2bb0d
postgres_cdc: route unmarshalable rows with SetError; mongodb_cdc: al…
squiidz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright 2026 Redpanda Data, Inc. | ||
| // | ||
| // Licensed as a Redpanda Enterprise file under the Redpanda Community | ||
| // License (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // https://github.com/redpanda-data/connect/v4/blob/main/licenses/rcl.md | ||
|
|
||
| package cdc | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "go.mongodb.org/mongo-driver/v2/bson" | ||
| ) | ||
|
|
||
| func TestSnapshotAckFn(t *testing.T) { | ||
| noPersist := func(context.Context, bson.Raw) error { | ||
| return errors.New("persist must not be called for a nil token") | ||
| } | ||
|
|
||
| t.Run("a nack resolves too: auto_replay_nacks off is an opt-in drop", func(t *testing.T) { | ||
| resolved := false | ||
| ackFn := snapshotAckFn(func() *bson.Raw { | ||
| resolved = true | ||
| return nil | ||
| }, noPersist) | ||
| require.NoError(t, ackFn(t.Context(), errors.New("downstream failure"))) | ||
| require.True(t, resolved, "a nacked batch is deleted per the auto_replay_nacks contract; the stream must continue past it") | ||
| }) | ||
|
|
||
| t.Run("ack resolves and accepts a nil resume token", func(t *testing.T) { | ||
| resolved := false | ||
| ackFn := snapshotAckFn(func() *bson.Raw { | ||
| resolved = true | ||
| return nil | ||
| }, noPersist) | ||
| require.NoError(t, ackFn(t.Context(), nil)) | ||
| require.True(t, resolved) | ||
| }) | ||
|
|
||
| t.Run("a streaming token surfaced by out-of-order acks is persisted", func(t *testing.T) { | ||
| // Snapshot and streaming share one ordered tracker: when a streaming | ||
| // batch acks before an earlier snapshot batch, the snapshot slot's | ||
| // resolve legitimately returns the streaming token as the contiguous | ||
| // frontier. It must be persisted, not dropped. | ||
| token := bson.Raw("streaming-token") | ||
| var persisted bson.Raw | ||
| ackFn := snapshotAckFn(func() *bson.Raw { return &token }, func(_ context.Context, tok bson.Raw) error { | ||
| persisted = tok | ||
| return nil | ||
| }) | ||
| require.NoError(t, ackFn(t.Context(), nil)) | ||
| require.Equal(t, token, persisted, "the resolved streaming checkpoint must persist through the same path as a streaming ack") | ||
| }) | ||
| } |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The snapshot ack path now resolves the checkpoint slot on nack (
snapshotAckFnignores the error argument), but this streaming ack path still bails at the top withif err != nil { return err }and never callsresolve().The rationale in this PR's own commit message applies equally here: with
auto_replay_nacks: falsea nack is a documented opt-in drop, so pinning the slot is not correct. Because a nacked streaming batch never resolves, the sharedcheckpoint.Cappedtracker keeps that slot pending forever; oncecheckpoint_limitfurther batches accumulate,cp.Trackblocks and the input stalls permanently with no way to recover short of a restart — exactly the permanent-backpressure failure the snapshot change was made to avoid.Suggest routing the streaming ack through the same resolve-then-persist shape as
snapshotAckFnso the two halves of the one tracker agree on nack semantics.Ref:
internal/impl/mongodb/cdc/input.go#L958-L968There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in dd2bb0d — the streaming ack path now resolves and persists on nack exactly like the snapshot path, with the contract-drop logged at warn. This extends the auto_replay_nacks ruling to the pre-existing guard for consistency: pinning the shared tracker wedged cp.Track at checkpoint_limit permanently, the same backpressure failure the ruling resolved elsewhere.