Skip to content

Fix index consumer deadlock - #25666

Merged
XuPeng-SH merged 12 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix-index-consumer-deadlock
Jul 14, 2026
Merged

XuPeng-SH merged 12 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix-index-consumer-deadlock

Conversation

@jiangxinmeng1

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #25632

What this PR does / why we need it:

Fixes a permanent deadlock in IndexConsumer.Consume when the downstream
index 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 block
forever and the original executor error would never be returned.

This change:

  • makes producer sends select on downstream errors and context cancellation
  • preserves final flushCdc errors from sinkTail
  • reports ISCP index consumer errors through a non-blocking helper
  • applies the same non-blocking error reporting pattern to the CUVS runner
  • adds ISCP index failpoints for executor/send/watermark/close/HNSW/CUVS paths
  • adds a dev-cluster chaos script for repeatable ISCP index failure testing

Test 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

Flow Fault Point Workload Status
IVF-FLAT snapshot first batch fj/iscp/index/exec/error async IVF index
over existing rows Passed
IVF-FLAT snapshot second batch fj/iscp/index/exec/error async IVF
index over 8300 rows to force multiple flushes Passed
IVF-FLAT tail first batch fj/iscp/index/exec/error create async IVF
index, then insert tail rows Passed
IVF-FLAT tail second batch fj/iscp/index/exec/error create async IVF
index, then insert 8300 tail rows Passed
FULLTEXT snapshot fj/iscp/index/exec/error async FULLTEXT index over
existing rows Passed
FULLTEXT tail fj/iscp/index/exec/error create async FULLTEXT index,
then insert/delete tail rows Passed
Producer send slow path fj/iscp/index/send/block injected sleep before
channel send Passed
Channel close slow path fj/iscp/index/close/block injected sleep
before closing sqlBufSendCh Passed
HNSW update fj/iscp/index/hnsw/update/error create async HNSW index,
then insert tail row Passed

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Jul 13, 2026

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking issue:

  • In the tail path, sendSql can now stop the producer via errch / ctx.Done, but the consumer side still handles case e2 := <-errch: errch <- e2; return as a successful return from the long-lived RunTxnWithSqlContext callback (pkg/iscp/index_consumer.go). RunTxnWithSqlContext commits on nil (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 skipping UpdateWatermark(). 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 errch branch, 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 sendSql failure/cancel after at least one tail SQL has already been executed, then asserts rollback + no watermark advance.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fengttt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take another review/design at the mutex usage.

Comment thread pkg/iscp/data_retriever.go Resolved

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the latest fixes — the earlier deadlock / cancellation blockers I raised are addressed. But two high-signal issues still remain at this head:

  1. 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.

  1. 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 XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants