Skip to content

fix(iscp): retry drain while executor initializes - #26183

Merged
XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
XuPeng-SH:xp/fix-iscp-executor-readiness
Jul 26, 2026
Merged

XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
XuPeng-SH:xp/fix-iscp-executor-readiness

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #26181.

  • wait briefly for a late ISCP executor runtime only for the initial drain request
  • return the existing retryable CN-transition error if it remains unavailable
  • retry only that error with a bounded readiness window and fresh task-runner/address discovery
  • revalidate task ownership after every successful drain; if ownership moves, fence every observed runner before proceeding
  • renew and roll back all acquired fences, including best-effort cleanup of an uncertain remote target after a lost/error response
  • preserve legitimate long drains by starting a fresh readiness generation after each successful drain
  • force the assignment-before-readiness path in the existing async-index clone BVT, including when Proxy routes SQL to the task-runner CN

Validation

  • focused handler/readiness race stress: 10 iterations
  • focused runner-handoff/cleanup/timeout race stress: 10 iterations
  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=600s ./pkg/cnservice ./pkg/sql/compile
  • GOWORK=off go build -mod=readonly ./pkg/cnservice ./pkg/sql/compile
  • GOWORK=off go vet -mod=readonly ./pkg/cnservice ./pkg/sql/compile
  • formal UT/SCA and deployment BVT workflows are triggered by this PR update

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner July 26, 2026 04:54
@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 →

@XuPeng-SH
XuPeng-SH requested a review from jiangxinmeng1 July 26, 2026 04:55
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 26, 2026
@XuPeng-SH
XuPeng-SH requested a review from LeftHandCold as a code owner July 26, 2026 06:18
@XuPeng-SH
XuPeng-SH requested a review from a user July 26, 2026 06:18
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Jul 26, 2026
@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Deep review of d4d41bda3d42f3b94b9d39274be227198a6f7bb6: I found four code issues plus the current SCA blocker. I do not think this head is ready to merge.

  1. [P1] Re-observing the same CN UUID is not an ownership/fence linearization point.
    fencedRunners is keyed only by CN UUID and the loop exits as soon as a fresh read returns an already-seen UUID. The fence, however, lives in a specific in-memory ISCPTaskExecutor generation. After fencing CN-A/generation-1, the executor can restart on the same CN with an empty fence map; the task row still returns CN-A, so the loop exits without fencing generation 2. There is also an unavoidable window after the final owner read where the task can move from A to B before the DDL transaction terminates. The lease only renews the saved executor pointer/query address and never follows the new owner.
    This needs a durable job fence or an ownership epoch/token coupled to task assignment and checked by every executor generation when registering a consumer. Seeing the same UUID twice is not sufficient.
  2. [P1] Earlier runner fences can expire before the lease is started.
    Successful targets are only appended to fencedTargets; startISCPJobFenceLease is called after the entire owner-convergence loop. The actual drain intentionally uses the statement context and may legitimately take longer than the readiness deadline. For example, A is fenced, ownership moves to B, and draining B takes longer than the 30-minute fence TTL. A's fence expires while waiting for B, allowing its consumer to restart. If ownership cycles back to A, the UUID set still causes the loop to exit even though A is no longer fenced.
    Renewal must start as soon as the first target is fenced and safely incorporate later targets. Please add a short-TTL A/B handoff test with a long second drain.
  3. [P1] errors.Join destroys the primary moerr identity on failed drain cleanup.
    cleanupAfterFailure always returns errors.Join(cause, cleanupErr). Even when cleanup succeeds and cleanupErr is nil, this returns a joinError. moerr.IsMoErrCode, commit-result-unknown handling, and frontend whole-transaction rollback classification require the error itself to be *moerr.Error; they do not unwrap joined errors. A first remote drain failure such as ErrBackendClosed is already wrapped because the uncertain target is included, so ALTER/DROP INDEX in an explicit transaction can take statement-only rollback instead of the required whole-transaction rollback.
    Return cause unchanged when cleanup succeeds. If cleanup also fails, preserve the primary moerr identity or update the relevant classifiers to unwrap. Tests should assert moerr.IsMoErrCode, not only ErrorContains.
  4. [P2] Rollback can synchronously block for up to 30 minutes.
    The rollback cost-event callback creates a background context with iscp.DefaultRollbackFenceTTL and waits for all target operations via wg.Wait. The generic query client has no shorter default backend read timeout, so one connected but unresponsive old runner can hold the transaction terminal path for the full 30 minutes. Fence TTL and RPC cleanup timeout should be separate; use a short bounded cleanup deadline, log cleanup failures, and rely on TTL for fail-closed expiry. A blackholed-target rollback latency test would cover this.
  5. Current CI blocker: Matrixone CI / SCA Test on Linux/arm64 fails at pkg/sql/compile/iscp_util.go:523 with copyloopvar: the i := i copy can be deleted under Go 1.22+.

Independent validation on this exact head:

  • focused pkg/sql/compile drain/target tests: -race -count=10 passed
  • focused pkg/cnservice drain-handler tests: -race -count=10 passed
  • git diff --check passed

The previous sequential multi-target renewal/removal deadline issue is fixed by the concurrent operation helper in this head; the findings above are additional closure gaps.

@ck89119 please review again

@XuPeng-SH
XuPeng-SH force-pushed the xp/fix-iscp-executor-readiness branch from 94f936a to ff0a3fa Compare July 26, 2026 09:43
@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Follow-up safety correction in ff0a3faf2b (rebased onto current origin/main 3128259d4b): the previous head made remote renewal an upsert. That could let a delayed renew processed after rollback/remove recreate a fence and block the consumer until TTL. Renewal is now strictly conditional and removal is terminal.

The in-process dual-copy state is also linearized under one lock order:

  • renew requires an existing CN fence and, when an executor is published, an existing executor-local fence; it updates both together
  • remove deletes the CN fence and the currently published executor copy together
  • a stale executor pointer cannot recreate state after removal
  • publishing/re-publishing an executor clears and rebuilds its local fence map from the CN registry, so an old object cannot reintroduce removed state
  • the executor-not-yet-published path can still renew the already-installed pending CN fence

New deterministic regressions cover renew-before-initial-drain rejection, active renewal, remove-then-late-renew rejection, stale executor renewal, old-executor re-publication, and pending-executor renewal.

Post-rebase validation:

  • full pkg/iscp, pkg/cnservice, and pkg/sql/compile with -race: pass
  • focused ordering/generation regressions with -race -count=50: pass
  • build and vet: pass
  • targeted golangci-lint: 0 issues
  • make err-check and git diff --check: pass

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Latest-head update from another deep pass: I do not see new blockers beyond the remaining ownership-linearization gap already under discussion, but I also do not see that gap closed on the current head.

The convergence condition is still if _, ok := fencedRunners[runnerCN]; ok { break } after a fresh runner read (pkg/sql/compile/iscp_util.go:359-363). That proves only that the current CN UUID was seen/fenced before; it does not prove that no different runner owned the daemon task in between. The new tests cover A -> B -> B handoff and same-owner revalidation after a long drain (pkg/sql/compile/iscp_util_extra_test.go:560-639, 924-997), but they still do not cover A -> B -> A. A transient B owner can still admit a consumer because fences are CN-scoped and an already-running consumer is only canceled on a later failed lease check, not immediately on ownership change (pkg/iscp/executor.go:516-523, pkg/iscp/iteration.go:517-539).

So my latest-head conclusion is: the renew/remove/generation fixes look good, but the drain loop still lacks a true ownership linearization point / terminal quiescence proof.

@XuPeng-SH
XuPeng-SH merged commit c8d29e9 into matrixorigin:main Jul 26, 2026
16 of 21 checks passed
@XuPeng-SH
XuPeng-SH deleted the xp/fix-iscp-executor-readiness branch July 26, 2026 10:53

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

size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ISCP task runner is published before executor readiness, causing clone failure in Multi-CN + Proxy

4 participants