Skip to content

Reduce race UT CPU cost and bootstrap polling waits - #29575

Merged
XuPeng-SH merged 4 commits into
mainfrom
codex/ut-race-phase3-20261002
Oct 2, 2026
Merged

XuPeng-SH merged 4 commits into
mainfrom
codex/ut-race-phase3-20261002

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Embedded race tests repeatedly pay the normal HAKeeper check interval after bootstrap, registration, and admission evidence has already committed. Wake the existing checker on those state changes, and let CN startup reuse its existing admission notification before refreshing authoritative inventory. Stable heartbeats, the periodic fallback, bootstrap deadline, command delivery, and readiness requirements retain their existing contracts.

The earlier expression-owner traversal optimization remains in this PR: skip scalar payloads while preserving traversal of exported expression-bearing fields. Neither optimization removes test scenarios or weakens existing assertions.

Design and cost

  • Heartbeats return a local, nonpersistent NoOP proposal-result hint when accepted registration/readiness, replica count, capability, or existing barrier evidence changes. CommandBatch bytes and RPC fields are unchanged; older versions keep the periodic fallback.
  • A capacity-one nonblocking store notification feeds the existing serial ticker. No additional worker, cached readiness, state machine, or configuration is introduced. Late notifications remain safe after shutdown.
  • CN startup treats admission notifications as hints and still checks revocation, upgrade failure/cancellation, and fresh authoritative inventory. A notification alone cannot authorize startup.
  • Stable heartbeat Tick, resource, address, replica term and ordinary receipt changes do not generate checker notifications. Failed checks retain the configured periodic cadence and wall-clock bootstrap budget.

Measured result

Paired complete pkg/tests/issues/isolated race runs on the same eight pinned CPUs with runtime data on NVMe. The baseline is phase3 commit ac340a83 on main 5a09e1ff; the comparison adds this startup change, so subsequent upstream vector improvements are not attributed to this patch.

Metric Baseline Startup change Change
Wall 222.90 s 167.63 s -24.80% / 55.27 s saved
CPU 199.17 s 167.98 s -15.66%
Peak RSS 3,850,928 KiB 3,719,880 KiB -3.40%
Cumulative allocation 9,924.69 MiB 9,212.12 MiB -7.18%
Twelve service starts 146.93 s 99.32 s -32.41%

All 45 test/subtest PASS identities are identical in both runs. The CN-notification-only experiment did not improve wall time; the complete committed-state chain is necessary for the measured result.

The latest completed racing job spent 62m46s in UT and reported 41 service starts totaling 10.64 minutes. These measurements suggest approximately 2–4 minutes of CI savings, not an observed CI result or proof that the CI target has been achieved. Keep #29562 open until comparable CI evidence confirms the result.

Validation and review

  • Full normal and race owning packages: hakeeper, logservice, cnservice.
  • Full race consumers: isolated issues, embed, SQL integration, upgrade, and multi-CN integration; covers bootstrap/repair, WAL recovery, non-leader restore, restart, dynamic CN expansion, startup query readiness, CDC lifecycle/takeover, and two-CN view description.
  • Three new concurrency tests each pass 100 race repetitions: startup/in-check notification coalescing, shutdown safety, and admission-triggered authoritative refresh. Existing lost-response/ack/BatchID/command-ID assertions are retained.
  • New pure RSM cases cover stable unrelated fields, replica 1-to-2 reporting, barrier evidence re-observation, generation rollback before activation, rejected stale generations, and one-time de-admission on protocol downgrade.
  • Changed-package vet, repository-pinned incremental golangci-lint (zero issues), formatting, diff checks, and make err-check pass.
  • Design and final independent read-only review: gpt-6.1-sol / xhigh, PASS, zero blockers.
  • Mergify's existing main update is preserved. On the updated head, isolated and multi-CN race integration and mergeutil pass. Vector race passes under UTC; under America/New_York, the unchanged main TestRowToString assertion incorrectly formats a negative current timezone offset as an hour instead of converting the epoch date (expected 1970-01-01 -4:00:00 vs actual 1969-12-31 19:00:00). This pre-existing timezone limitation is recorded separately from this change. No agent main merge/rebase is performed.

@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 changed the title perf(plan): reduce reflection work in expression owner traversal Reduce race UT CPU cost and bootstrap polling waits Oct 2, 2026
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Oct 2, 2026

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-review conclusion: APPROVE recommendation, zero blocking findings at 90c71d3bd891550a7b7f343b8bb94fae93b64d8a, against base/merge-base 9078a8bd87af49ea06f52e09d64e7740122aea61. Reviewed every hunk in all eleven files, #29562, prior comments, and the affected producers, consumers, reset/restart and shutdown paths. No subagents.

