Repository navigation
Fix index consumer deadlock - #25666
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Blocking issue:
- In the tail path,
sendSqlcan now stop the producer viaerrch/ctx.Done, but the consumer side still handlescase e2 := <-errch: errch <- e2; returnas a successful return from the long-livedRunTxnWithSqlContextcallback (pkg/iscp/index_consumer.go).RunTxnWithSqlContextcommits onnil(pkg/vectorindex/sqlexec/sqlexec.go:360-365), so a producer-side failure after some tail SQL has already been consumed will commit partial hidden-table changes while skippingUpdateWatermark(). That trades the deadlock for a correctness hole: the next retry replays from the old watermark against already-committed partial index state.
Suggestion:
- On the tail runner's
errchbranch, propagate the error (or a rollback sentinel) instead of bare-returning, so the transaction rolls back together with the missing watermark update. - Add a regression test that forces a later
sendSqlfailure/cancel after at least one tail SQL has already been executed, then asserts rollback + no watermark advance.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Latest head looks good to me.
The two blocking lifecycle issues from my last review are fixed in this update:
- the consumer-side cancellation path is now wired through the shared iteration context instead of context.Background(), so sibling failure / explicit cancel can actually interrupt in-flight consumers;
- SQL/index runners now propagate ctx.Err() instead of returning success-shaped nil on cancellation, and RunTxnWithSqlContext derives its txn context from the parent ctx instead of context.Background().
The DataRetriever side also now drops refcounts on failed/canceled deliveries, so the earlier post-failure AtomicBatch ownership leak is closed as well. I don't see a remaining high-confidence correctness blocker at this head.
fengttt
left a comment
There was a problem hiding this comment.
Please take another review/design at the mutex usage.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Thanks for the latest fixes — the earlier deadlock / cancellation blockers I raised are addressed. But two high-signal issues still remain at this head:
- Shared iterations now fail all sibling jobs on the first consumer error.
runISCPTaskIterationConsumers groups jobs together when their watermark window can be shared (pkg/iscp/table_entry.go and pkg/iscp/job_config.go), but on the first consumer failure it now calls cancel() for the whole shared iteration (pkg/iscp/iteration.go:472-487). Any healthy sibling in the same iteration then returns context.Canceled, gets statuses[i].SetError(err), and is flushed with watermark=status.From instead of status.To (pkg/iscp/iteration.go:420-428, 677-687). The new test TestRunISCPTaskIterationConsumersSiblingFailureCancelsInFlightConsumer locks in exactly that behavior. That means one broken index job can roll back progress for every healthy sibling that only happened to share the same source scan window.
Suggestion: shared iteration should stay an optimization, not an all-or-nothing failure domain. Either do not cancel healthy siblings on one consumer failure, or at minimum do not persist sibling context.Canceled as a job failure / watermark rollback.
- Caller cancellation can now bypass explicit txn cleanup in RunTxnWithSqlContext.
RunTxnWithSqlContext now derives newctx from the parent ctx (pkg/vectorindex/sqlexec/sqlexec.go:350-365), which is correct for in-flight cancellation, but it also uses that same canceled context for txnOp.Rollback / Commit. On this PR head, txnOperator.Rollback/Commit first call CancelAndWaitRunningSQLWithSQL(ctx, ...) and close locally on ctx error before sending the rollback/commit RPC (pkg/txn/client/operator.go:847-852, 901-906, 950-955 in this head). So if the caller cancels mid-transaction, the ISCP helper can skip explicit TN rollback/commit cleanup entirely and rely on backend GC instead.
Suggestion: keep parent cancellation for body execution, but perform rollback/commit finalization with a fresh bounded cleanup context so cleanup still reaches TN deterministically.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Latest head looks good to me.
The two blockers from my last review are addressed in this update:
- shared ISCP iterations no longer cancel every healthy sibling job on the first consumer failure, and the new test now checks that a healthy sibling keeps a clean status while only the failing sibling is marked failed;
- RunTxnWithSqlContext now uses a fresh bounded cleanup context for rollback/commit finalization, so caller cancellation no longer bypasses explicit txn cleanup.
I don't see a remaining high-confidence correctness blocker at this head.
What type of PR is this?
Which issue(s) this PR fixes:
issue #25632
What this PR does / why we need it:
Fixes a permanent deadlock in
IndexConsumer.Consumewhen the downstreamindex SQL executor returns an error.
Previously, the consumer goroutine could report the executor error and exit
while the producer continued generating CDC SQL and attempted to send to the
unbuffered
sqlBufSendCh. With no receiver left, the producer could blockforever and the original executor error would never be returned.
This change:
flushCdcerrors fromsinkTailTest Matrix
Unit / Package Tests
Area Case Expected Result Status
━━━━━━━━━━━━━━━━━━ ━━━━━━━━━━━━━━━━━━ ━━━━━━━━━━━━━━━━━━ ━━━━━━━━━━━━━━━━━━
IndexConsumer SQL executor Consume returns Passed
executor failure fails after the original
first batch executor error
promptly;
producer does
not deadlock
────────────────── ────────────────── ────────────────── ──────────────────
IndexConsumer flushCdc fails final flush Passed
tail final flush at end of error is
sinkTail returned instead
of discarded
────────────────── ────────────────── ────────────────── ──────────────────
IndexConsumer producer sendSql exits Passed
blocked send attempts to send via ctx.Done() /
while context is errch; no
canceled / permanent block
consumer is gone
────────────────── ────────────────── ────────────────── ──────────────────
CUVS runner CUVS factory/ errors are Passed by
error reporting save/append reported through package tests /
errors non-blocking compile path
reportIndexConsu
merErr
Dev Cluster Failpoint Tests
Run:
make dev-build TYPECHECK=0
make dev-up
TIMEOUT_SECONDS=120 CASE=all-cpu etc/docker-multi-cn-local-disk/iscp-chaos-
test.sh
fj/iscp/index/exec/errorfj/iscp/index/exec/errorfj/iscp/index/exec/errorfj/iscp/index/exec/errorfj/iscp/index/exec/errorfj/iscp/index/exec/errorfj/iscp/index/send/blockfj/iscp/index/close/blocksqlBufSendChfj/iscp/index/hnsw/update/error