refactor(disttae): redesign CN transaction workspace - #27013
Draft
gouhongshen wants to merge 5 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
Related to #26796.
The issue remains open as the benchmark record for transaction performance versus transaction size. This PR removes the positional workspace architecture that caused current-state operations to depend on accumulated transaction history; it does not claim to close every transaction-performance problem recorded in the issue.
What this PR does / why we need it
Problem
The CN transaction workspace used physical positions in a global write slice as statement boundaries, read visibility, rollback markers, and commit inputs. Readers and transaction operators depended on
txnOffset,snapshotWriteOffset,offsets, and direct access totxn.writes.That representation coupled logical transaction semantics to mutable slice layout. Statement retry, compaction, spilling, DDL rollback, CN transfer, and payload reclamation had to scan or rewrite shared positional state. As retired history grew, current-state operations could become proportional to the transaction's total history instead of the active working set.
Architecture
This PR replaces the positional model with explicit owners and opaque identities:
StatementJournalowns statement identity, retry attempts, rollback resources, RC boundaries, DDL operations, and LOAD-created files.TableOverlayowns each table's active mutations, PK candidates, row/block tombstones, uncommitted objects, and DDL visibility.PayloadStoreowns memory batches and spilled objects through generation-based leases. Readers pin payload generations instead of retaining unowned raw batch pointers.WorkspaceReadViewis an immutable logical visibility boundary.WorkspaceWriteMarkidentifies one write scope without exposing physical workspace positions.CommitBuilderfreezes logical mutations, pins referenced payloads, and builds the existing TN commit requests without mutating live workspace state.The workspace maintains ordered active indexes. Current-state reads, commit preparation, object-delete lookup, DDL lookup, and rollback use active indexes rather than scanning retired mutation history. Historical access is limited to an explicit statement-scoped read view.
Transaction semantics
The implementation preserves and tests:
capture/pin -> I/O -> validate/publish) so stale or rolled-back attempts cannot publish;CommitBuilder.Protocol-order correctness
Logical visibility order and TN precommit protocol order are separate concerns. This PR now models the latter with a
commitEpochadvanced by ordinary Compile read-view publication:This fixes the DDL/DML regression exposed by
delete_workspace.sqlwithout reintroducing physical workspace offsets.API changes
The internal engine workspace contract no longer exposes positional write offsets:
PublishReadViewandCurrentReadViewreplace snapshot/write offset accessors.BeginWriteAttemptandAdjust(WorkspaceWriteMark)replace positional adjustment.Ranges,CollectTombstones, and reader construction acceptWorkspaceReadViewinstead of transaction offsets.All in-repository callers and mocks are migrated. No compatibility wrapper or fallback positional implementation is retained.
Performance
Benchmarks cover retired histories of 0, 1,000, and 10,000 mutations. Current-state operations keep identical allocation counts and show no growth trend with retired history:
Validation
Passed locally on a clean MO instance at port 6002 (port 6001 was already owned by Docker and was not disturbed):
go test ./pkg/vm/engine/disttae -count=1make build127.0.0.1:6001to the test instance at127.0.0.1:6002git diff --checkThe ownership, visibility, lock-order, payload-lifecycle, spill, rollback, and commit contracts are documented in
docs/design/cn-transaction-workspace.md.