The design is proportional to the performance problem. Expression traversal is optimized at its existing owner; heartbeat hints originate at the RSM owner after accepted state changes and feed the existing serial checker; CN startup consumes its existing admission notification and refreshes authoritative inventory. There is no second readiness state machine, execution worker, cache, persistent field, wire-format change or configuration switch. Production is +121/-19 (net +102), tests +457/-1 (net +456 across six files), documentation unchanged.

  • Expression traversal: scalar fields/elements cannot contain expression roots. Exported containers, interfaces, map values, aliases, pointer-cycle handling, repeated Expr visits and visitor errors keep their existing semantics. Map keys and named pointers retain their prior behavior. Checked validation after decode, remote-expression feature detection, bound string-domain traversal and planner visitors. Existing/new validation tests remain useful independently of the performance result.
  • HAKeeper hints: compared accepted CN state, including one-time de-admission by a rejected obsolete heartbeat. Stable Tick/load/configuration/address/term/ordinary receipt changes do not generate checker hints. Result.Data remains the existing CommandBatch; the resolved Dragonboat NoOP-session path does not cache the new result hint in persisted client-session state. Lost responses, follower/no-worker stores, and same-count replica replacements retain periodic convergence. Extra checks preserve the configured periodic schedule and absolute bootstrap deadline.
  • CN startup: a notification only advances the next refresh. Fresh inventory still needs the current UUID/address/commit/generation and appropriate query membership. Revocation and bootstrap error/cancellation are checked before and after refresh; failed refresh cannot authorize startup. The raw registration, admission/ingress handoff, authoritative query inventory and public frontend order remain intact.
Unhappy-path invariant Closure
Q1: one effective owner The store owns a capacity-one channel for its lifetime; tickerStopper joins the existing checker/task workers before NodeHost close. CN owns and retires each retry timer.
Q2: waits terminate Notification sends are nonblocking, including nil/disabled and shutdown cases. Existing checker RPC deadlines, stopper cancellation and CN refresh contexts remain effective.
Q3: growth is bounded At most one empty notification waits per store. No retained callback/state cache is added; expression traversal keeps its existing per-call seen set. A queued old hint carries no stale state across local replica restart.

Independent reviewer validation used Go 1.26.4 on darwin/arm64 with a complete native generation built from this head by make -j8 cgo:

  • The new plan-container and RSM accepted-readiness/barrier tests passed in normal mode. Focused race checks passed for checker cadence, bootstrap deadline and failure, acknowledged-command lost response, CN cancellation/refresh failure and admission notifications.
  • Each of TestHAKeeperCheckWakeupCoalescesAfterShutdown, TestHAKeeperCheckWakeupRechecksDuringActiveCheck and TestClusterSelfReadinessUsesAdmissionNotification passed 100 race repetitions in a single process, run individually. JSON measurement was 0/0.14/0 seconds, selecting the 100-repeat cap under the 30-second stress budget. Every command reached terminal exit 0.
  • A reviewer-only Go-overlay test exercised the added notification branch, then returned matching inventory during the second refresh together with upgrade error, owner cancellation, generation revocation or refresh failure. All four rejection cases and the success control passed under race. Repository source/tests were not edited.
  • Formatting, diff checks and the isolated checkout were clean.

Reused current-head CI after verifying SHA, Go 1.26.4 linux/amd64, race invocation, owning-package selection and terminal results in downloaded logs/checkpoints. All four owning packages were selected; embed, isolated issues, SQL integration, multi-CN and upgrade execution stages returned status 0. Existing replica restart/voting-role, recovery and command assertions were preserved. Linux/arm64 SCA, build, coverage and PROXY/pessimistic BVT also succeeded. Compile-only/skipped stages are not counted as execution evidence. The PR's broad normal-package results remain author-reported evidence.

The expression optimization has a separate matched component check: the delivered six-shape benchmark ran sequentially with GOMAXPROCS=1, three 150ms samples, identical native artifacts and fixtures, using only the base production file through a Go overlay for the control. Median ordinary owner traversal was 151.7 → 34.7 μs, wide owner 1.450 → 0.335 ms, and direct Expr 10.46 → 10.45 ns; allocations did not increase in any shape. The same new container tests passed against both implementations. The fixtures/benchmarks cover distinct container, validation and size contracts without weakening existing assertions or introducing another cluster fixture.

Performance acceptance is limited to the demonstrated component improvements. The PR's paired isolated-race 222.90 → 167.63 seconds result is attributed to the author. The completed current CI Unit Testing step took 62m56s; it is not a matched causal comparison and does not establish a ten-minute reduction. Keep #29562 open until its actual CI/CPU/memory target is measured. The projected 2–4 minute saving is not treated as an observed result.

There are no earlier actionable review findings or unresolved threads. The authenticated account is also the PR author (XuPeng-SH), so GitHub permits this submitted COMMENT but not a formal self-APPROVE. This records the completed code-review recommendation and its evidence.

This branch was previously deployed

1 inactive deployment
ci — 8dc48eb5 Deployed Oct 2, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants