Repository navigation
fix: stabilize lockservice RPC lifecycle under CI load - #26473
Merged
XuPeng-SH merged 7 commits intoJul 31, 2026
Merged
Conversation
Distinguish MORPC create-queue delay from backend creation time, harden lockservice bind-change and shutdown paths, and make the affected CI regressions deterministic.
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? |
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
iamlinjunhong
self-requested a review
July 31, 2026 06:12
This was referenced Jul 31, 2026
2 of 7 tasks
XuPeng-SH
added a commit
that referenced
this pull request
Aug 1, 2026
## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes #26547 Related: #26475 Nightly regression: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/30649446904/job/91275888648 ## What this PR does / why we need it: The failing 1000-thread sysbench run returned 100 lock RPC errors as backend-closed (20502). Incident metrics show the same 88/12 split across two clients in both MORPC auto-create timeouts and lockservice backend-closed errors, with no create-queue full/drop, circuit-breaker trip, pod restart, or OOM. The connection factory was delayed while the CNs were CPU saturated, so the lockservice-wide 500ms backend-create deadline expired for all callers coalesced on those two cold connections. The direct mechanism is not unique to #26473: the 500ms lockservice setting came from #23435, and a genuinely blocked factory reproduces the 100/100 failure on both the pre-#26473 baseline and the incident MORPC code. #26473 makes completion-at-the-deadline classification deterministic, which can affect the boundary, but a real factory delay beyond 500ms does not require that change. This PR: - keeps the independent 5s local create-queue admission bound on every lockservice transport; - limits the 500ms peer-health deadline to active-transaction recovery and service-validation transports, where fast failure is required; - lets normal Lock/Unlock, keeper, and control traffic follow their already-bounded caller contexts and the backend's 5s connect timeout; - preserves the independent liveness probe in recovery client configs; - classifies backend-create timeout separately from generic backend-closed in MORPC and lockservice metrics; - adds a low-cardinality distinct-create-event counter alongside the existing per-request impact counter; - emits at most one warning per create state and rate-limits the static event to one log per client per minute; - updates the RPC Grafana panel to compare affected requests with distinct create events. Deep-review hardening: - the timeout logger retains only one keyed limiter state, bounding future accidental dynamic-key growth; - failure-only diagnostic fields are placed after the pre-existing hot client state, preserving mutex/pool field offsets used by every Send; - normal traffic is tested for prompt caller cancellation while factory creation remains blocked; - wrapped create-timeout errors retain their dedicated metric classification. The regression tests construct a successful but delayed backend factory. They verify 100 coalesced callers all reproduce 20502 at 500ms, while producing 100 impact counts, one event count, one retained limiter key, and one warning. The lockservice policy test verifies normal traffic succeeds after waiting beyond 500ms, remains caller-cancellable, and recovery traffic still fails fast. Verification after rebasing onto latest main: - focused fan-out race: T=0.5s, B=30s, N=60 - focused lockservice role/cancellation race: T=1.11s, B=30s, N=27 - admission-boundary, nil-state timeout, and error-classification race: N=100 each - full `./pkg/common/morpc` race: passed - full `./pkg/lockservice` race: passed - full non-race MORPC, lockservice, and metric-v2 tests: passed - build and vet for all four modified packages: passed - hot-path benchmark, clean main vs PR: both 144 B/op and 1 alloc/op; PR 207-212 ns/op vs main 210-211 ns/op - dashboard compile-only test: passed; its live-Grafana tests require `127.0.0.1:80` and fail identically on clean HEAD when Grafana is absent
4 of 7 tasks
XuPeng-SH
added a commit
that referenced
this pull request
Aug 10, 2026
…#26914) ## What type of PR is this? - [x] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes #26474 ## What this PR does / why we need it: This closes the two lifecycle gaps deliberately left after #26473. ### Contextual backend creation - Adds the backward-compatible `ContextBackendFactory` capability. Existing `BackendFactory` implementations continue to work; clients prefer contextual creation when supported. - Binds every asynchronous create state to its exact client generation and GC-manager incarnation. Client close, targeted/full reset, queue invalidation, and manager replacement cancel that state. - Makes the Goetty factory contextual without allowing cancellation to bypass the process-wide concurrency bound: shared workers and lower-level legacy Connect attempts are both capped at four. A cancelled late result retains ownership and is closed before it can escape. - Keeps local lifecycle cancellation out of `factoryErr`, error logs, and peer-breaker evidence. A factory timeout while the generation remains live is still preserved as definitive failure evidence. ### Unknown-commit callbacks - Defines completion callbacks as prompt, non-blocking external code that may re-enter `Close`. - Reserves callback capacity when ownership transfers and caps accepted-but-not-returned callbacks at 1024. There is no unbounded callback queue or detached-goroutine fan-out. - Saturation returns an error before callback ownership transfers, while lock-cleanup ownership is still scheduled so locks are not stranded. - Service shutdown seals callback admission, joins the resolver, drains pending callback reservations by transferring invocation out of service ownership, and only then releases the RPC transport. `Close` never waits on a callback body that may itself call `Close`. - Rolls back callback ownership if resolver task startup fails, preventing double admission release on the caller error path. ### Validation Based on `origin/main@fa0ea95`. - `go vet -mod=readonly ./pkg/common/morpc ./pkg/lockservice` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/common/morpc ./pkg/lockservice` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=15m ./pkg/common/morpc ./pkg/lockservice` - Each of the 10 new lifecycle regressions measured individually under race (`T=0s..0.06s`, stress budget `B=30s`, adaptive `N=100`) and then passed separately with exact `-run`, `-race`, and `-count=100`. The local Darwin linker emitted only the pre-existing missing `/opt/homebrew/opt/libpqxx/lib/` search-path warning; every command exited successfully.
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…26473) ## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#26467 ## What this PR does / why we need it: The failures grouped in matrixorigin#26467 are not one lock-conflict race and are not test-only. A loaded CI host exposes four production contract violations: 1. **Local scheduling was treated as peer failure.** MORPC charged time spent waiting for a process-wide create worker to the backend factory timeout and could poison a healthy peer's breaker. 2. **Endpoint observations were treated as service identity.** A stale endpoint could return one negative validation result and disable a newer/live lockservice bind. 3. **Cleanup ownership was implicit.** Backend, table, callback, and response cleanup could block while holding publication locks, race with replacement generations, or be performed twice. 4. **Shutdown was not a protocol.** Close paths did not consistently seal admission, cancel admitted work, join it, drain queues, and then release resources. Under adverse timing this caused late sends, long waits, leaks, or deadlocks. ### Production-code fixes #### MORPC scheduling, failure evidence, and lifecycle - Separate the local backend-create queue budget from the peer factory budget. Queue-full/queue-timeout are local transient errors and do not update the peer breaker. - Replace synchronous queue-full fallback with a fixed four-worker process-wide factory pool, bounding concurrent DNS/dial work under overload. - Track exact create state and generation through queued -> started -> completed, share one factory budget across retries, and reject late results from invalidated generations. - Preserve definitive `BackendCannotConnect` evidence while keeping timeout/closed/local-congestion failures transient. - Pin a manager generation to each client, support safe manager replacement/reconfiguration, use one metrics ticker, and gate workers again after dequeue so shutdown cannot start new factory work. - Make `CloseBackend` invalidate and detach under the client mutex, then physically close outside it. Replacement publication is no longer blocked by a slow backend close, while client close still joins the detached cleanup exactly once. #### Lockservice recovery and shutdown - Isolate normal, control, active-transaction, validation, and keeper traffic so transaction saturation cannot starve recovery/control paths. - Require two independent negative validation observations: reset the validation backend and refresh authoritative discovery before disabling a bind. Missing reset capability fails closed instead of accepting one stale negative. - Commit negative validation only if the bind-set identity and keepalive generation still match the snapshot, so stale validation cannot overwrite newer positive evidence. - Add idempotent/sticky close ownership and best-effort `errors.Join` cleanup for clients, server, allocator, and service resources. - Implement service/server admission gates: seal new work, cancel admitted work, wait for callbacks/operations, drain queued responses, then close owned tables and transports. - Propagate service cancellation through remote/forward lock work and transfer async callback finalization with an explicit atomic ownership state. - Run unknown-commit callbacks outside resolver tasks so a re-entrant `Close` cannot wait on its own stopper task. - Detach lock tables and waiter/store edges under locks, publish the new holder version, and perform potentially blocking close/notification outside locks. This removes holder/table -> bounded event queue -> worker -> holder/table cycles. ### Test-only changes - Add deterministic, channel-synchronized regression tests for queue admission, create-generation invalidation, manager stop/reconfiguration, close ownership, callback re-entry, service cancellation, stale validation evidence, and full waiter queues. - Complete the bind-change recovery protocol in test doubles instead of relying on timing. - Reuse the package-owned authenticated embedded cluster in Issue26095 instead of starting another persistent cluster, reducing CI port/resource contention. The tests expose the interleavings; the correctness and performance fixes are in production code. ### Performance impact - Concurrent factory work is hard-bounded at four workers; there is no unbounded synchronous dial fallback. - Slow physical backend/table close no longer serializes publication under global/holder locks. - Independent recovery transports trade a small, bounded connection footprint for isolation from transaction-traffic head-of-line blocking. - Transport cleanup is concurrent where resources are independent, avoiding additive close latency. ### Validation on merged latest `main` - `mo-cgo-test -race -count=1 ./pkg/common/morpc` — PASS - `mo-cgo-test -race -count=1 ./pkg/lockservice` — PASS - original lock-conflict tests, `-race -count=100` — PASS - `TestRemoteWithBindChanged`, `-race -count=100` — PASS - `TestIssue26095ConcurrentDataBranchDeletion`, `-race -count=1` — PASS - `go vet` with the repository CGo environment for MORPC, lockservice, lockop, and issue tests — PASS ### Known bounded follow-up `BackendFactory.Create` does not accept a context today. Cancellation can therefore invalidate its result but cannot interrupt a factory call that has already started. The fixed worker pool bounds the blast radius; a contextual factory API (and, if measurements justify it, an explicit control-priority lane) should be handled as a separate interface change. Unknown-commit completion callbacks are detached from the resolver stopper task so that callback re-entry into `Close` cannot self-deadlock. MatrixOne's current callbacks are short admission-release operations; the public callback contract should explicitly require non-blocking completion, or move to a bounded dispatcher, before accepting arbitrary external callbacks.
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…gin#26553) ## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#26547 Related: matrixorigin#26475 Nightly regression: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/30649446904/job/91275888648 ## What this PR does / why we need it: The failing 1000-thread sysbench run returned 100 lock RPC errors as backend-closed (20502). Incident metrics show the same 88/12 split across two clients in both MORPC auto-create timeouts and lockservice backend-closed errors, with no create-queue full/drop, circuit-breaker trip, pod restart, or OOM. The connection factory was delayed while the CNs were CPU saturated, so the lockservice-wide 500ms backend-create deadline expired for all callers coalesced on those two cold connections. The direct mechanism is not unique to matrixorigin#26473: the 500ms lockservice setting came from matrixorigin#23435, and a genuinely blocked factory reproduces the 100/100 failure on both the pre-matrixorigin#26473 baseline and the incident MORPC code. matrixorigin#26473 makes completion-at-the-deadline classification deterministic, which can affect the boundary, but a real factory delay beyond 500ms does not require that change. This PR: - keeps the independent 5s local create-queue admission bound on every lockservice transport; - limits the 500ms peer-health deadline to active-transaction recovery and service-validation transports, where fast failure is required; - lets normal Lock/Unlock, keeper, and control traffic follow their already-bounded caller contexts and the backend's 5s connect timeout; - preserves the independent liveness probe in recovery client configs; - classifies backend-create timeout separately from generic backend-closed in MORPC and lockservice metrics; - adds a low-cardinality distinct-create-event counter alongside the existing per-request impact counter; - emits at most one warning per create state and rate-limits the static event to one log per client per minute; - updates the RPC Grafana panel to compare affected requests with distinct create events. Deep-review hardening: - the timeout logger retains only one keyed limiter state, bounding future accidental dynamic-key growth; - failure-only diagnostic fields are placed after the pre-existing hot client state, preserving mutex/pool field offsets used by every Send; - normal traffic is tested for prompt caller cancellation while factory creation remains blocked; - wrapped create-timeout errors retain their dedicated metric classification. The regression tests construct a successful but delayed backend factory. They verify 100 coalesced callers all reproduce 20502 at 500ms, while producing 100 impact counts, one event count, one retained limiter key, and one warning. The lockservice policy test verifies normal traffic succeeds after waiting beyond 500ms, remains caller-cancellable, and recovery traffic still fails fast. Verification after rebasing onto latest main: - focused fan-out race: T=0.5s, B=30s, N=60 - focused lockservice role/cancellation race: T=1.11s, B=30s, N=27 - admission-boundary, nil-state timeout, and error-classification race: N=100 each - full `./pkg/common/morpc` race: passed - full `./pkg/lockservice` race: passed - full non-race MORPC, lockservice, and metric-v2 tests: passed - build and vet for all four modified packages: passed - hot-path benchmark, clean main vs PR: both 144 B/op and 1 alloc/op; PR 207-212 ns/op vs main 210-211 ns/op - dashboard compile-only test: passed; its live-Grafana tests require `127.0.0.1:80` and fail identically on clean HEAD when Grafana is absent
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…matrixorigin#26914) ## What type of PR is this? - [x] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#26474 ## What this PR does / why we need it: This closes the two lifecycle gaps deliberately left after matrixorigin#26473. ### Contextual backend creation - Adds the backward-compatible `ContextBackendFactory` capability. Existing `BackendFactory` implementations continue to work; clients prefer contextual creation when supported. - Binds every asynchronous create state to its exact client generation and GC-manager incarnation. Client close, targeted/full reset, queue invalidation, and manager replacement cancel that state. - Makes the Goetty factory contextual without allowing cancellation to bypass the process-wide concurrency bound: shared workers and lower-level legacy Connect attempts are both capped at four. A cancelled late result retains ownership and is closed before it can escape. - Keeps local lifecycle cancellation out of `factoryErr`, error logs, and peer-breaker evidence. A factory timeout while the generation remains live is still preserved as definitive failure evidence. ### Unknown-commit callbacks - Defines completion callbacks as prompt, non-blocking external code that may re-enter `Close`. - Reserves callback capacity when ownership transfers and caps accepted-but-not-returned callbacks at 1024. There is no unbounded callback queue or detached-goroutine fan-out. - Saturation returns an error before callback ownership transfers, while lock-cleanup ownership is still scheduled so locks are not stranded. - Service shutdown seals callback admission, joins the resolver, drains pending callback reservations by transferring invocation out of service ownership, and only then releases the RPC transport. `Close` never waits on a callback body that may itself call `Close`. - Rolls back callback ownership if resolver task startup fails, preventing double admission release on the caller error path. ### Validation Based on `origin/main@fa0ea95`. - `go vet -mod=readonly ./pkg/common/morpc ./pkg/lockservice` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/common/morpc ./pkg/lockservice` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=15m ./pkg/common/morpc ./pkg/lockservice` - Each of the 10 new lifecycle regressions measured individually under race (`T=0s..0.06s`, stress budget `B=30s`, adaptive `N=100`) and then passed separately with exact `-run`, `-race`, and `-count=100`. The local Darwin linker emitted only the pre-existing missing `/opt/homebrew/opt/libpqxx/lib/` search-path warning; every command exited successfully.
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…26473) ## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#26467 ## What this PR does / why we need it: The failures grouped in matrixorigin#26467 are not one lock-conflict race and are not test-only. A loaded CI host exposes four production contract violations: 1. **Local scheduling was treated as peer failure.** MORPC charged time spent waiting for a process-wide create worker to the backend factory timeout and could poison a healthy peer's breaker. 2. **Endpoint observations were treated as service identity.** A stale endpoint could return one negative validation result and disable a newer/live lockservice bind. 3. **Cleanup ownership was implicit.** Backend, table, callback, and response cleanup could block while holding publication locks, race with replacement generations, or be performed twice. 4. **Shutdown was not a protocol.** Close paths did not consistently seal admission, cancel admitted work, join it, drain queues, and then release resources. Under adverse timing this caused late sends, long waits, leaks, or deadlocks. ### Production-code fixes #### MORPC scheduling, failure evidence, and lifecycle - Separate the local backend-create queue budget from the peer factory budget. Queue-full/queue-timeout are local transient errors and do not update the peer breaker. - Replace synchronous queue-full fallback with a fixed four-worker process-wide factory pool, bounding concurrent DNS/dial work under overload. - Track exact create state and generation through queued -> started -> completed, share one factory budget across retries, and reject late results from invalidated generations. - Preserve definitive `BackendCannotConnect` evidence while keeping timeout/closed/local-congestion failures transient. - Pin a manager generation to each client, support safe manager replacement/reconfiguration, use one metrics ticker, and gate workers again after dequeue so shutdown cannot start new factory work. - Make `CloseBackend` invalidate and detach under the client mutex, then physically close outside it. Replacement publication is no longer blocked by a slow backend close, while client close still joins the detached cleanup exactly once. #### Lockservice recovery and shutdown - Isolate normal, control, active-transaction, validation, and keeper traffic so transaction saturation cannot starve recovery/control paths. - Require two independent negative validation observations: reset the validation backend and refresh authoritative discovery before disabling a bind. Missing reset capability fails closed instead of accepting one stale negative. - Commit negative validation only if the bind-set identity and keepalive generation still match the snapshot, so stale validation cannot overwrite newer positive evidence. - Add idempotent/sticky close ownership and best-effort `errors.Join` cleanup for clients, server, allocator, and service resources. - Implement service/server admission gates: seal new work, cancel admitted work, wait for callbacks/operations, drain queued responses, then close owned tables and transports. - Propagate service cancellation through remote/forward lock work and transfer async callback finalization with an explicit atomic ownership state. - Run unknown-commit callbacks outside resolver tasks so a re-entrant `Close` cannot wait on its own stopper task. - Detach lock tables and waiter/store edges under locks, publish the new holder version, and perform potentially blocking close/notification outside locks. This removes holder/table -> bounded event queue -> worker -> holder/table cycles. ### Test-only changes - Add deterministic, channel-synchronized regression tests for queue admission, create-generation invalidation, manager stop/reconfiguration, close ownership, callback re-entry, service cancellation, stale validation evidence, and full waiter queues. - Complete the bind-change recovery protocol in test doubles instead of relying on timing. - Reuse the package-owned authenticated embedded cluster in Issue26095 instead of starting another persistent cluster, reducing CI port/resource contention. The tests expose the interleavings; the correctness and performance fixes are in production code. ### Performance impact - Concurrent factory work is hard-bounded at four workers; there is no unbounded synchronous dial fallback. - Slow physical backend/table close no longer serializes publication under global/holder locks. - Independent recovery transports trade a small, bounded connection footprint for isolation from transaction-traffic head-of-line blocking. - Transport cleanup is concurrent where resources are independent, avoiding additive close latency. ### Validation on merged latest `main` - `mo-cgo-test -race -count=1 ./pkg/common/morpc` — PASS - `mo-cgo-test -race -count=1 ./pkg/lockservice` — PASS - original lock-conflict tests, `-race -count=100` — PASS - `TestRemoteWithBindChanged`, `-race -count=100` — PASS - `TestIssue26095ConcurrentDataBranchDeletion`, `-race -count=1` — PASS - `go vet` with the repository CGo environment for MORPC, lockservice, lockop, and issue tests — PASS ### Known bounded follow-up `BackendFactory.Create` does not accept a context today. Cancellation can therefore invalidate its result but cannot interrupt a factory call that has already started. The fixed worker pool bounds the blast radius; a contextual factory API (and, if measurements justify it, an explicit control-priority lane) should be handled as a separate interface change. Unknown-commit completion callbacks are detached from the resolver stopper task so that callback re-entry into `Close` cannot self-deadlock. MatrixOne's current callbacks are short admission-release operations; the public callback contract should explicitly require non-blocking completion, or move to a bounded dispatcher, before accepting arbitrary external callbacks.
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…gin#26553) ## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#26547 Related: matrixorigin#26475 Nightly regression: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/30649446904/job/91275888648 ## What this PR does / why we need it: The failing 1000-thread sysbench run returned 100 lock RPC errors as backend-closed (20502). Incident metrics show the same 88/12 split across two clients in both MORPC auto-create timeouts and lockservice backend-closed errors, with no create-queue full/drop, circuit-breaker trip, pod restart, or OOM. The connection factory was delayed while the CNs were CPU saturated, so the lockservice-wide 500ms backend-create deadline expired for all callers coalesced on those two cold connections. The direct mechanism is not unique to matrixorigin#26473: the 500ms lockservice setting came from matrixorigin#23435, and a genuinely blocked factory reproduces the 100/100 failure on both the pre-matrixorigin#26473 baseline and the incident MORPC code. matrixorigin#26473 makes completion-at-the-deadline classification deterministic, which can affect the boundary, but a real factory delay beyond 500ms does not require that change. This PR: - keeps the independent 5s local create-queue admission bound on every lockservice transport; - limits the 500ms peer-health deadline to active-transaction recovery and service-validation transports, where fast failure is required; - lets normal Lock/Unlock, keeper, and control traffic follow their already-bounded caller contexts and the backend's 5s connect timeout; - preserves the independent liveness probe in recovery client configs; - classifies backend-create timeout separately from generic backend-closed in MORPC and lockservice metrics; - adds a low-cardinality distinct-create-event counter alongside the existing per-request impact counter; - emits at most one warning per create state and rate-limits the static event to one log per client per minute; - updates the RPC Grafana panel to compare affected requests with distinct create events. Deep-review hardening: - the timeout logger retains only one keyed limiter state, bounding future accidental dynamic-key growth; - failure-only diagnostic fields are placed after the pre-existing hot client state, preserving mutex/pool field offsets used by every Send; - normal traffic is tested for prompt caller cancellation while factory creation remains blocked; - wrapped create-timeout errors retain their dedicated metric classification. The regression tests construct a successful but delayed backend factory. They verify 100 coalesced callers all reproduce 20502 at 500ms, while producing 100 impact counts, one event count, one retained limiter key, and one warning. The lockservice policy test verifies normal traffic succeeds after waiting beyond 500ms, remains caller-cancellable, and recovery traffic still fails fast. Verification after rebasing onto latest main: - focused fan-out race: T=0.5s, B=30s, N=60 - focused lockservice role/cancellation race: T=1.11s, B=30s, N=27 - admission-boundary, nil-state timeout, and error-classification race: N=100 each - full `./pkg/common/morpc` race: passed - full `./pkg/lockservice` race: passed - full non-race MORPC, lockservice, and metric-v2 tests: passed - build and vet for all four modified packages: passed - hot-path benchmark, clean main vs PR: both 144 B/op and 1 alloc/op; PR 207-212 ns/op vs main 210-211 ns/op - dashboard compile-only test: passed; its live-Grafana tests require `127.0.0.1:80` and fail identically on clean HEAD when Grafana is absent
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…matrixorigin#26914) ## What type of PR is this? - [x] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#26474 ## What this PR does / why we need it: This closes the two lifecycle gaps deliberately left after matrixorigin#26473. ### Contextual backend creation - Adds the backward-compatible `ContextBackendFactory` capability. Existing `BackendFactory` implementations continue to work; clients prefer contextual creation when supported. - Binds every asynchronous create state to its exact client generation and GC-manager incarnation. Client close, targeted/full reset, queue invalidation, and manager replacement cancel that state. - Makes the Goetty factory contextual without allowing cancellation to bypass the process-wide concurrency bound: shared workers and lower-level legacy Connect attempts are both capped at four. A cancelled late result retains ownership and is closed before it can escape. - Keeps local lifecycle cancellation out of `factoryErr`, error logs, and peer-breaker evidence. A factory timeout while the generation remains live is still preserved as definitive failure evidence. ### Unknown-commit callbacks - Defines completion callbacks as prompt, non-blocking external code that may re-enter `Close`. - Reserves callback capacity when ownership transfers and caps accepted-but-not-returned callbacks at 1024. There is no unbounded callback queue or detached-goroutine fan-out. - Saturation returns an error before callback ownership transfers, while lock-cleanup ownership is still scheduled so locks are not stranded. - Service shutdown seals callback admission, joins the resolver, drains pending callback reservations by transferring invocation out of service ownership, and only then releases the RPC transport. `Close` never waits on a callback body that may itself call `Close`. - Rolls back callback ownership if resolver task startup fails, preventing double admission release on the caller error path. ### Validation Based on `origin/main@fa0ea95`. - `go vet -mod=readonly ./pkg/common/morpc ./pkg/lockservice` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/common/morpc ./pkg/lockservice` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=15m ./pkg/common/morpc ./pkg/lockservice` - Each of the 10 new lifecycle regressions measured individually under race (`T=0s..0.06s`, stress budget `B=30s`, adaptive `N=100`) and then passed separately with exact `-run`, `-race`, and `-count=100`. The local Darwin linker emitted only the pre-existing missing `/opt/homebrew/opt/libpqxx/lib/` search-path warning; every command exited successfully.
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…26473) ## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#26467 ## What this PR does / why we need it: The failures grouped in matrixorigin#26467 are not one lock-conflict race and are not test-only. A loaded CI host exposes four production contract violations: 1. **Local scheduling was treated as peer failure.** MORPC charged time spent waiting for a process-wide create worker to the backend factory timeout and could poison a healthy peer's breaker. 2. **Endpoint observations were treated as service identity.** A stale endpoint could return one negative validation result and disable a newer/live lockservice bind. 3. **Cleanup ownership was implicit.** Backend, table, callback, and response cleanup could block while holding publication locks, race with replacement generations, or be performed twice. 4. **Shutdown was not a protocol.** Close paths did not consistently seal admission, cancel admitted work, join it, drain queues, and then release resources. Under adverse timing this caused late sends, long waits, leaks, or deadlocks. ### Production-code fixes #### MORPC scheduling, failure evidence, and lifecycle - Separate the local backend-create queue budget from the peer factory budget. Queue-full/queue-timeout are local transient errors and do not update the peer breaker. - Replace synchronous queue-full fallback with a fixed four-worker process-wide factory pool, bounding concurrent DNS/dial work under overload. - Track exact create state and generation through queued -> started -> completed, share one factory budget across retries, and reject late results from invalidated generations. - Preserve definitive `BackendCannotConnect` evidence while keeping timeout/closed/local-congestion failures transient. - Pin a manager generation to each client, support safe manager replacement/reconfiguration, use one metrics ticker, and gate workers again after dequeue so shutdown cannot start new factory work. - Make `CloseBackend` invalidate and detach under the client mutex, then physically close outside it. Replacement publication is no longer blocked by a slow backend close, while client close still joins the detached cleanup exactly once. #### Lockservice recovery and shutdown - Isolate normal, control, active-transaction, validation, and keeper traffic so transaction saturation cannot starve recovery/control paths. - Require two independent negative validation observations: reset the validation backend and refresh authoritative discovery before disabling a bind. Missing reset capability fails closed instead of accepting one stale negative. - Commit negative validation only if the bind-set identity and keepalive generation still match the snapshot, so stale validation cannot overwrite newer positive evidence. - Add idempotent/sticky close ownership and best-effort `errors.Join` cleanup for clients, server, allocator, and service resources. - Implement service/server admission gates: seal new work, cancel admitted work, wait for callbacks/operations, drain queued responses, then close owned tables and transports. - Propagate service cancellation through remote/forward lock work and transfer async callback finalization with an explicit atomic ownership state. - Run unknown-commit callbacks outside resolver tasks so a re-entrant `Close` cannot wait on its own stopper task. - Detach lock tables and waiter/store edges under locks, publish the new holder version, and perform potentially blocking close/notification outside locks. This removes holder/table -> bounded event queue -> worker -> holder/table cycles. ### Test-only changes - Add deterministic, channel-synchronized regression tests for queue admission, create-generation invalidation, manager stop/reconfiguration, close ownership, callback re-entry, service cancellation, stale validation evidence, and full waiter queues. - Complete the bind-change recovery protocol in test doubles instead of relying on timing. - Reuse the package-owned authenticated embedded cluster in Issue26095 instead of starting another persistent cluster, reducing CI port/resource contention. The tests expose the interleavings; the correctness and performance fixes are in production code. ### Performance impact - Concurrent factory work is hard-bounded at four workers; there is no unbounded synchronous dial fallback. - Slow physical backend/table close no longer serializes publication under global/holder locks. - Independent recovery transports trade a small, bounded connection footprint for isolation from transaction-traffic head-of-line blocking. - Transport cleanup is concurrent where resources are independent, avoiding additive close latency. ### Validation on merged latest `main` - `mo-cgo-test -race -count=1 ./pkg/common/morpc` — PASS - `mo-cgo-test -race -count=1 ./pkg/lockservice` — PASS - original lock-conflict tests, `-race -count=100` — PASS - `TestRemoteWithBindChanged`, `-race -count=100` — PASS - `TestIssue26095ConcurrentDataBranchDeletion`, `-race -count=1` — PASS - `go vet` with the repository CGo environment for MORPC, lockservice, lockop, and issue tests — PASS ### Known bounded follow-up `BackendFactory.Create` does not accept a context today. Cancellation can therefore invalidate its result but cannot interrupt a factory call that has already started. The fixed worker pool bounds the blast radius; a contextual factory API (and, if measurements justify it, an explicit control-priority lane) should be handled as a separate interface change. Unknown-commit completion callbacks are detached from the resolver stopper task so that callback re-entry into `Close` cannot self-deadlock. MatrixOne's current callbacks are short admission-release operations; the public callback contract should explicitly require non-blocking completion, or move to a bounded dispatcher, before accepting arbitrary external callbacks.
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…gin#26553) ## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#26547 Related: matrixorigin#26475 Nightly regression: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/30649446904/job/91275888648 ## What this PR does / why we need it: The failing 1000-thread sysbench run returned 100 lock RPC errors as backend-closed (20502). Incident metrics show the same 88/12 split across two clients in both MORPC auto-create timeouts and lockservice backend-closed errors, with no create-queue full/drop, circuit-breaker trip, pod restart, or OOM. The connection factory was delayed while the CNs were CPU saturated, so the lockservice-wide 500ms backend-create deadline expired for all callers coalesced on those two cold connections. The direct mechanism is not unique to matrixorigin#26473: the 500ms lockservice setting came from matrixorigin#23435, and a genuinely blocked factory reproduces the 100/100 failure on both the pre-matrixorigin#26473 baseline and the incident MORPC code. matrixorigin#26473 makes completion-at-the-deadline classification deterministic, which can affect the boundary, but a real factory delay beyond 500ms does not require that change. This PR: - keeps the independent 5s local create-queue admission bound on every lockservice transport; - limits the 500ms peer-health deadline to active-transaction recovery and service-validation transports, where fast failure is required; - lets normal Lock/Unlock, keeper, and control traffic follow their already-bounded caller contexts and the backend's 5s connect timeout; - preserves the independent liveness probe in recovery client configs; - classifies backend-create timeout separately from generic backend-closed in MORPC and lockservice metrics; - adds a low-cardinality distinct-create-event counter alongside the existing per-request impact counter; - emits at most one warning per create state and rate-limits the static event to one log per client per minute; - updates the RPC Grafana panel to compare affected requests with distinct create events. Deep-review hardening: - the timeout logger retains only one keyed limiter state, bounding future accidental dynamic-key growth; - failure-only diagnostic fields are placed after the pre-existing hot client state, preserving mutex/pool field offsets used by every Send; - normal traffic is tested for prompt caller cancellation while factory creation remains blocked; - wrapped create-timeout errors retain their dedicated metric classification. The regression tests construct a successful but delayed backend factory. They verify 100 coalesced callers all reproduce 20502 at 500ms, while producing 100 impact counts, one event count, one retained limiter key, and one warning. The lockservice policy test verifies normal traffic succeeds after waiting beyond 500ms, remains caller-cancellable, and recovery traffic still fails fast. Verification after rebasing onto latest main: - focused fan-out race: T=0.5s, B=30s, N=60 - focused lockservice role/cancellation race: T=1.11s, B=30s, N=27 - admission-boundary, nil-state timeout, and error-classification race: N=100 each - full `./pkg/common/morpc` race: passed - full `./pkg/lockservice` race: passed - full non-race MORPC, lockservice, and metric-v2 tests: passed - build and vet for all four modified packages: passed - hot-path benchmark, clean main vs PR: both 144 B/op and 1 alloc/op; PR 207-212 ns/op vs main 210-211 ns/op - dashboard compile-only test: passed; its live-Grafana tests require `127.0.0.1:80` and fail identically on clean HEAD when Grafana is absent
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…matrixorigin#26914) ## What type of PR is this? - [x] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#26474 ## What this PR does / why we need it: This closes the two lifecycle gaps deliberately left after matrixorigin#26473. ### Contextual backend creation - Adds the backward-compatible `ContextBackendFactory` capability. Existing `BackendFactory` implementations continue to work; clients prefer contextual creation when supported. - Binds every asynchronous create state to its exact client generation and GC-manager incarnation. Client close, targeted/full reset, queue invalidation, and manager replacement cancel that state. - Makes the Goetty factory contextual without allowing cancellation to bypass the process-wide concurrency bound: shared workers and lower-level legacy Connect attempts are both capped at four. A cancelled late result retains ownership and is closed before it can escape. - Keeps local lifecycle cancellation out of `factoryErr`, error logs, and peer-breaker evidence. A factory timeout while the generation remains live is still preserved as definitive failure evidence. ### Unknown-commit callbacks - Defines completion callbacks as prompt, non-blocking external code that may re-enter `Close`. - Reserves callback capacity when ownership transfers and caps accepted-but-not-returned callbacks at 1024. There is no unbounded callback queue or detached-goroutine fan-out. - Saturation returns an error before callback ownership transfers, while lock-cleanup ownership is still scheduled so locks are not stranded. - Service shutdown seals callback admission, joins the resolver, drains pending callback reservations by transferring invocation out of service ownership, and only then releases the RPC transport. `Close` never waits on a callback body that may itself call `Close`. - Rolls back callback ownership if resolver task startup fails, preventing double admission release on the caller error path. ### Validation Based on `origin/main@fa0ea95`. - `go vet -mod=readonly ./pkg/common/morpc ./pkg/lockservice` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=15m ./pkg/common/morpc ./pkg/lockservice` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=15m ./pkg/common/morpc ./pkg/lockservice` - Each of the 10 new lifecycle regressions measured individually under race (`T=0s..0.06s`, stress budget `B=30s`, adaptive `N=100`) and then passed separately with exact `-run`, `-race`, and `-count=100`. The local Darwin linker emitted only the pre-existing missing `/opt/homebrew/opt/libpqxx/lib/` search-path warning; every command exited successfully.
This branch was previously deployed
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:
Fixes #26467 #26475
What this PR does / why we need it:
The failures grouped in #26467 are not one lock-conflict race and are not test-only. A loaded CI host exposes four production contract violations:
Production-code fixes
MORPC scheduling, failure evidence, and lifecycle
BackendCannotConnectevidence while keeping timeout/closed/local-congestion failures transient.CloseBackendinvalidate and detach under the client mutex, then physically close outside it. Replacement publication is no longer blocked by a slow backend close, while client close still joins the detached cleanup exactly once.Lockservice recovery and shutdown
errors.Joincleanup for clients, server, allocator, and service resources.Closecannot wait on its own stopper task.Test-only changes
The tests expose the interleavings; the correctness and performance fixes are in production code.
Performance impact
Validation on merged latest
mainmo-cgo-test -race -count=1 ./pkg/common/morpc— PASSmo-cgo-test -race -count=1 ./pkg/lockservice— PASS-race -count=100— PASSTestRemoteWithBindChanged,-race -count=100— PASSTestIssue26095ConcurrentDataBranchDeletion,-race -count=1— PASSgo vetwith the repository CGo environment for MORPC, lockservice, lockop, and issue tests — PASSKnown bounded follow-up
BackendFactory.Createdoes not accept a context today. Cancellation can therefore invalidate its result but cannot interrupt a factory call that has already started. The fixed worker pool bounds the blast radius; a contextual factory API (and, if measurements justify it, an explicit control-priority lane) should be handled as a separate interface change.Unknown-commit completion callbacks are detached from the resolver stopper task so that callback re-entry into
Closecannot self-deadlock. MatrixOne's current callbacks are short admission-release operations; the public callback contract should explicitly require non-blocking completion, or move to a bounded dispatcher, before accepting arbitrary external callbacks.