Repository navigation
Conversation
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? |
LeftHandCold
left a comment
There was a problem hiding this comment.
Code-review verdict: LGTM on exact head 6177edf (GitHub does not allow the author account to submit APPROVE on its own PR).
I traced the per-key allocation state machine, refill ownership, waiter cancellation/takeover, shared-client generation reset, frontend timeout propagation, and Q1-Q3 resource/wait/growth paths. The elected refiller is the sole channel closer; every normal success/error path wakes waiters; cancellation is independent of the refill RPC; failed refill ownership is retryable by a valid waiter; and a stale client failure cannot reset a replacement generation. ID uniqueness and full batch-boundary consumption are preserved, while cached allocations and unrelated keys no longer queue behind a slow refill.
I found no production-reachable correctness, availability, performance, or lifecycle blocker. MatrixOne UT/SCA/BVT/coverage checks are green. I deliberately did not rerun heavy local UT/BVT.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed commit 6177edf.
The per-key refill state machine has a single refill owner, publishes the batch before waking waiters, lets independently-cancelled waiters exit or take over after owner failure, and keeps cached allocations for other keys off the refill/client locks. Client invalidation is generation-scoped, so stale failures cannot reset a replacement client. The frontend allocation deadline is now aligned with the configured connection/handshake timeout.
Verified the five new logservice concurrency/deadline tests and the frontend timeout propagation test with -race -count=100; all passed. No blocking findings.
Merge Queue Status
This pull request spent 19 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Tick the box to put this pull request back in the merge queue (same as
|
…7119) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27114 ## What this PR does / why we need it: The failing debug job admitted exactly 92 of 1,000 Sysbench connections and rejected the remaining 908. That matches the 92 IDs left in the local 100-ID connection batch. The rejected connections produced 908 `failed to get connection ID from HAKeeper` errors. The apparent 5.28-second HAKeeper outage was mostly a client-side convoy: 1. `AllocateIDByKeyWithBatch` held the managed client's single mutex across cached allocation, HAKeeper discovery, and the refill RPC. 2. The first refill exhausted `getConnID`'s hard-coded two-second deadline. 3. Hundreds of callers had already passed context validation and then waited behind that mutex until their deadlines expired. 4. A stale waiter could consequently reach MORPC with an expired deadline. MORPC returned `invalid input: timeout has invalid deadline`; the managed client treated that local error as a broken shared transport and reset it. 5. The remaining stale waiters then serialized HAKeeper rediscovery under the same mutex. The job recorded 880 `isHAKeeper:false` results while that queue drained. This change separates ID-batch state from managed-client state and gives each allocation key its own refill coordination: - one caller refills an empty batch while same-key waiters wait on a refill channel with their own contexts; - cached IDs and other keys no longer wait behind a slow refill RPC; - a failed refiller wakes waiters so a still-valid caller can take over; - client snapshots are used outside the allocation lock and resets remain generation-safe; - expired contexts are rejected before discovery/RPC; and - connection-ID allocation uses the configured frontend `ConnectTimeout` (60 seconds by default) instead of an unrelated hard-coded two seconds. The same refill primitive is used by unkeyed allocation so that path cannot reintroduce cross-key blocking through the shared client mutex. No public API, wire format, persistent state, or server-side ID allocation semantics change. ## Validation The deterministic regressions failed on the unmodified implementation: - a same-key waiter remained blocked after its 20 ms context expired and then incorrectly consumed an ID after the leader completed; - `getConnID` exposed a roughly two-second deadline despite a configured 17-second connection timeout. The fixed implementation passes: - 1,000 concurrent connection allocations starting with 92 cached IDs: 1,000 unique contiguous IDs and exactly 10 refill RPCs; - context cancellation while waiting for a refill; - rejection of an already-expired context before RPC; - cached allocation for another key during a blocked refill; - waiter takeover after the refill owner fails; - client reuse after caller-scoped context errors; - complete batch-boundary consumption; and - propagation of the configured frontend connection timeout. Commands/results: - focused regressions: pass; - every focused regression with `-race -count=100`: pass; - `pkg/logservice` owning-package tests: pass in 134.665s, excluding the independently reproduced baseline failure noted below; - `pkg/frontend` owning-package tests: pass in 16.418s; - `pkg/logservice` owning-package race tests: pass in 140.629s, with the same baseline exclusion; - `pkg/frontend` owning-package race tests: pass in 25.105s; - `go build -mod=readonly ./pkg/logservice ./pkg/frontend`: pass; - `go vet -mod=readonly ./pkg/logservice ./pkg/frontend`: pass; and - `git diff --check`: pass. `TestNewServiceClosesStoreOnReplicaStartFailure` is currently a deterministic, unrelated failure on this environment. On the clean `main` base `bdbd613fdece966769eb68481a3e58bfbc36b30c`, the exact test failed 10/10 with the same `service_test.go:171: Expected nil, but got *logservice.Service` signature. This PR does not touch service construction or that test; it was the only exclusion from the two package-level `pkg/logservice` runs above. ## Risk The normal cached path adds only a per-key mutex; refill RPCs are still single-flight per key. The change intentionally allows independent keys to allocate concurrently, which HAKeeper already has to support across distinct clients and CNs. Refill channels are per generation, owned and closed exactly once by the elected refiller, and no background goroutine or new cleanup owner is introduced. Co-authored-by: XuPeng-SH <[email protected]>
…7119) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27114 ## What this PR does / why we need it: The failing debug job admitted exactly 92 of 1,000 Sysbench connections and rejected the remaining 908. That matches the 92 IDs left in the local 100-ID connection batch. The rejected connections produced 908 `failed to get connection ID from HAKeeper` errors. The apparent 5.28-second HAKeeper outage was mostly a client-side convoy: 1. `AllocateIDByKeyWithBatch` held the managed client's single mutex across cached allocation, HAKeeper discovery, and the refill RPC. 2. The first refill exhausted `getConnID`'s hard-coded two-second deadline. 3. Hundreds of callers had already passed context validation and then waited behind that mutex until their deadlines expired. 4. A stale waiter could consequently reach MORPC with an expired deadline. MORPC returned `invalid input: timeout has invalid deadline`; the managed client treated that local error as a broken shared transport and reset it. 5. The remaining stale waiters then serialized HAKeeper rediscovery under the same mutex. The job recorded 880 `isHAKeeper:false` results while that queue drained. This change separates ID-batch state from managed-client state and gives each allocation key its own refill coordination: - one caller refills an empty batch while same-key waiters wait on a refill channel with their own contexts; - cached IDs and other keys no longer wait behind a slow refill RPC; - a failed refiller wakes waiters so a still-valid caller can take over; - client snapshots are used outside the allocation lock and resets remain generation-safe; - expired contexts are rejected before discovery/RPC; and - connection-ID allocation uses the configured frontend `ConnectTimeout` (60 seconds by default) instead of an unrelated hard-coded two seconds. The same refill primitive is used by unkeyed allocation so that path cannot reintroduce cross-key blocking through the shared client mutex. No public API, wire format, persistent state, or server-side ID allocation semantics change. ## Validation The deterministic regressions failed on the unmodified implementation: - a same-key waiter remained blocked after its 20 ms context expired and then incorrectly consumed an ID after the leader completed; - `getConnID` exposed a roughly two-second deadline despite a configured 17-second connection timeout. The fixed implementation passes: - 1,000 concurrent connection allocations starting with 92 cached IDs: 1,000 unique contiguous IDs and exactly 10 refill RPCs; - context cancellation while waiting for a refill; - rejection of an already-expired context before RPC; - cached allocation for another key during a blocked refill; - waiter takeover after the refill owner fails; - client reuse after caller-scoped context errors; - complete batch-boundary consumption; and - propagation of the configured frontend connection timeout. Commands/results: - focused regressions: pass; - every focused regression with `-race -count=100`: pass; - `pkg/logservice` owning-package tests: pass in 134.665s, excluding the independently reproduced baseline failure noted below; - `pkg/frontend` owning-package tests: pass in 16.418s; - `pkg/logservice` owning-package race tests: pass in 140.629s, with the same baseline exclusion; - `pkg/frontend` owning-package race tests: pass in 25.105s; - `go build -mod=readonly ./pkg/logservice ./pkg/frontend`: pass; - `go vet -mod=readonly ./pkg/logservice ./pkg/frontend`: pass; and - `git diff --check`: pass. `TestNewServiceClosesStoreOnReplicaStartFailure` is currently a deterministic, unrelated failure on this environment. On the clean `main` base `bdbd613fdece966769eb68481a3e58bfbc36b30c`, the exact test failed 10/10 with the same `service_test.go:171: Expected nil, but got *logservice.Service` signature. This PR does not touch service construction or that test; it was the only exclusion from the two package-level `pkg/logservice` runs above. ## Risk The normal cached path adds only a per-key mutex; refill RPCs are still single-flight per key. The change intentionally allows independent keys to allocate concurrently, which HAKeeper already has to support across distinct clients and CNs. Refill channels are per generation, owned and closed exactly once by the elected refiller, and no background goroutine or new cleanup owner is introduced. Co-authored-by: XuPeng-SH <[email protected]>
…7119) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27114 ## What this PR does / why we need it: The failing debug job admitted exactly 92 of 1,000 Sysbench connections and rejected the remaining 908. That matches the 92 IDs left in the local 100-ID connection batch. The rejected connections produced 908 `failed to get connection ID from HAKeeper` errors. The apparent 5.28-second HAKeeper outage was mostly a client-side convoy: 1. `AllocateIDByKeyWithBatch` held the managed client's single mutex across cached allocation, HAKeeper discovery, and the refill RPC. 2. The first refill exhausted `getConnID`'s hard-coded two-second deadline. 3. Hundreds of callers had already passed context validation and then waited behind that mutex until their deadlines expired. 4. A stale waiter could consequently reach MORPC with an expired deadline. MORPC returned `invalid input: timeout has invalid deadline`; the managed client treated that local error as a broken shared transport and reset it. 5. The remaining stale waiters then serialized HAKeeper rediscovery under the same mutex. The job recorded 880 `isHAKeeper:false` results while that queue drained. This change separates ID-batch state from managed-client state and gives each allocation key its own refill coordination: - one caller refills an empty batch while same-key waiters wait on a refill channel with their own contexts; - cached IDs and other keys no longer wait behind a slow refill RPC; - a failed refiller wakes waiters so a still-valid caller can take over; - client snapshots are used outside the allocation lock and resets remain generation-safe; - expired contexts are rejected before discovery/RPC; and - connection-ID allocation uses the configured frontend `ConnectTimeout` (60 seconds by default) instead of an unrelated hard-coded two seconds. The same refill primitive is used by unkeyed allocation so that path cannot reintroduce cross-key blocking through the shared client mutex. No public API, wire format, persistent state, or server-side ID allocation semantics change. ## Validation The deterministic regressions failed on the unmodified implementation: - a same-key waiter remained blocked after its 20 ms context expired and then incorrectly consumed an ID after the leader completed; - `getConnID` exposed a roughly two-second deadline despite a configured 17-second connection timeout. The fixed implementation passes: - 1,000 concurrent connection allocations starting with 92 cached IDs: 1,000 unique contiguous IDs and exactly 10 refill RPCs; - context cancellation while waiting for a refill; - rejection of an already-expired context before RPC; - cached allocation for another key during a blocked refill; - waiter takeover after the refill owner fails; - client reuse after caller-scoped context errors; - complete batch-boundary consumption; and - propagation of the configured frontend connection timeout. Commands/results: - focused regressions: pass; - every focused regression with `-race -count=100`: pass; - `pkg/logservice` owning-package tests: pass in 134.665s, excluding the independently reproduced baseline failure noted below; - `pkg/frontend` owning-package tests: pass in 16.418s; - `pkg/logservice` owning-package race tests: pass in 140.629s, with the same baseline exclusion; - `pkg/frontend` owning-package race tests: pass in 25.105s; - `go build -mod=readonly ./pkg/logservice ./pkg/frontend`: pass; - `go vet -mod=readonly ./pkg/logservice ./pkg/frontend`: pass; and - `git diff --check`: pass. `TestNewServiceClosesStoreOnReplicaStartFailure` is currently a deterministic, unrelated failure on this environment. On the clean `main` base `bdbd613fdece966769eb68481a3e58bfbc36b30c`, the exact test failed 10/10 with the same `service_test.go:171: Expected nil, but got *logservice.Service` signature. This PR does not touch service construction or that test; it was the only exclusion from the two package-level `pkg/logservice` runs above. ## Risk The normal cached path adds only a per-key mutex; refill RPCs are still single-flight per key. The change intentionally allows independent keys to allocate concurrently, which HAKeeper already has to support across distinct clients and CNs. Refill channels are per generation, owned and closed exactly once by the elected refiller, and no background goroutine or new cleanup owner is introduced. Co-authored-by: XuPeng-SH <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27114
What this PR does / why we need it:
The failing debug job admitted exactly 92 of 1,000 Sysbench connections and
rejected the remaining 908. That matches the 92 IDs left in the local
100-ID connection batch. The rejected connections produced 908
failed to get connection ID from HAKeepererrors.The apparent 5.28-second HAKeeper outage was mostly a client-side convoy:
AllocateIDByKeyWithBatchheld the managed client's single mutex acrosscached allocation, HAKeeper discovery, and the refill RPC.
getConnID's hard-coded two-second deadline.behind that mutex until their deadlines expired.
MORPC returned
invalid input: timeout has invalid deadline; the managedclient treated that local error as a broken shared transport and reset it.
same mutex. The job recorded 880
isHAKeeper:falseresults while that queuedrained.
This change separates ID-batch state from managed-client state and gives each
allocation key its own refill coordination:
channel with their own contexts;
generation-safe;
ConnectTimeout(60 seconds by default) instead of an unrelated hard-coded two seconds.
The same refill primitive is used by unkeyed allocation so that path cannot
reintroduce cross-key blocking through the shared client mutex. No public API,
wire format, persistent state, or server-side ID allocation semantics change.
Validation
The deterministic regressions failed on the unmodified implementation:
incorrectly consumed an ID after the leader completed;
getConnIDexposed a roughly two-second deadline despite a configured17-second connection timeout.
The fixed implementation passes:
1,000 unique contiguous IDs and exactly 10 refill RPCs;
Commands/results:
-race -count=100: pass;pkg/logserviceowning-package tests: pass in 134.665s, excluding theindependently reproduced baseline failure noted below;
pkg/frontendowning-package tests: pass in 16.418s;pkg/logserviceowning-package race tests: pass in 140.629s, with the samebaseline exclusion;
pkg/frontendowning-package race tests: pass in 25.105s;go build -mod=readonly ./pkg/logservice ./pkg/frontend: pass;go vet -mod=readonly ./pkg/logservice ./pkg/frontend: pass; andgit diff --check: pass.TestNewServiceClosesStoreOnReplicaStartFailureis currently a deterministic,unrelated failure on this environment. On the clean
mainbasebdbd613fdece966769eb68481a3e58bfbc36b30c, the exact test failed 10/10 withthe same
service_test.go:171: Expected nil, but got *logservice.Servicesignature. This PR does not touch service construction or that test; it was the
only exclusion from the two package-level
pkg/logserviceruns above.Risk
The normal cached path adds only a per-key mutex; refill RPCs are still
single-flight per key. The change intentionally allows independent keys to
allocate concurrently, which HAKeeper already has to support across distinct
clients and CNs. Refill channels are per generation, owned and closed exactly
once by the elected refiller, and no background goroutine or new cleanup owner
is introduced.