Skip to content

fix: preserve transaction visibility for table clone - #26293

Merged
XuPeng-SH merged 12 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-26113-same-txn-clone
Jul 30, 2026
Merged

XuPeng-SH merged 12 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-26113-same-txn-clone

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #26113

What this PR does / why we need it:

Clone restore currently injects a generated MO_TS even inside an explicit transaction. That forces source resolution through a cloned snapshot transaction, which cannot see a table created earlier by the shared transaction.

This change:

  • keeps the generated timestamp for branch metadata/protect-snapshot bookkeeping, but does not inject that generated hint into restore SQL under explicit BEGIN;
  • uses the same shared-transaction view for COPY GRANTS unless the user explicitly requested a snapshot;
  • interprets a same-commit parent edge as having no parent-owned history before the parent creation commit;
  • resolves direct and intermediate ancestors by stable table ID only when edge TS < creation CTS <= endpoint snapshot;
  • resolves a dropped intermediate at the bounded lineage endpoint rather than the current snapshot;
  • clamps LCA row probes to the LCA creation commit so post-commit DIFF never reads before the table exists.

User-provided snapshot hints remain intact for both data and grants, ordinary autocommit clones retain the existing generated-hint path, and historical ancestors continue to resolve at their original clone snapshot.

Regression coverage uses a real embedded cluster and one MySQL connection to verify:

  • ordinary autocommit and explicit named-snapshot clones remain distinct after the source changes;
  • explicit named-snapshot COPY GRANTS preserves snapshot data and privileges;
  • raw CLONE, COPY GRANTS, and three-level Data Branch chains read their own uncommitted DDL;
  • commit preserves exact src -> b1 -> b2 -> b3 lineage and matching protect snapshots;
  • direct DIFF and deep b3 against src DIFF after dropping intermediate b1 return the expected counts;
  • rollback removes tables, copied role privileges, mo_branch_metadata, and branch protect snapshots atomically.

Local validation on exact head e4e1154df21a59df41e35e0b90d366f5f11f6578:

  • focused issue regression under -race: PASS (T=20.739s, B=30s, N=1)
  • full ./pkg/tests/issues -race: PASS (367.233s)
  • exact UnionBatch regressions under -race -count=100: PASS
  • full ./pkg/container/vector -race: PASS (3.071s)
  • full ./pkg/frontend -race: PASS (27.134s)
  • production package build and affected go vet: PASS
  • BVT authored: test/distributed/cases/git4data/clone/clone_can_rollback.sql and .result; exact-head CI execution pending
  • git diff --check: PASS
  • rebase proof: all ten commits are patch-identical by git range-diff; the only upstream change in a touched production file is non-overlapping
  • schema v4 preflight: PASS review=PASS validation=PENDING, diff hash 718fee756f387d451f79c27514863104d891973cb3ca27296c92c5349f2995bd

QA handoff

  • QA required: yes
  • Reason: this changes explicit-transaction visibility and the interpretation of persisted Data Branch timestamps during later DIFF.
  • Required scenarios: on a deployed environment, use one connection and explicit BEGIN to build multi-level CREATE TABLE ... CLONE, COPY GRANTS, and DATA BRANCH CREATE TABLE chains; verify read-your-own-DDL, explicit snapshot data/grant preservation, commit lineage/protect snapshots, direct and deep post-commit DIFF after dropping an intermediate ancestor, and rollback cleanup of tables, privileges, metadata, and branch snapshots. Retain an autocommit control.
  • The linked issue intentionally remains open for QA verification.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 28, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Jul 28, 2026
@VioletQwQ-0
VioletQwQ-0 force-pushed the codex/issue-26113-same-txn-clone branch from a37a215 to e644873 Compare July 28, 2026 11:02
@VioletQwQ-0
VioletQwQ-0 marked this pull request as ready for review July 29, 2026 02:46
@VioletQwQ-0
VioletQwQ-0 requested a review from XuPeng-SH as a code owner July 29, 2026 02:46
@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 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.

[P1] Handle a zero-history table when it is the LCA itself

The new fallback covers a created-and-dropped table only while walking one side of a path. It does not cover the same zero-history node when it is the LCA of two surviving sibling branches: diffOnBase resolves a non-endpoint LCA with getRelationById at the pre-commit clone timestamp and returns immediately on the missing relation, before resolveSameTransactionDataBranchRelation / hasZeroHistory can run.

I reproduced this on this exact head with an authenticated embedded cluster:

begin;
data branch create table issue_26113.f1 from issue_26113.src;
insert into issue_26113.f1 values (4, shared txn change);
data branch create table issue_26113.f2 from issue_26113.f1;
data branch create table issue_26113.f3 from issue_26113.f1;
drop table issue_26113.f1;
commit;
data branch diff issue_26113.f2 against issue_26113.f3 output count;

Both endpoints have identical inherited data, so the expected count is 0. Instead the last statement fails with internal error: can not find table by id <f1-id>. This is the same transaction-visibility class addressed by the PR, but in a branched DAG rather than the currently tested linear chain. Please make zero-history resolution apply systemically to LCA resolution as well and add a sibling-LCA regression test.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed the latest zero-history LCA review finding in fbedd96.

  • Reproduced the exact sibling-LCA failure on the previous head before changing production code.
  • Require endpoint-bounded stable-ID misses before classifying the LCA as zero-history.
  • Preserve the original DAG for schema/range derivation, then compare whole endpoint histories without dereferencing the absent LCA relation.
  • Added bidirectional identical-sibling assertions and bidirectional divergent-sibling assertions, plus deleted-LCA/live-child metadata checks.

Exact-head local validation:

  • go test ./pkg/frontend -run Test.*DataBranch -count=1
  • go test ./pkg/tests/issues -run ^TestIssue26113CloneCreatedTableInSameTransaction$ -count=3
  • go test -race ./pkg/tests/issues -run ^TestIssue26113CloneCreatedTableInSameTransaction$ -count=2
  • focused UnionBatch normal/race tests
  • git diff --check
  • preflight schema v4: PASS review=PASS, validation=PENDING

@XuPeng-SH please re-review the current head.

@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 30, 2026
@VioletQwQ-0
VioletQwQ-0 force-pushed the codex/issue-26113-same-txn-clone branch from fbedd96 to e4e1154 Compare July 30, 2026 05:10
@VioletQwQ-0
VioletQwQ-0 requested a review from a user July 30, 2026 05:10

@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 updated head and the author's responses. The previous zero-history LCA blocker is now closed: classification requires stable-ID misses at the historical probe and both endpoint creation timestamps, schema/range construction handles the absent ancestor without swallowing unrelated errors, and the symmetric whole-endpoint comparison preserves inherited and divergent rows. The full authenticated issue regression (including sibling LCA, dropped intermediates, COPY GRANTS, commit/rollback) passes locally, as do the focused UnionBatch fast-path tests under -race.

@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 updated head, including the author’s response to the zero-history LCA blocker. The prior nine commits are patch-equivalent across the rebase; the new LCA fallback is guarded by missing stable-ID probes and endpoint CTS bounds, preserves schema/range derivation, and compares endpoint histories symmetrically. The embedded issue regression (including sibling LCA, linear lineage, COPY GRANTS, and rollback cases) and focused frontend Data Branch suite pass locally. No remaining blocking findings.

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