Skip to content

Preserve borrowed vector snapshots and backing ownership - #31932

Closed
iamlinjunhong wants to merge 15 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/a5114d39a50a46e5609c163e9e774f48f5639dcec11e18df0e2bd331491a57ab
Closed

iamlinjunhong wants to merge 15 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/a5114d39a50a46e5609c163e9e774f48f5639dcec11e18df0e2bd331491a57ab

Conversation

@iamlinjunhong

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:

What this PR does / why we need it:

Borrowed vector backing could lose the owner of a replacement allocation during Shuffle, while Shrink could mutate data still visible to retained snapshots. This change preserves the allocation owner and uses copy-on-write when shrinking borrowed data. Retained views keep their own leases until the last consumer releases them.

Vector, batch and TAE shrink/compact operations prepare replacements before committing them, so a recoverable allocation failure leaves the original state intact. Callers propagate the new errors; these internal Go API signature changes require downstream source callers to migrate. Result bytes needed beyond a source batch's lifetime are retained or copied at their ownership boundaries.

Validation:

  • Regression tests cover borrowed and owned Shuffle, retained fixed and varlen snapshots, allocation rollback, wide batches and duplicate vectors. See vector tests, batch rollback tests, and wide-batch tests.
  • The delivered snapshot cancellation test passed at the final commit with -race -count=100; it checks actual connector reset and receiver cleanup after delivery and producer copy-on-write. Earlier real SQL termination tests and the component test provide layered evidence; native Sirius asynchronous cancellation was not directly exercised.
  • After integrating main, normal tests passed for hashmap, ISCP, external, fill, plan, function and util. Earlier normal owning-package tests and race tests for vector, batch, pSpool, TAE containers and aggexec remain applicable to unchanged code. CI is pending. Independent BVT and multi-CN tests were not run: this change targets local backing ownership and no distinct SQL output or wire-format change was identified.
  • On Darwin arm64 / Apple M4, Go 1.27.1, ten interleaved baseline/head pairs measured 1,024-row vectors with 512 selected rows. Borrowed varlen Shuffle had a 1.052 median head/base ratio; borrowed Shrink was 4.01x fixed and 3.84x varlen in an initial probe because it now copies data to preserve snapshots. The old borrowed paths did not provide equivalent correct ownership/snapshot semantics. Wide owned batch Shrink measured +20% to +121% across 8–8,192 columns; above 4,096 columns the temporary map allocated about 296–591 KB/op. Window entries added 32 B each. These microbenchmarks do not predict production latency or peak RSS; the sparse SQL RSS samples do not establish a peak or improvement. A maintained batch benchmark is included.

@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 added kind/bug Something isn't working kind/test-ci kind/api-change labels Oct 30, 2026
@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

做的不好,重新规划

This branch had an error being deployed

1 failed deployment
ci — a0ca407a Deployed Oct 30, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/api-change kind/bug Something isn't working kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants