Skip to content

fix: preserve Data Branch lineage across TRUNCATE - #28148

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26064-bad14f06
Sep 5, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26064-bad14f06

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • FEATURE
  • ENHANCEMENT
  • DOC
  • TEST
  • CI
  • CHORE

Which issue(s) this PR fixes:

Related to #26064

What this PR does / why we need it:

Root cause: Scope.TruncateTable drops the old physical relation before the replacement ID exists. The normal DROP hook therefore retires the active Data Branch row and reclaims its protection snapshot; the replacement has no lineage metadata. DELETE FROM t without a predicate uses this same path.

Changes:

  • Use the established COPY ALTER lineage preparation, snapshot barrier, and owner-lifecycle lock for TRUNCATE.
  • Delay only the internal replacement DROP branch reclaim. After CREATE provides the new physical ID, publish the successor alter:table edge and protection snapshot, then invoke the same shared reclaim-and-compaction lifecycle used by ordinary DROP.
  • Reject a live Data Branch TRUNCATE in an explicit transaction with an operation-specific error, matching the existing COPY ALTER safety boundary.
  • Add a BVT covering consecutive TRUNCATE and predicate-free DELETE rebuilds, all four reported COPY ALTER forms, metadata/protection-snapshot transitions, DATA BRANCH DIFF, DATA BRANCH DELETE, predicate DELETE, and explicit-transaction atomicity.
  • Complete TestCCPRGC's intentionally minimal system catalog with the snapshots, PITR, and branch-metadata tables now read by its predicate-free DELETE/TRUNCATE path. Missing production catalog tables still surface as errors; this fixture now matches bootstrap.

Issue-to-test proof:

  • [Bug]: Table rebuild operations discard Data Branch identity and protection metadata #26064: test/distributed/cases/git4data/branch/metadata/branch_rebuild_lifecycle.sql proves every reported rebuild form obtains a new physical ID while retaining a live lineage edge and all required protection snapshots. It also proves DIFF and DELETE succeed, and that DELETE reclaims the full generation chain.
  • CI regression: TestCCPRGC exercises its five CCPR GC states through predicate-free DELETE after initializing every required system catalog dependency.

Tests run:

  • make build

  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/sql/compile

  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 ./pkg/util/executor

  • ./run.sh -p test/distributed/cases/git4data/branch/metadata -m genrs -i branch_rebuild_lifecycle with mo-tester (generated result inspected)

  • ./run.sh -p test/distributed/cases/git4data/branch/metadata -m run -i branch_rebuild_lifecycle with mo-tester — 59/59 passed

  • Rebase verification on 494e6a7723: the pkg/sql/compile and pkg/util/executor CGo suites passed again; BVT branch_rebuild_lifecycle passed again, 59/59.

  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m -run '^TestCCPRGC$' ./pkg/vm/engine/test — passed.

  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/vm/engine/test — passed in 146.851s.

  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=20m ./pkg/sql/compile — passed.

  • Rebase verification on 149219181f: pkg/sql/compile CGo suite passed in 6.080s; TestCCPRGC passed in 4.079s.

  • Rebase verification on 8a83e3e31e: make build passed; pkg/sql/compile CGo suite passed in 9.548s; TestCCPRGC passed in 4.120s; branch_rebuild_lifecycle BVT passed 59/59 in normal comparison mode on a clean single-node instance. Report and error report were inspected.

  • Rebase verification on e6b25ee772: controlled CGo pkg/sql/compile passed in 6.702s and TestCCPRGC passed in 4.473s. The upstream change is limited to window-frame binding and its tests, with no Data Branch/DDL overlap; the prior clean-instance lifecycle BVT evidence remains applicable.

  • Rebase verification on 0fdc39e236: controlled CGo pkg/sql/compile passed in 8.040s and TestCCPRGC passed in 4.153s. Upstream touched GROUP spill performance, BOOL aggregate compatibility, and unrelated BVT expectations, with no Data Branch/DDL lifecycle overlap; the prior clean-instance lifecycle BVT evidence remains applicable.

  • Rebase verification on 243b77a742: controlled CGo pkg/sql/compile passed in 7.235s and TestCCPRGC passed in 5.575s. Upstream changed cluster-table INSERT planning only, with no Data Branch/DDL lifecycle overlap; the prior clean-instance lifecycle BVT evidence remains applicable.

  • Rebase verification on 4356759714: controlled CGo pkg/sql/compile passed in 7.315s and TestCCPRGC passed in 5.173s. Upstream added bounded exact DISTINCT spill support and a portable SCA-cache workflow tweak, with no Data Branch/DDL lifecycle overlap; the prior clean-instance lifecycle BVT evidence remains applicable.

  • Rebase verification on 425da14974: make build passed; controlled CGo pkg/sql/compile passed in 8.041s; TestCCPRGC passed in 4.002s; and the clean-single-node branch_rebuild_lifecycle BVT passed 59/59 in normal comparison mode. The report and error report were inspected. Upstream changed float table-lock keyspace coverage, adjacent to the lock boundary, so this public regression was rerun.

  • Rebase verification on 922e792ebf: make build passed; controlled CGo pkg/sql/compile passed in 6.080s; TestCCPRGC passed in 5.327s; and the clean-single-node branch_rebuild_lifecycle BVT passed 59/59 in normal comparison mode. The report and error report were inspected. Upstream changes lock-owner recovery, a lifecycle concurrency dependency, so this public regression was rerun.

  • Coverage follow-up after the 73.91% changed-code CI result: added TestPrepareAlterDataBranchLineageRejectsLiveBranchTxnWithStatement, which reaches active-lineage DAG admission and proves the exact TRUNCATE explicit-transaction rejection before compaction or replacement. The focused controlled-CGo suite passed in 2.432s and the owning pkg/sql/compile package passed in 6.208s.

  • Rebase verification on 26d008dbd0: the two upstream commits modify aggregate recovery and grant-test cleanup only; they do not touch Data Branch or lifecycle dependencies. The public lifecycle BVT evidence from the prior exact production revision remains valid.

  • Rebase verification on fa829e5c50: make build passed; the focused controlled-CGo lifecycle suite passed in 1.320s; the owning pkg/sql/compile package passed in 6.886s; and the clean-single-node branch_rebuild_lifecycle BVT passed 59/59 with an empty error report. Upstream exposes subscription tables and hardens HAKeeper replica removal; the former is adjacent to clone behavior, so the public Data Branch regression was rerun.

  • Rebase verification on 2bf4dddb3c: make build passed; focused controlled-CGo lineage and Data Branch projection suites passed in 1.306s and 1.416s; owning pkg/sql/compile and pkg/frontend packages passed in 7.593s and 18.644s; the race-enabled pkg/sql/compile package passed in 9.129s. On a clean ready single-node service, upstream diff_composite_pk_columns passed 28/28 twice and branch_rebuild_lifecycle passed 59/59 twice; every error report was empty and the service log emitted no fatal or panic record. The upstream primary-key projection change is a direct DIFF consumer, so both public paths were rerun.

  • Rebase verification on 522285b47a: on the preceding 3facd79c8a rebase, make build passed; the combined upstream hash-partition and lineage gate suite passed in 2.490s; full and race-enabled pkg/sql/compile passed in 6.350s and 8.477s. On the exact final head, the lineage gate passed in 1.325s and the upstream owning pkg/sql/colexec/aggexec and pkg/sql/colexec/window packages passed in 23.401s and 1.233s. The first upstream commit changed compiler hash-partition protocol gating; the second is confined to bounded-RANGE aggregate/window execution. Neither alters Data Branch DDL lifecycle state. A concurrent issue [Performance]: REPLACE INTO conflict detection falls back to loop join on large tables #27141 run owned the shared mo-tester run.yml and reports, so its cleanup failed before this BVT executed; no new BVT pass/fail status is claimed. The direct clean-instance lifecycle BVT evidence remains documented above.

  • Rebase verification on d300619bb4: the sampled-statistics and Iceberg manifest-bound commits do not change the Data Branch TRUNCATE protocol or its compiler/executor/test/BVT files. On exact head e9498ef2a3, controlled CGo lineage admission tests passed in 1.413s and TestCCPRGC passed in 4.111s, covering the explicit-transaction gate and predicate-free DELETE cleanup consumer. Prior full compiler/race and clean-instance lifecycle BVT evidence remains semantically valid.

Residual risks:

  • The lineage edge, replacement relation, and reclaim transition remain in one transaction. Any failure aborts the replacement rather than exposing a detached active table.

Rebase verification

Rebased onto e74cdbe5df, including 313991b503 (PR #28172), which corrects the sampled ANALYZE expectation behind the previously unrelated window_hash_partition BVT failure. The Data Branch lineage diff is unchanged by the rebase. Focused CGo validation passed for the compile lineage gates and pkg/vm/engine/test CCPR GC coverage.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

Mergify auto-update failure triage: this was infrastructure, not a MatrixOne code or test failure. The failed check reports: For security reasons, Mergify cannot update this pull request because GitHub refused an App update to .github/workflows/sca-go-module-cache.yaml without workflows permission. No workflow or permission change was made. I rebased locally onto 494e6a7723 and force-pushed the verified head 13d78e30e9, so CI and the queue can retry from a current branch.

@gouhongshen
gouhongshen force-pushed the agent/issue-26064-bad14f06 branch from 27487af to d1e07e6 Compare September 4, 2026 09:34
@gouhongshen
gouhongshen marked this pull request as ready for review September 4, 2026 09:38

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

Reviewed exact HEAD 5c9c375. No blocking findings.

The change keeps the physical replacement, successor lineage edge, protection snapshot, old-generation retirement, and compaction in one statement transaction. skipDataBranchReclaim is scoped only to the internal replacement DROP and is reset on Compile reuse; every subsequent failure rolls back the CREATE/metadata transition rather than exposing a detached table. The live relation ID is re-resolved after the RC snapshot barrier, closing stale-plan and concurrent replacement cases.

I traced the lifecycle counterexamples: consecutive TRUNCATE / predicate-free DELETE, explicit-transaction rejection, historical-only owners, branch deletion, and concurrent owner mutation. Pessimistic execution is serialized by the source metadata and lifecycle locks (deadlocks resolve through statement retry); optimistic execution conflicts on the lifecycle write. Snapshot/metadata growth remains tied to the existing ALTER lineage contract and is reclaimed when the logical/historical owner terminates. The new BVT checks physical-ID replacement, active/retired rows, protection snapshots, DIFF, DELETE cleanup, predicate DELETE control, and rejection atomicity; exact-head author evidence covers compile/engine packages and the public SQL path.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-05 02:19 UTC · Rule: main · triggered by @gouhongshen with the @mergifyio queue command
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-05 02:19 UTC · at e7bb0572235ec4bac81eb098eb0ad8900f0065ab · squash

This pull request spent 37 seconds in the queue, including 2 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@gouhongshen

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

queue

☑️ Command queue ignored because it is already running from a previous command.

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

Re-reviewed the full exact-head diff at 6c5258dacd3a6af5fc9148e3f55c515e3e3a0b9b, including the production lineage protocol and the new explicit-transaction regression test. I found no correctness, performance, or unhappy-path blocker.

The TRUNCATE path now treats replacement as one atomic copy/swap lineage transition: resolve and lock the old physical generation, take the RC freshness barrier where required, acquire the owner-lifecycle barrier, preserve the old edge through the internal DROP, create the successor, publish the successor edge, then run the same reclaim/compaction transition as ordinary DROP. Failures before commit roll the entire DDL transaction back. The skip-reclaim option is statement-local, passed only to this internal DROP, and reset when Compile is reused.

Counterexamples checked: consecutive TRUNCATE generations, delete-as-truncate, historical snapshot/PITR ownership, live logical branches, relation replacement while waiting for an RC lock, explicit transactions, branch deletion/reclaim, and failures between DROP/CREATE/publication/reclaim. The latest test-only commit closes the exact TRUNCATE explicit-transaction gate without changing runtime behavior.

Resource/liveness audit: Q1 — lineage metadata, source snapshots, and replacement IDs remain transaction-owned and reclaim is shared with DROP; Q2 — no goroutine/channel/wait lifecycle is introduced, and all error exits are transaction rollback paths; Q3 — work is bounded by the existing lineage DAG/history probes, with no retry loop or unbounded allocation added. Ordinary TRUNCATE does pay the existing lineage serialization/probe cost required to exclude concurrent owner publication, but adds no row-data scan.

CI is still running on this exact head; per request I did not wait for it.

@gouhongshen

gouhongshen commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Unrelated CI blocker:

Resolved since this comment: #28171 is closed, and its sampled-ANALYZE BVT expectation fix (313991b503, PR #28172) is incorporated by this fresh rebase.

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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants