Repository navigation
perf(disttae): bound in-transaction point-read cost by the probed key - #30685
Conversation
In one long transaction, every statement's transaction-local read ran MemPKFilter.FilterVector over every workspace insert batch, re-encoding all accumulated rows per read even when the batch could not contain the probed key. Statement-boundary merging packs shuffled keys into fat batches whose min/max envelopes defeat range-only pruning, so the cost of a single-row pk UPDATE statement grows with the in-transaction modification count. Measured at the base: 3.628x late/early latency growth over a 30k-statement single-transaction workload, FilterVector at 31.06 percent cumulative in the CPU profile. Add an encoded-primary-key envelope per insert batch (written once, kept through the lifecycle) plus a lazily hydrated, budget-charged exact-key index per batch. A transaction-local point read can then skip whole batches by envelope or resolve them through the exact index instead of re-encoding the full batch. Predicates outside the gate (non-EQUAL preds, serial or composite keys, membership filters, disjunctions, prefix ops) keep the unpruned path, fail-closed. Ownership and lifecycle invariants enforced and tested by this change: - each hydrated index charges the workspace budget exactly once and is refunded exactly once on every terminal path (commit finalization, rollback, merge destination and source, shrink, release, dump-drop, ALTER transfer), centralized in unaccountInsertKeyOffsetsLocked - the ALTER writes-transfer duplicate re-hydrates under its own ownership and never clones a charged map - forward compactions clear the vacated backing-array slots through the original full-length slice so retired batches and refunded maps stay unreachable; clearing through the commit dumpAll compaction's prefix-shortened append target used to panic out-of-range when a DROP/TRUNCATE hole was retained below the merge gate - spill sizing (scanInMemInsertSize, the dump gate and per-table selection) counts batch plus index bytes so the spill decision sees what the budget charges - zero-row entries fail closed instead of hydrating an empty charged index Verified by 13 focused unit tests (RED-first: bounded point-read work, statement-boundary cadence, envelope contracts, exact-probe gating, index lifecycle and memory accounting, teardown under enforced debug accounting, ALTER ownership, merge and dumpAll vacated-slot clearing, spill sizing with hydrated charge, fail-closed zero-row hydration), a 328-statement BVT case replayed at 100 percent, and a live 10k single-transaction point-update benchmark that stays flat with the reader path absent from the profile. Related to matrixorigin#26796.
|
Unrelated CI / merge-infrastructure blockers currently observed on this PR, each tracked by an existing issue:
|
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Addressed the design-gate finding from review 5593891733 (mo-bot-xupeng, request_changes at Verification before action. Checked the finding against the actual diff: the change does introduce Action (commit Per the contract, implementation approval remains blocked until this design revision is reviewed in this thread; requesting that review here. |
aptend
left a comment
There was a problem hiding this comment.
Independent deep review of exact head 3a758d8ffd88e416b3a0e220d75fd94a25babdf1, base/merge-base 20f7f8dd2e0d514a1ed4105a301ae3cec5136338. Read all history/discussion (no inline threads), the linked issue, every current changed hunk and affected lifecycle callers.
Distinct design-first decision: ACCEPT rev1 docs/design/20261021-disttae-workspace-point-read-bounding.md at this exact head. The new artifact closes the earlier missing-design concern; this is a traceable review decision, not a request for a status badge. The two-tier design, per-layout invalidation, single refund owner and integration with existing spill sizing are coherent. Write-side encoding, two uncharged envelope-key clones per entry and approximate retained-index accounting remain explicit tradeoffs; no global O(1) lookup or free-write claim.
Implementation closure: canonical range pruning remains conservative; exact probes require equality, matching column and no independent membership filter. Unknown/unmodeled cases keep the original filter path; the common tombstone/output tail remains. Traced index creation through merge/shrink/release, ALTER duplication, dump/compaction, statement rollback and commit/transaction teardown. No stale layout or shared-charge owner found. Vacated tail slots clear references, and spill gate/quota/table selection include the same index charges. Q1/Q2/Q3: one live owner/refund, existing workspace mutex with no new asynchronous waits, transaction-local bounded state tied to existing spill containment. No blocking finding.
Verified evidence reuse: f4fd8cfc4eff6d682ff13b7eeace96fbe4944a59..HEAD changes only the design document, so implementation/test/native inputs are identical. Reconciled raw logs and downloaded artifacts from successful CI run 39520372413:
- Ubuntu UT job
118962565013: checkpoint explicitly selects complete disttae and readutil owning packages under-short -tags matrixone_test -race, with terminal light-stage exit0; all 13 new roots are in the unfiltered selection and have no short skips. - Normal coverage producer
118962609967: terminal exit0, 82679 pass events and no failed package/test events. This is CI-mode normal-suite evidence, not a separately computed changed-line coverage percentage. - SCA
118962565049: repository vet/molint and golangci2.14.0 completed successfully. - Compose/Proxy BVT
118965296885: the new case actually executed 328/328 assertions, zero failure/ignore/abnormal; suite terminal success. Positive seed, repeated updated-row/unique-key lookup, postcommit data and rollback assertions are present. git diff --check: PASS.
No new local test/benchmark or mixed-topology measurement claimed; local native preflight executed no tests, and the equivalent green CI evidence was reused. No source changes or review probes were added. Approval is for the documented optimization and lifecycle contract, not independent verification of the author's live benchmark numbers.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-xupeng · review
Commit: 3a758d8ffd88e416b3a0e220d75fd94a25babdf1
Assessment: approve
Reviewed the complete 12-file delta, linked issue, frozen comments, design and affected callers. The design-gate concern is closed. Filtering, index ownership, invalidation, accounting and spill integration are coherent; no actionable defects remain.
Model: gpt-6-astra / xhigh
Session: 01a15209-2c6d-71e2-b8f3-aa17387fa283 · slot 2 · generation 0
Validation:
-
Verified clean source, assigned HEAD/merge-base, supplied patch consistency and git diff --check.
-
Traced cache lifecycle through hydration, merge/shrink, ALTER transfer, spill, compaction, statement rollback and transaction teardown. Reviewed all 13 new test roots and SQL/result oracles.
-
Independently reconciled CI run 39520372413 at f4fd8cf. Only the design document differs from the assessed HEAD; implementation, tests and build inputs are identical.
-
Race checkpoint selects complete disttae/readutil packages with -short -tags matrixone_test -race and no test-name filter; terminal status is 0. Normal coverage producer reports exit 0 and no failed package/test events. Vet/molint and golangci-lint completed successfully.
-
Compose/Proxy BVT logs confirm the new SQL case executed all 328 statements successfully, with zero failures, ignored or abnormal results and terminal suite success.
-
Retained evidence and hashes in attempt-1/review-evidence.json and analysis in review-notes.json. Audit receipt checks/1792553494509118563-4.json matches the command, clean source fingerprint, exit 0 and review-audit.stdout.log/review-audit.stderr.log.
Limitations:
-
No local Go tests, native builds, BVT or benchmarks were repeated; equivalent CI execution was reused. Individual race-test event records were unavailable, so verification used package selection, source skip checks and terminal status.
-
Author latency figures, ordinary-write overhead and peak heap usage were not independently measured. Write-time encoding, two uncharged envelope keys per entry and approximate index accounting are explicit accepted design costs.
-
This optimization bounds repeated encoding within batch layouts; entry scanning and fallback filtering remain. Approval does not assert global constant-time reads or resolution of every workload in issue #26796.
Merge Queue Status
This pull request spent 3 hours 40 minutes 46 seconds in the queue, including 1 hour 5 minutes 17 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
Related to #26796
Design review gate (required before implementation approval)
Review 5593891733
classified this change as design-mandatory under the repository's
feature-design-review contract:
the change introduces a transaction-lifetime exact-key index (a stateful
cache with hydration, invalidation and charge/refund lifecycle) on the
workspace read hot path, and the 647 changed non-generated production
lines also exceed the 500-line default size trigger.
docs/design/20261021-disttae-workspace-point-read-bounding.md,
added in commit
3a758d8ffd88e416b3a0e220d75fd94a25babdf1. It records the gate record, the invariant set,ownership and lifecycle, memory bounds and accounting, the hot-path cost
model including ordinary workloads, alternatives, compatibility, the
validation mapping, and an approval record for this design review.
the contract. Design review is requested on this PR.
What this PR does / why we need it:
Problem
Inside one long transaction, every statement's transaction-local read
(
filterInMemUnCommittedInserts) ranMemPKFilter.FilterVectoroverevery workspace insert batch, re-encoding all accumulated rows per
read — even when the batch's primary-key column could not possibly
contain the probed key. Because statement-boundary merging packs
shuffled keys into large fat batches, the batch-level min/max envelope
defeats range-only pruning, so the per-statement cost grows with the
in-transaction modification count (quadratic in total over the
transaction). Measured at base
eb18dbfa03with the workload recordedin the issue: 1,000-statement window medians grow 3.628x late/early
over a 30k single-transaction point-update run, and
MemPKFilter.FilterVectoroccupies 31.06% cumulative CPU in amid-transaction profile.
Change
pkg/vm/engine/readutil/pk_filter_mem.go,pkg/vm/engine/readutil/filter_util.go: keep an encoded-primary-keyenvelope per insert batch (written once at write time, kept through
its lifecycle); add a lazily hydrated, budget-charged exact-key
index per batch. The read gate now applies only to single-column
EQUAL primary-key probes on a batch without attached membership
filters; anything else (composite/serial keys, non-EQUAL
predicates, disjunctions, prefix ops, membership filters) keeps the
original unpruned path, fail-closed.
pkg/vm/engine/disttae/local_disttae_datasource.go: probeworkspace insert batches through the envelope skip and the exact
index before falling back to the full-vector filter.
pkg/vm/engine/disttae/txn.go,txn.go,txn_table.go,types.go: make the index's ownership and lifecycle sound —unaccountInsertKeyOffsetsLockedcentralizes refund + map drop,used by every terminal path (commit finalization, rollback, merge
destination and source, shrink, release, dump-drop, ALTER
transfer), so a hydrated index is charged exactly once and
refunded exactly once;
transferWorkspaceWritesForAlterLockedmoves the ALTERwrites-transfer loop and resets the duplicate's key index
ownership so it re-hydrates under its own charge;
clearVacatedWriteSlotsclears retired entries from the vacatedbacking-array tail at all four compaction sites; the commit-time
dumpAll compaction now clears through the original full-length
slice (the previously used prefix-shortened append target panicked
index out of rangewhen a DROP/TRUNCATE hole was retained belowthe merge gate);
inMemEntryDataSizecounts batch + index bytes forscanInMemInsertSizeanddumpInsertTableSelectionLocked, so thedump gate, quota arithmetic, and per-table selection see the same
bytes the budget charges;
charged index.
test/distributed/cases/disttae/disttae_filters/issue_26796_long_txn_point_updatesBVT case.
Issue-to-test proof
TestIssue26796PointReadWorkStaysBounded,TestIssue26796WorkspaceMaintenanceWorkBounded(base: 64 / 512 / 400 rows encoded vs bound 8)TestIssue26796WorkspaceMergingBoundsEntryCount(base: fails at first statement)TestIssue26796PruningKeepsReadSemantics,TestIssue26796MembershipFilterGatesExactProbePath,TestIssue26796EnvelopeWrittenOnceAndKeptByLifecycleTestIssue26796KeyIndexLifecycle,TestIssue26796KeyIndexMemoryAccounting,TestIssue26796TeardownClearsKeyIndexesWithDebugAccounting(RED: debug-accounting panic at commit/rollback)TestIssue26796AlterTransferResetsKeyIndexOwnership(RED: workspace accounting mismatch 604 per 888)TestIssue26796WorkspaceCompactionClearsRetiredIndexSlots(RED: vacated slot 29 holds retired batch)TestIssue26796DumpAllClearsVacatedSlotsThroughFullSlice(RED:index out of range [1] with length 1)TestIssue26796SpillSizingSeesHydratedKeyIndexBytes(RED: batch-only numbers 0x14e vs 0xa0)Test commands and outcomes
GOEXPERIMENT=simd CGO_CFLAGS="-I$ROOT/cgo -I$ROOT/thirdparties/install/include" go test -run 'Issue26796' -v -count=1 ./pkg/vm/engine/disttae→ 13/13 PASS, exit 0; packagesuites
disttae,disttae/cache,disttae/logtailreplay,disttae/route,disttae/sidecar,readutilallok;gofmtand
go vetclean.TOTAL 328, SUCCESS 328, FAILED 0, rate 100%, verdict
this test succeed.single-row pk UPDATEs in one transaction over a 10,000-row table
with two unique keys — window medians 0.81–1.70ms with no growth
trend (late/early ratios 1.040 / 1.111 across recorded runs), COMMIT
0.13–0.20s, exact post-commit validation
(count/distinct/sum/bad = 10000/10000/10000/10000/0); 30s
mid-transaction CPU profile:
FilterVectorandMemPKFilterabsentfrom the cumulative report vs 31.06% at base.
Residual risks
FilterVectorpath for correctness.the threshold may spill slightly earlier (intended consequence of
honest accounting; exercised live with identical validation and
commit latency).
and may textually conflict on Entry fields, the read gate, and the
compaction/transfer helpers.