Skip to content

fix(iscp): preserve initialization lifecycle atomically - #28176

Merged
XuPeng-SH merged 11 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-iscp-watermark-stage
Sep 5, 2026
Merged

XuPeng-SH merged 11 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-iscp-watermark-stage

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

What this fixes

Closes #28175.

The periodic ISCP watermark flush rebuilt JobStatus from only the next LSN. Because Stage=Init is the zero value, an initialized async-index job could regress from Running to Init; a later iteration could execute non-idempotent initialization again and make derived index metadata inconsistent.

The fix now closes both the current write bug and the cross-restart/cross-version lifecycle holes rather than recognizing one observed row shape.

Design artifact

Atomic ISCP initialization lifecycle is the R3 design artifact. Its status remains Review required until an independent owner approves the lifecycle and rollout contract.

First-principles invariant

For one (account_id, table_id, job_name, job_id) generation:

  • maintenance may advance progress but cannot authorize initialization or regress lifecycle state;
  • InitSQL effects and Stage=Running/LSN/lifecycle evidence have one commit point;
  • a stale or compensating writer must lose by exact job ID and previous-LSN CAS;
  • recovery may retry initialization only when durable state proves that no prior non-idempotent initialization committed.

Implementation

  • Maintenance watermark writes mutate the existing JSON with JSON_SET, preserving stage, errors, lifecycle evidence, and future fields.
  • Full status writes preserve max(durable Stage, incoming Stage) and max(durable LifecycleVersion, incoming LifecycleVersion).
  • InitSQL and the Running transition execute in one transaction.
  • Atomic initialization success writes LifecycleVersion=1 with Running. An Init error writes the same evidence only through the old-LSN CAS; if Commit actually succeeded, the advanced LSN makes that compensating write lose.
  • Registration deliberately does not set the marker: the CN creating a job may not be the active executor. The marker therefore proves executor history, not creator version.
  • Startup quarantines every unversioned Completed/Init job with InitSQL, including LSN=0, advanced-LSN, and retry/error variants. Old code can leave all of those shapes after InitSQL already committed, so none is safe evidence for re-execution.
  • Recovery mirrors the same predicate in memory to cover repair-commit/logtail visibility lag.
  • CAS losers stop obsolete retries and cannot publish an error over the winning generation. Transaction commit/rollback failures remain observable.

Upgrade and unhappy paths

  • A new DDL CN cannot falsely certify a job still processed by an old executor because registration leaves the status unversioned.
  • During roll-forward, old ambiguous Init rows fail closed and require job/index recreation; already-corrupted derived data is never declared healthy.
  • If an upgraded executor stops after seeing a fresh job but before persisting success or error evidence, restart also fails closed. This is a deliberate rare availability cost because durable state cannot distinguish it from the old split-transaction crash shape.
  • Do not return ISCP task ownership to an old CN after versioned Init state exists. A supported rollout must either backport the atomic protocol and marker preservation to every eligible owner, or transfer ownership to upgraded code and prevent reassignment to old code until rollout completes.
  • Code rollback remains format-compatible, but it must not clear a committed quarantine or guess initialization history.

Performance and risk

  • No index algorithm, row-processing/data-batch hot path, public SQL, catalog column, wire protocol, goroutine, queue, or lock changes.
  • A full status update adds one bounded catalog JSON extraction/comparison. It runs per status persistence, not per source row.
  • Maintenance remains one conditional update per eligible job and preserves JSON in place.
  • Startup remains one O(number of ISCP jobs) catalog update outside the query/ingestion path; the revised predicate uses one lifecycle-version extraction instead of the previous LSN plus two error-field extractions.
  • The marker is omitted from JSON while zero, avoiding payload growth for unrelated/unhandled statuses.

Validation

  • Full pkg/cdc and pkg/iscp tests passed with the repository CGo harness.
  • Lifecycle SQL/classification/recovery/error/atomic-completion tests passed under -race -count=10.
  • Tests cover legacy LSN=0, advanced LSN, retry message, error code, normalized Pending/Running, terminal state, no-InitSQL, versioned atomic retry, marker preservation, and future-version monotonicity.
  • make err-check and git diff --check passed.
  • Existing PR validation covers atomic commit/rollback on success, statement/status failure, cancellation and panic; stale-owner CAS behavior; maintenance rollback; clean-table/start-from-now scheduling; full owning-package race tests; real async-IVF create/update/restart result verification; and two-CN handoff.

The design still requires independent approval. This update is pushed without waiting for CI.

@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 →

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Sep 5, 2026
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/L Denotes a PR that changes [500,999] lines labels Sep 5, 2026
@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Deep review result for cfea7c8ddc4930a9d5e15a1b71980e84430c3a22:

Implementation verdict: no code-level blocker found; approvable after the independent design gate is satisfied.

I traced the complete lifecycle through registration, startup repair/replay, candidate admission, InitSQL, ordinary consumption, maintenance watermark flushes, retry/CAS loss, cancellation, commit ambiguity, job recreation, and multi-CN ownership handoff.

Key conclusions:

  • InitSQL effects and Stage=Running / next LSN / LifecycleVersion=1 now share one transaction. A failed or ambiguous commit cannot be followed by a compensating writer that overwrites a committed winner because that writer uses the old-LSN CAS.
  • Maintenance mutates the durable JSON in place and preserves lifecycle/error/future fields. Full writes retain monotonic Stage and LifecycleVersion; exact job ID plus expected LSN fences stale generations.
  • Pure CAS loss stops immediately, while joined cleanup failures remain observable. Retry/backoff, worker admission/stop, result closure, and transaction completion are bounded; I found no unbounded wait or queue-growth change.
  • Legacy ambiguity is handled conservatively and SQL/Go recovery predicates agree: unversioned Completed/Init rows with InitSQL fail closed instead of guessing whether non-idempotent initialization committed.
  • Added JSON work is per status persistence, not per source row. Startup adds one bounded catalog scan per executor generation; no index row-processing hot path changed.
  • The head merges cleanly with current main (0cee094f15b1931d2911a5a2b1ce01447454b367); the two intervening main commits do not overlap ISCP/CDC code. Exact-head UT, SCA, coverage, build, proxy BVT, and pessimistic multi-CN BVT are green.

The remaining merge gate is the design artifact itself: it still says Status: Review required. An independent owner must explicitly accept the fail-closed migration behavior and the real rollout prerequisite that ISCP ownership must not return to an old CN after versioned state exists (or the protocol must be backported to every eligible owner). That condition is documented but intentionally not enforced by this code.

The authenticated GitHub user is also the PR author (XuPeng-SH), so GitHub does not permit this account to submit an APPROVE review on its own PR. Please obtain the independent design/PR approval from one of the requested owners.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact head cfea7c8. No blocking correctness, availability, performance, or lifecycle issue found.

I independently accept design revision 2, including the conservative fail-closed treatment of unversioned Completed/Init rows with InitSQL. I also accept the documented rollout invariant as a release/operations gate: once versioned lifecycle state can be written, every CN eligible to own ISCP must understand this protocol, or ownership must be pinned so it cannot return to an old CN.

The implementation closes the original failure mode: InitSQL effects and the Running lifecycle marker commit atomically; exact job generation plus previous-LSN CAS fences stale or ambiguous writers; maintenance advances watermark in place and cannot erase or regress Stage/LifecycleVersion; restart rebuilds from durable state and quarantines genuinely ambiguous legacy rows. CAS losers, commit/rollback failures, cancellation, worker generation shutdown, and partial multi-job watermark flushes retain bounded and observable behavior.

Q1 cleanup ownership: pass. Transactions, results, workers, consumers, and flush reservations have one effective cleanup/reconciliation path.
Q2 bounded waits: pass. Iterations, catalog operations, retry budgets, transaction finish, worker stop, and consumer drains are canceled or time-bounded.
Q3 bounded growth: pass. Worker concurrency and queue capacity are fixed; startup scan is bounded by the catalog job set and a five-minute context; no per-source-row hot-path growth was added.

Validation evidence at this exact head is green: Ubuntu x86 UT, coverage, arm64 SCA, build, proxy multi-CN BVT, and pessimistic multi-CN BVT. The original vector_ivf_async.sql scenario ran 39/39 successfully in the pessimistic multi-CN job. The branch is behind main but the intervening main changes do not overlap this PRs files.

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/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ISCP watermark flush resets initialized index stage and reruns IVF init

3 participants