Skip to content

fix: preserve clone auto-increment continuation - #27154

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27092-853b7421
Aug 30, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27092-853b7421

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Aug 14, 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:

Fixes #27092

What this PR does / why we need it:

Root cause

Fresh table clones copied the source row from mo_catalog.mo_increment_columns into the destination allocator. That row offset is the upper bound of a reserved allocation batch (10,000 in the reproducer), not the next source-session value (4). Because a fresh clone has a new table ID and an independent allocator, transferring that reservation made its first generated ID 10,001.

The persisted table definition separately carries explicit schema lower bounds such as ALTER TABLE ... AUTO_INCREMENT = 100. Those are user-visible state and must still be preserved.

Changes

  • For a fresh clone, reconstruct visible auto-increment state from the copied row maximum and the larger source/destination schema lower bound. Do not copy the source allocator reserved-batch upper bound.
  • Continue copying raw allocator state for ALTER COPY paths that retain the column-ID space, where existing CN caches make that state part of the ownership handoff.
  • Continue copying allocator state for hidden internal auto-increment columns; hidden index-table allocator handling is unchanged.
  • Add unit coverage for the fresh-clone and ALTER COPY ownership boundaries, including a source schema lower bound larger than the destination lower bound.
  • Add BVT coverage for table clone, database clone, both Data Branch forms, empty sources, deleted maximum IDs, explicit AUTO_INCREMENT, explicit transactions, and historical snapshots.
  • Stabilize the five existing snapshot stored-procedure checks with ORDER BY name and @sortkey:1, while retaining @ignore:0,9,10; this changes neither the expected proc_id entries nor any non-ignored field assertion.
  • Update table-clone and temporary-table-clone BVT expectations to assert contiguous IDs from the highest copied row instead of discarded source reservation batches.

Issue-to-test proof

  • The exact issue reproduction reports source next 4, clone next 5, and first cloned-table insert 4 for table, database, and both Data Branch clone forms.
  • Empty sources insert 1; a source whose largest row was deleted seeds the independent clone from the copied maximum; explicit AUTO_INCREMENT = 100 inserts 100; snapshot clone asserts snapshot-visible rows plus exact 4 / 5 inserted/next values.
  • A permanent source cloned into a temporary table preserves copied IDs 10 and 11, then assigns 12 to the first destination insert.
  • Unit tests prove that fresh visible columns discard the persisted reservation while preserving the larger source/destination schema floor; ALTER COPY and hidden internal columns retain allocator state required by their ownership model.
  • The existing chained-clone BVT proves subsequent clone and delete/insert sequences continue at 40001 through 40006, without introducing a new 10,000-value gap at each clone.
  • The snapshot/restore procedure checks still validate every catalog field except the pre-existing ignored ID and timestamp columns. Their deterministic unique name ordering prevents ignored allocator IDs from pairing one procedure with another.

Verification

Latest semantic rebase: patch-equivalent head 1c9ff2e42bc751bd0028bcfe0cd51b8704071bcb was rebased conflict-free from main at a15139da62b938b0918c19675c619b259cd86460 onto main at 07fe9a69c6a3d6ed5e2b4299fb143d10bef442c0, producing exact head 23c7a20c072375324fee984c087de370ef5bd323.

  • git range-diff a15139da62..1c9ff2e42b 07fe9a69c6..23c7a20c07: all four clone patches are equivalent.
  • Stable aggregate patch ID before and after the rebase: ff530dfc6cb58fd343bc0663b95c917a95aa40fc.
  • The final diff is the intended six clone files plus two targeted snapshot BVT files; git diff --check origin/main...HEAD passed and the worktree is clean.
  • On exact head c3332623e5be8961a2c54bed286c888b75f82bee, an isolated local MatrixOne service and mo-tester upstream/main 334d3e124bbfbdcd6b5cc63439278d172c72b706 passed sys_restore_system_table_to_sys_account twice with CI flags -g -n -o: 313/313 statements each time. Normal metadata mode also passed 313/313.
  • A direct matcher negative-control proves the BVT assertion remains strict: ignored IDs 9/10 versus expected 1920000/1920001 fail under full-row sorting, while ORDER BY name plus @sortkey:1 pairs rows correctly; mutations to each of the 14 non-ignored columns are rejected. @sortkey:1 alone remains order-dependent, so it is deliberately paired with SQL ordering.
  • Exact-head MatrixOne CGo validation selected and passed all eight focused clone allocator tests.
  • Incoming main commit 07fe9a69c6 fix(embed): align HAKeeper transport timeout under race (#27849) changes only embed/logservice configuration and its tests, with no PR-file overlap. All six directly affected tests passed: three embed timeout/config tests, two logservice client-config tests, and the authenticated two-CN fixture test.
  • Because the incoming logservice change is a transitive dependency of the clone owners, the complete pkg/sql/compile, pkg/frontend, and pkg/sql/colexec/table_clone packages were rerun through the MatrixOne CGo wrapper and passed on exact head 23c7a20c07.
  • Workflow 33283224004 attempt 1 on exact head 23c7a20c07 passed shared build, normal Ubuntu UT, SCA, Coverage UT, and PROXY BVT. All three changed clone cases passed; PESSIMISTIC BVT reproduced only unrelated [Bug]: mo-tester sorts rows by ignored columns, causing false BVT failures #27164, and aggregate Coverage was derivative.
  • Attempt-2 PESSIMISTIC BVT job 99187224896 is in progress after the single permitted failed-job rerun.

CI investigation

Residual risks

A fresh clone intentionally owns an independent allocator. If the highest generated source rows were deleted, the clone starts after the highest row it actually copied rather than inheriting an unused cached range from the source CN. Explicit schema lower bounds remain preserved. There are no catalog, wire-format, or API changes in this PR, and the fix does not read or mutate source CN allocator caches.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Aug 14, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Aug 14, 2026
@gouhongshen
gouhongshen force-pushed the agent/issue-27092-853b7421 branch from 4a1a0e6 to 34cfec2 Compare August 14, 2026 07:53
@gouhongshen

gouhongshen commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor Author

The underlying mo-tester pairing defect remains tracked in #27164. This PR now applies a case-only mitigation to all five mo_stored_procedure snapshot queries: ORDER BY name plus @sortkey:1, retaining @ignore:0,9,10, every expected proc_id, and all other checked fields. Exact-head local BVT passed 313/313 twice with upstream/main mo-tester; fresh CI on c3332623e5 is pending.

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

Deep review completed on exact head 9cf7087.

The fresh-clone versus ALTER-copy allocator ownership split is consistent: visible columns on a new table are rebuilt from the transaction-consistent copied-row maximum plus schema/session floors, while retained-ID ALTER paths and hidden internal allocators preserve their fenced state. I also verified the issue reproduction against a locally built exact-head server (source next 4, clone insert 4, clone next 5), explicit AUTO_INCREMENT=100, and the clone-of-clone empty-source counterexample. Focused checked-allocator tests, the full table_clone package, and focused race tests passed. No blocking code issue found.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

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

This pull request spent 18 seconds in the queue, including 1 second 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 Aug 30, 2026

Copy link
Copy Markdown
Contributor

queue

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

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 kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CLONE does not preserve AUTO_INCREMENT state

3 participants