Commit 48b6964
feat(auto-increment): add transactional epoch fence (#26027)
## What type of PR is this?
- [x] API-change
- [ ] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring
## Which issue(s) this PR fixes:
issue #23143
## What this PR does / why we need it:
This is the first AUTO_INCREMENT-specific prerequisite split from the
closed #25883. It does not expose `ALTER TABLE ... AUTO_INCREMENT=N`
yet.
The invariant introduced here is: a CN write carries the AUTO_INCREMENT
epoch observed when its values were allocated, and TN accepts the write
only when that epoch matches the table epoch. Once a table enters a
fenced epoch, legacy writers that cannot provide an epoch fail closed.
| Correctness requirement | Change in this PR |
| --- | --- |
| Preserve the allocator generation across the write path | Persist the
epoch in `SchemaExtra` / `plan.TableDef`, propagate it through disttae
workspace, row and object writes, flush/compaction, RPC, and TN
relations |
| Prevent stale cached values from committing after a reset | Validate
the known epoch at TN prepare/commit and require every epoch transition
to be exactly `current + 1` |
| Keep the fence effective after restart | Rebuild committed DML
watermarks during replay and keep prepared replay transactions fenced
until commit or rollback |
| Remain compatible before the feature is enabled | Treat an unknown
legacy epoch as zero only while the table epoch is zero; after the first
reset, unknown writers are rejected |
Additional guards reject epoch exhaustion before mutation and keep
ordinary schema ALTER operations from advancing the AUTO_INCREMENT
epoch.
### Explicit non-goals
- no allocator offset/cache reset API;
- no COPY/CLONE allocator reconciliation;
- no user-facing `ALTER TABLE ... AUTO_INCREMENT=N` planner or compile
entry point;
- no generic prepared/committing 2PC recovery redesign. The independent
TN route/cancellation prerequisite was merged in #25956.
### Diff size
- handwritten code and tests: 23 files, `+1283/-131`;
- generated protobuf code: 2 files, `+1565/-1079`;
- total: 25 files. Proto sources and generated files are committed
together.
### Validation
- `go test ./pkg/vm/engine/disttae ./pkg/vm/engine/tae/catalog
./pkg/vm/engine/tae/rpc ./pkg/vm/engine/tae/txn/txnimpl
./pkg/vm/engine/tae/db/test`
- focused `-race` coverage for epoch transitions and replay
commit/rollback lifecycle
- protobuf regeneration stability check
- `git diff --check`
- `mo-pr-preflight-review`: PASS at exact head
`4122a7add078c79757121a4add2d8771113c7980`
- `mo-self-review`: no open blocker
The PR is intentionally Draft while its full CI runs and while this
prerequisite is reviewed independently.
---------
Co-authored-by: ULookup <CHBulookup@outlook.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>1 parent f6070a0 commit 48b6964
25 files changed
Lines changed: 2848 additions & 1210 deletions
File tree
- pkg
- pb
- api
- plan
- sql/plan
- vm/engine
- cmd_util
- disttae
- cache
- tae
- catalog
- db/test
- rpc
- txn/txnimpl
- proto
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
79 | 92 | | |
80 | 93 | | |
81 | 94 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
| 510 | + | |
510 | 511 | | |
511 | 512 | | |
512 | 513 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
167 | 172 | | |
168 | 173 | | |
169 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
853 | 853 | | |
854 | 854 | | |
855 | 855 | | |
856 | | - | |
857 | | - | |
858 | | - | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
875 | 877 | | |
876 | 878 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
184 | 186 | | |
185 | 187 | | |
186 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
| |||
0 commit comments