Skip to content

refactor(tae): replace containers.Batch with batch.BatchWithDeletes (#33337) - #33541

Merged
fengttt merged 13 commits into
matrixorigin:mainfrom
fengttt:batch-with-attr
Nov 30, 2026
Merged

fengttt merged 13 commits into
matrixorigin:mainfrom
fengttt:batch-with-attr

Conversation

@fengttt

@fengttt fengttt commented Nov 30, 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:

issue #33337

What this PR does / why we need it:

  • batch.BatchWithDeletes embeds Batch and adds a delete bitmap. It replaces TAE's Batch and BatchWithVersion. batch.Batch is unchanged.
  • A batch has no column names. Attrs, Nameidx and Seqnums are gone; names and seqnums come from the schema. Fixed layouts (checkpoint, snapshot, tombstone, object metadata) are read by position, scans by the position in colIdxes.
  • The WAL codec is BatchWithDeletes.WriteWAL and batch.ReadWAL, which take and return the names. Replay maps them once to the object's schema, because a record may come from an older one. The unreachable V1 and V2 codecs are removed: only append command version 3 has been registered since remove stale compatibility code #21883.
  • AppendCmd.ReadFrom still ignores the error of reading its batch, as before; a comment now says why that is dangerous.
  • The logtail builders return the names next to the batch and walk the columns in seqnum order. They used to sort the batch, which reordered a live transaction node in place.
  • BatchSplitter is a loop over CloneWindow.
  • VectorPool moves to pkg/container/vector, so Close can return lent vectors. containers keeps thin wrappers.
  • Delete, RangeDelete and CloneWindow take the mpool they allocate from.

For reviewers:

  • Stricter check: AppendDataToTable rejects a CN write whose columns are not the first columns of the table, in order. Such a write used to be copied by schema position whatever its names said.
  • TAE code appends to vectors directly, so the row count is the vectors' length. RowCount is overridden; the count stored in the embedded Batch is not maintained.

Compatibility

  • The WAL bytes are unchanged: TestWriteWALGolden pins them to a hash computed with the old containers.Batch.WriteTo.
  • Crash recovery gives the same query results when the old binary's WAL is replayed by the new one, new by new, and new by old. The data had inserts, updates, deletes, ALTER (add, drop and rename column), accounts and a snapshot.
  • Logtail entries carry the same names as before.

Testing

  • Unit tests of 95 packages, including pkg/container, pkg/objectio, pkg/vm/engine, pkg/publication, pkg/backup and pkg/datasync.
  • Race detector on container/batch, TAE containers, logtail, txnimpl, tables, catalog, and publication.
  • BVT on a single node, no failures: ddl, dml, table, fake_pk, auto_increment, vector, publication_subscription. snapshot and pessimistic_transaction were stopped by a time limit, with no failures in the files that ran.
  • make static-check-changed (full graph): 0 issues.
  • After merging main and moving the codec: unit tests of pkg/container, pkg/objectio, pkg/vm/engine, pkg/publication and pkg/backup, the static check, and crash recovery old to new and new to new. BVT and the race detector were not repeated.
  • Not run: sysbench, TPC-H, multi-CN. The batch microbenchmarks were not repeated after the names were removed.

🤖 Generated with Claude Code

fengttt and others added 5 commits November 30, 2026 10:01
Column loaders fill a *batch.Batch and set its row count; read-filter
searches take []*vector.Vector. containers.Vectors is removed, and objectio
no longer imports the TAE containers package for it.

Batch.InitVectors allocates up to 8 vectors and their pointers at once, and
the Batch stays on the caller's stack. The reader creates its scratch vectors
on the first load, sized to the block: scans that copy straight to the output
never allocate them. LoadColumnsDataFromMeta's release no longer moves the
IOVector to the heap. The checkpoint readers no longer copy vector headers
that share ownership of their buffers.

VectorsCopyToBatch becomes CopyBatch; its test now checks the appends.

In containers, VectorPool picks an element with math/rand/v2 instead of a
linkname to runtime.cheaprand (about 3 ns per GetVector), and both runtime*.go
files are removed; runtime.go was never built.

Add benchmarks for tombstone reads, a reader's life, and the vector pool.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
containers/mock.go holds test data generators but was part of the production
package. Move it, with its test, to tae/testutils. catalog.MockBatch, a wrapper
over it in a non-test file, becomes testutils.MockSchemaBatch, so no production
package imports testutils. It takes an interface: testutils cannot import the
catalog without import cycles.

MockNullableBatch, only the body of MockBatch, is merged into it. The
containers tests that use the mocks become package containers_test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The same switches moved from tae/containers/mock.go to tae/testutils/mock.go;
no entry is added.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rixorigin#33337)

batch.BatchWithAttr is a Batch with column names, optional column seqnums and
a delete bitmap. It replaces TAE's Batch and BatchWithVersion; batch.Batch is
unchanged. BatchSplitter becomes a loop over CloneWindow.

Names are found by scanning Attrs up to 8 columns and through a private index
above that, checked against Attrs on each lookup, so removing or reordering
columns cannot make a name find another column, as the old Nameidx could.

Logtail collection walks the columns in seqnum order instead of sorting the
batch, which reordered a live transaction node's columns in place.

VectorPool moves to pkg/container/vector, so that Close can return lent
vectors. Delete, RangeDelete and CloneWindow take the pool they allocate from.

The WAL codec becomes functions (WriteBatch, ReadBatch) with the same bytes; a
golden test pins them to a hash computed with the old code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 30, 2026 •

Copy link
Copy Markdown
Contributor

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

The type-switch baseline may only shrink: tag MockVector and MockVector2,
whose default handles the remaining types, and drop their baseline entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: c1c68720cb57f8ea219be4fc6c6914c604a8f81b

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: c1c68720cb57f8ea219be4fc6c6914c604a8f81b

Assessment: approve

The refactor consolidates TAE batch and vector-pool ownership into the shared container packages while retaining the TAE metadata and WAL encoding contracts. No actionable defects were found.

Model: gpt-6.1-terra / max

Session: 01a22b07-00b6-7e32-b0a1-3099d0b867c7 · slot 1 · generation 39

Validation:

  • Isolation preflight passed. Full batch, vector, types and TAE container tests passed, including the old-writer WAL golden hash and V2 compatibility tests: checks/1796065598097356761-3.json.

  • Full object I/O, block I/O, reader and logtail package tests passed: checks/1796065943493981330-3.json.

  • Targeted checkpoint compatibility, delete replay, schema padding, rollback and materialization tests passed: checks/1796066475517299565-3.json.

  • Batch, vector and TAE container package tests passed under the race detector: checks/1796066618542240642-3.json.

  • A two-CN SQL probe passed across schema evolution, committed and rolled-back writes, flushing and same-binary restart: checks/1796067023412549070-3.json.

  • Focused backup restore, publication filtering and merge tests passed: checks/1796067191764707896-3.json.

Limitations:

  • The checkpoint compatibility fixture uses the current binary to construct a legacy-format checkpoint; no released predecessor binary was run.

  • The author's performance measurements were not independently reproduced.

@fengttt
fengttt marked this pull request as draft November 30, 2026 20:15
…#33337)

AppendCmd.ReadFrom ignores the error of reading its batch again, and ReadWAL
returns the part it could read. The comment says why that is dangerous.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 30, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

21 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Mon 30 Nov, 22:12 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 22:33 · 1e74629

Reason

Pull request #33541 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 1e74629b0ebb81619dbb156dcd468db2d065465c

"interrupted"

@fengttt
fengttt merged commit af2c49a into matrixorigin:main Nov 30, 2026
50 of 59 checks passed
@mergify mergify Bot added dequeued and removed queued labels Nov 30, 2026
fengttt added a commit to fengttt/matrixone that referenced this pull request Nov 30, 2026
Its squash (af2c49a) has the same tree as 1e74629, which this branch is
stacked on, so this branch's tree is the merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fengttt added a commit that referenced this pull request Dec 1, 2026
## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [x] Code Refactoring

## Which issue(s) this PR fixes:

issue #33337

## What this PR does / why we need it:

This follows #33541. Together its commits remove the `tae/containers`
package.

| Was | Now |
|---|---|
| `containers.MakeVector(t, mp)` | `vector.NewVec(t, mp)` |
| `containers.BuildBatch(types, opts)` |
`batch.NewBatchWithDeletesTypes(types, mp)` |
| `containers.BuildBatchWithPool(...)` |
`batch.NewBatchWithDeletesFromPool(types, rows, pool)` |
| `containers.Options` | removed; `Capacity` was never set |
| `containers.BatchFreeList` | `batch.FreeList` |
| `containers.OneSchemaBatchBuffer` |
`batch.NewFreeListWithLimit(maxBytes)` |
| `containers.IBatchBuffer` | removed; the sinker holds a
`*batch.FreeList` |
| sinker buffer statistics | removed; they never updated |
| `containers.Vector`, `VectorPool`, `ReleaseVector`, ... | the
`pkg/container/vector` originals they forwarded to |
| `GeneralBatchBuffer`, `Usage()`, `offHeap`, `WithOffHeap` | removed:
used only by tests, or stored and never read |
| `ToCNBatch(b)`, `ToTNBatch(b)` | `b.AsBatch()`,
`batch.NewBatchWithDeletesOf(b)` |
| `DedupSortedBatches`, `CopyBatch` | `batch.DedupSorted`,
`Batch.CopyFrom` |
| `UpdateValue` | `vector.UpdateAny`, or `vector.UpdateFixedAt` without
boxing |
| `MarkNull`, `CloneVector` | `Vector.TrySetNull`, `VectorPool.Clone` |
| `ForeachWindowBytes` | `vector.ForeachRaw` |
| `ForeachVector`, `ForeachVectorWindow`, `ForeachWindowFixed`,
`ForeachWindowVarlen`, `MakeForeachVectorOp` | typed
`vector.ForeachFixed` and `ForeachBytes`; two type switches go |
| `getNonNullValue` | removed; only tests used it |

For reviewers:

- **Key types.** Persisted dedup (`tables/functions.go`) now takes its
typed probe from its own table. `MakeForeachVectorOp` had no BIT or YEAR
case and panicked on those keys, as far as the code shows; they work
now, and `TestPersistedDedupKeyTypes` covers every key type in the
tables. A type without a dedup function is an error, not a panic.
- **Duplicate code.** The fixed-size and varlena appendable-block probes
share one `aBlkMatches.visit`.
- **Errors instead of panics.** `UpdateAny`, `UpdateFixedAt` and
`TrySetNull` return errors, and callers pass them on. `TrySetNull`
refuses a read-only vector; `MarkNull` did not check.
- **Constant vectors.** `ForeachRaw` handles constant fixed-size vectors
(the old code sliced past their one value), and `ForeachBytes` applies a
selection to a constant, which was ignored. A nil or empty selection
still means every row.
- **DedupSorted.** An empty key after an empty first batch is no longer
taken for a duplicate.

- A nil pool used to mean TAE's default pool. `vector.NewVec` with a nil
pool makes a read-only vector, so a nil now fails on the first append.
Literal nils were only in tests, which now name the pool.
- `NewBatchWithDeletesFromPool` returns an allocation failure as an
error and gives back the vectors it borrowed; `BuildBatchWithPool`
panicked. A transaction append now fails with the error.
`MakeBufferBatch` has no error result and still panics.
- `FreeList` reuses a kept batch only if its column type OIDs match the
requested types, and then gives it those types; before, it ignored them.
- `FreeList` has no mutex; `OneSchemaBatchBuffer` had one. Its users, GC
and `TransferFlow`, run sequentially and do not enable the sinker's
pipeline mode.
- The limit works as before: a batch that would take the list over it is
freed. GC and transfer limits are unchanged.
- The sinker has two unexported hooks, nil outside tests, where tests
that faked the interface inject failures. In `multi_update` those tests
now observe deletes and memory instead; I checked that each fails when
the ownership code is broken.
- `UpdateAny` and `UpdateFixedAt` reject a row out of range.
- **Flaky test, not from this change.**
`TestIssue25590TwoDirtyObjectCompactionIsAtomicAcrossReplacements` and
`...RecordFailureAfterStagedReplacementRetracts` read the ledger while
the GC pool may still be deleting the rewritten originals. `main` fails
too (20 of 390 stress processes). The fixed count was wrong for a worker
that may be anywhere, so they now run with the worker about to delete,
deleted but not settled, finished, and racing. Each order checks
ownership, the recorded copy, GC claims and files on storage, which
replaces the count. Settling before deleting, dropping the recorded copy
first, losing the GC claim, and not deleting each fail it. 0 of 240
stress processes fail, and `-race` is clean.
- **Fix: `TransferFlow.Process`.** It deferred the put-back inside its
read loop, so each batch read took a new buffer, all held until the end.
It now reads into one buffer, put back before the final transfer and
sync. `TestTransferFlowReusesReadBuffer` counts 51 buffers for 50
batches with the old loop, 1 now.

## Testing

- Unit tests on the final code: `pkg/container`, `pkg/objectio`,
`pkg/vm/engine/tae`, `disttae`, `engine/test`, `pkg/publication`,
`pkg/backup`, `pkg/datasync`, `pkg/vectorindex/ivfflat`, `pkg/tools`,
`pkg/iscp`, and `pkg/sql/colexec` with `multi_update`. New tests for the
moved functions.
- Sinker write, spill and sync benchmark, 8 interleaved runs, up to the
`FreeList` commit vs. the first commit: median 7.12 ms vs 7.22 ms; 593
allocs/op both.
- Last commit vs. the one before: index building unchanged; persisted
dedup level or faster with fewer allocations (1,038 to 13 per op at
1,024 probes), except a one-row block, about 80 ns more per block (180
to 259 ns). Sinker +2.4%, equal allocations, within its noise.
- `-race` on the last commit: `container/batch`, `tae/tables`,
`tae/index`, `tae/txn`, `tae/blockio`, `objectio/ioutil`. Before it:
`container/batch`, `objectio/ioutil`, `readutil`, `tae/db/gc`,
`multi_update`, and the transfer, tombstone, GC and sinker tests of
`disttae` and `engine/test`.
- Transfer fix: all of `disttae` and `engine/test`; `-race` on their
transfer and tombstone tests.
- `make static-check-changed` (full graph): 0 issues.
- Not run locally: BVT.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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

dequeued kind/enhancement kind/refactor Code refactor size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants