Skip to content

fix(objectio): isolate shared metadata load cancellation - #29779

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-29704-main
Oct 9, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-29704-main

Conversation

@ck89119

@ck89119 ck89119 commented Oct 9, 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:

Fixes #29704

What this PR does / why we need it:

Concurrent metadata reads share a dedupLoad result, but their cancellation ownership is independent. An empty subscription branch can finish normally and cancel the loader while another branch still needs the same object metadata. Previously, the live waiter inherited the loader's context canceled, causing the prepared JDBC metadata query to fail.

A controlled local replay of the prepared SQL reproduced this path: the loader's pipeline stopped normally, while the waiter received its error with a still-live context. The same replay succeeds with this fix. All temporary scheduling/cold-cache diagnostics have been removed.

Changes

  • Mark a completed load as abandoned only when every error leaf matches the loader's canceled context.
  • Let live waiters elect a replacement loader; canceled waiters return their own cancellation or deadline.
  • Recheck the cache inside the election critical section. Keep the latest generation reachable by already-admitted callers so a delayed waiter shares a fast takeover's result even when cache admission fails.
  • Remove terminal groups from the global table without invalidating existing waiters, and use identity-checked final cleanup so an old waiter cannot delete an independent new owner.
  • Preserve genuine storage errors, mixed error trees, unattributed cancellation, and panic/incomplete-load failures.
  • Each caller executes its own I/O closure at most once. No SQL retries, detached contexts, or cancellation-to-empty-success conversion.
  • Add deterministic coverage for cancellation ownership, repeated abandoned generations, concurrent takeover, and the real metadata/BloomFilter readers. Update the existing cleanup test without dropping its owner-error or map-cleanup assertions.

Validation

Local validation with Go 1.27.1 on Darwin arm64, using the repository CGo test wrapper:

  • pkg/objectio: full package tests, coverage, and full package race test passed.
  • Eight selected concurrency tests: each passed -race -count=100, including deterministic delayed-reelection cases (cached, rejected cache admission, takeover failure, and independent later owner).
  • pkg/vm/engine/readutil: full package tests passed.
  • Original publication_subscription/pub_sub4.sql on a local two-CN + Proxy cluster: 122/122 on two consecutive runs, no failed, ignored, or abnormal cases; teardown verified after each run. Preserves the prepared subscription/local/subscription 3 / 2 / 3 oracle.
  • gofmt, go vet, and incremental golangci-lint 2.14.0 passed.
  • Changed executable-line coverage: 58/59 (98.31%); changed coverage-block statements: 65/66 (98.48%). The review follow-up alone has 100% changed-code coverage.

The delayed-reelection regression tests failed against the initial patch and pass with the group-lifetime fix. After merging upstream main at 908166384d, reran the full objectio tests/coverage/race, focused race stress, readutil tests, static checks, service build, and two-CN + Proxy BVT listed above.

No generated files, SQL expectations, CI configuration, or diagnostic artifacts are 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 →

@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.

Reviewed commit 94449d9bd382269c29c0396daa7c5410494dafa5 against merge-base d7621ea017db4e43dbde9e5a855ba7b2ad920784. APPROVE — no blocking finding. All three changed files reviewed, including the complete test additions.

The fix belongs in the existing objectio metadata-result coordinator. Fileservice's IOMerger owns physical read/cache-fill notification; it does not supply this uncached decoded-result/error contract. The new group/current/users state has a concrete purpose: preserve the latest takeover result for already-admitted waiters while allowing independent callers after a terminal result. The owner executes its closure once, and re-election occurs only after an attributed cancellation. No SQL retry, detached context, duplicate cache or alternative execution path is introduced.

Checked cancellation/deadline ownership, mixed error trees, cache rejection/pressure skip, delayed waiters, repeated abandoned generations, independent later owners, and panic/incomplete loads. Channel close publishes result fields; the election mutex protects current/users and is not held across I/O. Terminal and last-user cleanup close group lifetime, including the old-waiter/new-owner boundary. ReadExtent retains its existing success/error read-result cleanup ownership. No new unbounded history or retry resource was found.

Validation:

  • Exact-head CI run is successful. The Proxy BVT log explicitly reports publication_subscription/pub_sub4.sql: 122/122, no failures/ignored/abnormal results, 7.071s. This includes the original prepared subscription/local/subscription rebinding query. Reused the author's recorded focused race stress, readutil/static checks and repeated same-instance BVT/teardown evidence.
  • Independent adjacent challenge: after the original owner's cancellation, the elected replacement either returns a storage failure or panics after another waiter joins. The peer must receive the terminal failure without another load; the group must disappear; the same key must load successfully again. Repeated the cycle on the same key. Reviewer probe passed -race -count=100; full objectio package also passed -race -count=1 (6.673s), with the repository CGo wrapper on Go 1.27.1/Darwin arm64.
  • Restoring the actual base implementation makes the changed cancellation regression fail with a live waiter receiving the owner's cancellation, confirming the discriminating control. git diff --check passed.

Performance is not zero-cost on misses. A reviewer microbenchmark with I/O removed and admission deliberately disabled isolates coordinator overhead: serial medians were 109→173ns (GOMAXPROCS=1) / 84→132ns (8); 8-worker disjoint-key throughput cost was 299→399ns/op. Allocation increased 176→192 B/op, 2→3 allocs/op. Three samples per mode; same inputs except the base/head cache.go implementation. The normal outer metadata/BloomFilter cache-hit path is unchanged. This bounded cold-path cost is justified by the correctness fix; these measurements do not establish TP throughput or latency impact.

Incremental quality: implementation +107/-22, tests +620/-4, docs 0. The tests exercise distinct error/generation boundaries and real metadata/BF readers with one object/row, deterministic admission barriers, exact results/read counts, and cleanup before restoring globals. Existing panic and cleanup assertions remain. No unused new state or unnecessary abstraction identified. There are no prior human review comments or inline threads to close; the only existing comment is the paused review bot.

@mergify mergify Bot added the queued label Oct 9, 2026
@mergify

mergify Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-09 13:04 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-09 13:08 UTC · at efd1c8952aeae14eb47530df9651a30a429b6e07

This pull request spent 3 minutes 32 seconds in the queue, with no time running CI.

Reason

Pull request #29779 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.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

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

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit d2a0055 into matrixorigin:main Oct 9, 2026
@mergify mergify Bot added dequeued and removed queued labels Oct 9, 2026
@ck89119
ck89119 deleted the issue-29704-main branch October 9, 2026 13:16
XuPeng-SH added a commit that referenced this pull request Nov 18, 2026
…agnostics (#32905)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to #32389. Backports the metadata cancellation fix from #29779.

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

When parallel readers share a metadata or Bloom filter load, a normal
pipeline stop can cancel the load owner. A waiter whose own context is
still live used to receive that owner's cancellation as its read result.
This can interrupt or underfill an IVF training sample.

The existing cache coordination now lets a live waiter take over after
the owner returns a cancellation attributable to its context. Each
caller can issue at most one load under its own context, with at most
one active owner per key. Real I/O errors, mixed errors, and the
waiter's own cancellation or deadline retain their semantics. Cache hits
bypass load coordination.

Scope cancellation that survives classification gets a structured event
before cleanup changes context state. It records the phase, original and
returned errors, observed context causes, and trace or transaction
correlation.

- Bare cancellation or deadline matching the reader's own context is a
bounded DEBUG event. Unattributed, mixed, and actual storage failures
remain visible at ERROR. A normal stop while building parallel readers
is DEBUG and still contributes to its existing counter.
- Typed terminal sends do not wait for channel capacity. Connector,
dispatch, and remote notification report an unqueued terminal as DEBUG
when the edge already holds a durable terminal state. A missing channel
or still-active edge remains WARN. Existing cleanup counters stay
intact, and cleanup logs share the existing strict time budget.
- An optional disk-cache write canceled by its caller is DEBUG and does
not inflate the disk-cache error rate. Real write or cleanup failures
remain WARN and count as errors.

The SQL results, terminal delivery and storage format stay the same.
Cache hit behavior is unchanged. The cold metadata path adds one small
group allocation and synchronizes admission and cleanup. A
single-threaded coordination-only microbenchmark measured 481 to 533
ns/op, excluding object I/O.

### Validation

- Full race runs for `pkg/objectio`, `pkg/sql/compile`, and
`pkg/vm/engine/readutil`. Retained cache ownership cases were also
stress-tested under race. Cleanup owners and consumers were covered by
the final race run.
- Scope and reader log checks distinguish matching cancellation from
failure while contexts are live. Disk-cache tests cover matching
cancellation, deadline, mixed errors, and a real cleanup failure racing
cancellation. Existing terminal delivery and event budget checks
continue to pass under race.
- Incremental gofmt, diff check, and golangci-lint passed. Any molint
findings in the selected packages also occur on the base revision.
- Earlier controlled SIFT1M runs demonstrated the shared-load defect and
validated the cache-only correction. The first cancellation source of
the historical TKE failures remains unconfirmed.
- On the delivery code, a local three-CN cluster built an IVF index
three times over 1M SIFT128 rows with `vector_ip_ops lists=500`,
returned 10 rows from the normalized vector query each time, and dropped
each index. The local launcher used an isolated proxy port. The INFO log
contained no reader cancellation errors, false terminal timeout
warnings, or disk-cache cancellation warnings during these builds.

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: prepared JDBC index metadata returns context canceled in multi-CN Proxy BVT

3 participants