Skip to content

[4.2-dev] fix: restore DATA BRANCH lineage after restore - #32868

Merged
mergify[bot] merged 4 commits into
matrixorigin:4.2-devfrom
gouhongshen:agent/issue-32820-4.2-dev-cbbee9d8
Nov 17, 2026
Merged

mergify[bot] merged 4 commits into
matrixorigin:4.2-devfrom
gouhongshen:agent/issue-32820-4.2-dev-cbbee9d8

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Nov 17, 2026 •

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:

Related to #32820.

What this PR does / why we need it:

Snapshot and PITR restore recreate DATA BRANCH tables with new physical rel_id values. The restore path preserved table data and dat_type='data-branch' but did not publish active mo_branch_metadata lineage for those new IDs, so the restored branch failed DATA BRANCH DELETE with Error 20101.

Multi-generation restore also has two related lifecycle requirements: ordinary ancestors need their historical branch protection, and a compacted ALTER generation can have no current metadata when its descendant is restored. Restore must coordinate with deletion of the last live sibling so reclamation cannot remove protection required by the restored descendant.

Root cause

  1. Table recreation allocated new physical IDs without DATA BRANCH clone publication for the restored table's current ID.
  2. Lineage reconciliation assumed every historical ALTER ancestor still had current metadata, even though ALTER cleanup can remove that generation.
  3. Current lineage/protection inspection occurred outside the lineage DAG coordination used by ALTER compaction and sibling reclamation, allowing protection to be reclaimed after restore observed it.

Changes

  • Add historical lineage collection and locked current-state reconciliation for table/database snapshot and PITR restore.
  • Publish direct lineage and required ordinary ancestor protection in the existing restore transaction, preserving historical parent IDs, clone timestamps, creators, levels, and deleted states.
  • Reconstruct only missing alter:<level> ancestors as deleted history. Missing ordinary ancestors, duplicates, identity mismatches, malformed history, and cycles fail without partial publication.
  • Acquire the existing full-metadata DAG lock, refresh the pessimistic read-committed workspace after lock waits, re-read current state, and hold coordination through restore commit.
  • Expose the existing single-row branch-protection insertion through the caller's transaction. Account/cluster restore behavior is unchanged.
  • Add focused frontend unit tests, real-cluster issue regressions, and the original SQL BVT coverage.

Issue-to-test proof

Behavior Executable proof
Original database snapshot, database PITR, and table snapshot reproduction TestIssue32820SnapshotRestoreRestitchesBranchLineage, TestIssue32820PITRRestoreRestitchesBranchLineage, and TestIssue32820TableSnapshotRestoreRestitchesBranchLineage; branch_restored_lineage.sql/.result covers the user-visible SQL flow. The database snapshot/PITR tests fail on the assigned base with missing current-ID lineage and Error 20101, and pass with this change.
Ordinary A→B→C ancestry, protection, DIFF, and cleanup TestIssue32820SnapshotRestoreRestoresAncestorProtection and TestIssue32820PITRRestoreRestoresAncestorProtection.
Compacted A→B0→B1(ALTER)→C ancestry, protection ownership, DIFF, and cleanup TestIssue32820SnapshotRestoreReconstructsAlterAncestorLineage and TestIssue32820PITRRestoreReconstructsAlterAncestorLineage. Both failed before the repair because B1 metadata was absent.
Concurrent last-sibling deletion and descendant restore TestIssue32820RestoreSerializesSiblingProtectionReclaim, including exact committed lineage/protection and final cleanup. This test failed before restore joined DAG coordination.
Validation, rollback, publication ordering, and error propagation Fourteen focused TestRestitchRestoredBranchLineage* / TestRestoreBranchLineage* frontend unit tests.
Independent black-box behavior Corrected compacted-ALTER snapshot and PITR cases, the four-session lock-observed overlap case, and eleven retained regressions passed in the independent Challenger.

For multi-generation cases, the semantic DIFF oracle is exactly one UPDATE row for id=1,v=11; restored C retains its historical v=10. Tests also verify that deleted ancestors stay deleted, C-old is not reactivated, reclaimed ALTER protection is not recreated, and final deletion cleans restored protection.

Validation

Run from the worktree with GOWORK=off, the repository CGo environment, and the current compiler scratch directory:

go list -mod=readonly ./pkg/frontend ./pkg/tests/issues
go build -mod=readonly ./pkg/frontend
go vet -mod=readonly ./pkg/frontend ./pkg/tests/issues

.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=5m \
  -run '^(TestRestitchRestoredBranchLineage.*|TestRestoreBranchLineage.*)$' \
  -o /tmp/issue-32820-pr-create-1794895086030/frontend.test ./pkg/frontend

.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=8m \
  -run '^(TestIssue32820(Snapshot|PITR|TableSnapshot)RestoreRestitchesBranchLineage|TestIssue32820(Snapshot|PITR)RestoreRestoresAncestorProtection|TestIssue32820(Snapshot|PITR)RestoreReconstructsAlterAncestorLineage|TestIssue32820RestoreSerializesSiblingProtectionReclaim)$' \
  -o /tmp/issue-32820-pr-create-1794895086030/issues.test ./pkg/tests/issues

Final PR-creation results on implementation commit d9da981988eccc758a69667ab0e4a6d4dfc8c9fb (before Mergify's automatic target-branch merge): gofmt reported no differences; go list, go build, and go vet exited 0. All fourteen selected frontend unit tests passed (ok github.com/matrixorigin/matrixone/pkg/frontend 3.404s). All eight selected real-cluster regressions passed (ok github.com/matrixorigin/matrixone/pkg/tests/issues 36.253s). Logs and saved exit statuses are retained under state/artifacts/issue-32820/create-pr-*.

Residual risk

The complete repository suite, Go race belt, and full mo-tester BVT suite remain for CI. The focused unit and real-cluster regressions cover the changed restore behavior and its red/green proof; this turn does not claim those broader suites ran.

SCA follow-up

Commit 46ef2d6a731d5de7ab63d56f0a15160ec77f7288 preallocates the restored-lineage metadata and protection insert buffers, resolving the two prealloc findings in MatrixOne ALL CI run 44108040094, job 134126747724.

The direct golangci-lint 2.6.2 check (golangci-lint run -v --concurrency 1 -c .golangci.yml ./pkg/frontend) and all fourteen focused TestRestitchRestoredBranchLineage* / TestRestoreBranchLineage* frontend tests passed locally. The combined Make target's separate molint vet wrapper could not run with the installed newer molint CLI, so the failed golangci-lint stage was invoked directly with the CI-pinned version; fresh CI will verify the complete static-check target.

Snapshot/PITR restore recreates tables with new physical IDs. Publish
current-ID lineage and ordinary ancestor protection, reconstruct compacted
ALTER history, and coordinate with sibling reclamation under the existing
lineage DAG lock.

Add focused frontend, real-cluster, and BVT regressions.

Related to matrixorigin#32820.
@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 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

Address the SCA prealloc findings for metadata and protection reconciliation.
@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 46ef2d6a731d5de7ab63d56f0a15160ec77f7288

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 46ef2d6a731d5de7ab63d56f0a15160ec77f7288

Assessment: approve

The fix reuses the restore transaction, DAG lock and protection writer. Historical/current reconciliation is justified to preserve ancestry and deleted states; no actionable defects remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed the complete eight-file delta, linked issue and all three discussion entries; source remained unchanged.

  • All 14 focused frontend tests and eight real-cluster regressions passed using the three-CN fixture.

  • Both owning packages passed normal and race suites under -short; new regressions also passed without -short. Adaptive concurrency validation passed with T=23.41s, B=30s, N=1.

  • Baseline controls reproduced missing lineage and Error 20101 for snapshot and PITR restore; the candidate passed those cases.

  • Verified formatting, 173 native inputs, and command/source/exit receipts against retained logs.

Limitations:

  • Full mo-tester, predecessor-binary and forced-GC retention experiments were not independently rerun.

  • Supplied CI reports UT/SCA/BVT success; external workflow commands and author raw artifacts were unavailable.

@mergify mergify Bot added the queued label Nov 17, 2026
@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into 4.2-dev as 72c43e9 at 19:32 UTC

51 min in the queue, 49 min of it CI.

So far

  • ✅ Entered the queue Tue 17 Nov, 18:40 · rule release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ✅ Passed · in place
  • ✅ Merged 19:32 · 72c43e9 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — cf312d5f Deployed Nov 17, 2026 by mergify[bot]
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/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants