Skip to content

[4.2-dev] fix(logservice): harden HAKeeper retry and shutdown - #32847

Merged
XuPeng-SH merged 2 commits into
4.2-devfrom
fix/30420-hakeeper-reset-42dev
Nov 17, 2026
Merged

XuPeng-SH merged 2 commits into
4.2-devfrom
fix/30420-hakeeper-reset-42dev

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 17, 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:

Related to #30420 (native-reset fix on main: #30426) and #28452 (related HAKeeper transport recovery).

Related: #32825 and its failed UT run.

What this PR does / why we need it:

A native connection reset can escape HAKeeper recovery during ID allocation, making an operation such as CREATE DATABASE fail. Recognize wrapped ECONNRESET and the relevant typed backend connection errors in the existing retry path; preserve the MORPC backend-creation timeout sentinel as a non-retryable result.

Keep client ownership in the managed client: closing it now ends admission and wakes retry waiters, and a late failure only resets the client generation that actually failed. This prevents a retry from recreating a client after Close and prevents a stale failure from closing its replacement. Honor cancellation before issuing cached IDs or publishing a newly constructed client, and pass the caller context through reverse-proxy discovery while retaining discovery's own RPC options.

For callers with an explicit MORPC backend-wait deadline, newly retryable transport failures return their original error after the current failed attempt rather than starting another HAKeeper-level dial. Existing EOF/NoHAKeeper retry behavior is preserved. An already-running synchronous dial or client cleanup can still overrun a caller or backend-wait deadline; this PR does not claim a hard end-to-end timeout. Lost allocation responses can still produce ID gaps, and the initiating server-side reset in the reported CI run is not established.

Validation on 10.222.1.57, Linux/amd64, Go 1.26.4 and matching CPU CGo libraries:

  • Reproduced retry after Close and late-generation failure; regression coverage exercises terminal close, concurrent callers, cleanup errors, context cancellation and recovery, including a real MORPC backend-creation timeout.
  • pkg/logservice in normal and race modes (-short -tags matrixone_test -count=1): 307 passing root tests / 463 named passes, zero failures and one existing skip in each mode. Each of 17 changed/new roots also passed 100 race repetitions.
  • Existing three-CN TestTableFeatures passed with race and its original topology and assertions; existing MORPC backend-wait and HAKeeper ID-state-machine controls passed under race.
  • Formatting/diff checks, vet, pinned molint and incremental golangci-lint passed for the owner and direct constructor/consumer closure (nine packages).

The logservice suites used isolated user/network namespaces after a pre-existing host listener prevented an unrelated Gossip test from binding its port; no test assertion or port was changed. Cached ID admission adds a context/close check under the existing lock; a single-CPU microbenchmark measured roughly 2 ns/op extra and zero allocations, not an end-to-end throughput measurement.

CI for the updated head is pending.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 4f0b74fd633adca92a360143ccda7cf97c6c9f16

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 4f0b74fd633adca92a360143ccda7cf97c6c9f16

Assessment: approve

Native and wrapped ECONNRESET now reuse existing HAKeeper recovery without adding state or separate retry machinery. No actionable correctness or design findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed the complete delta, relevant owners and consumers, linked issue, and all three discussion entries.

  • Logservice suite passed with -race -short -tags matrixone_test: 426 named passes and one skip.

  • Each of six changed/new test roots passed 100 race repetitions.

  • Exact baseline production overlay failed only the native/wrapped-reset assertions; neighboring classifier controls passed.

  • Package build, vet, gofmt and git diff --check passed. Source/native provenance, commands, exits and retained logs are reconciled in validation-reconciliation.json; final receipt: checks/1794902635410294120-2.json.

Limitations:

  • Frozen CI remained pending.

  • Transport errors were injected; the initiating cause of the earlier CI peer reset remains unestablished.

  • Four incomplete dependency/build attempts are retained separately and excluded from passing validation.

Backport wrapped ECONNRESET recovery from main commit 47b9690 (#30426).
Reuse existing client replacement, context and retry waits. Extend the
existing allocation fixtures for reset, deadline and cancellation controls.

Related to #30420.
@XuPeng-SH
XuPeng-SH force-pushed the fix/30420-hakeeper-reset-42dev branch from 4f0b74f to 3644b98 Compare November 17, 2026 10:00
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Nov 17, 2026
@XuPeng-SH XuPeng-SH changed the title [4.2-dev] fix(logservice): retry native HAKeeper connection resets [4.2-dev] fix(logservice): harden HAKeeper retry and shutdown Nov 17, 2026
@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 3644b98d38d6829fcb3852b02e69eb9427ddf302

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 3644b98d38d6829fcb3852b02e69eb9427ddf302

Assessment: approve

Recovery remains in the managed client. Terminal close notification and generation snapshots address the lifecycle races without a separate retry engine; timeout classification and discovery boundaries remain intact. No actionable defect found.

Model: gpt-6.1-sol / max

Session: 01a1e395-a6d9-7ad1-bf20-81f1c6210100 · slot 2 · generation 0

Validation:

  • Reviewed the complete four-file delta and traced managed request/ID paths, MORPC timeout/cleanup, reverse-proxy discovery, consumers and unchanged ID-state-machine semantics.

  • Reused the current author's reported normal/race logservice results (307 roots, 463 named passes, one existing skip), 100 race repetitions per behavioral root, original three-CN TestTableFeatures and MORPC/ID controls. Older-head validation was not reused for new lifecycle code.

  • Local gofmt and source/diff/discussion audits passed. validation-reconciliation.json matches command/source/exit receipts with retained logs.

Limitations:

  • Frozen current-head CI is pending. No local Go/native/SQL/benchmark rerun was performed; author execution reports lack raw local_validation artifacts.

  • Synchronous construction or cleanup can overrun caller/backend-wait deadlines; no hard end-to-end timeout is established.

  • Lost allocation responses can leave ID gaps. Injected transport failures do not establish the cause of the original CI peer reset.

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

Independent deep review of 3644b98 against 4.2-dev / 8c77e14.

Verdict: REQUEST_CHANGES — one validation blocker.

[P2] Complete the committed unhappy-path coverage and pass the required coverage gate. The current-head coverage job fails with 122/188 modified lines covered (64.89%), required >75%. This is a completed threshold failure. The coverage manifests and downloaded final/debug artifacts identify this head. The merged profile leaves changed preparation/retry and reset/cleanup branches uncovered, including GetCNState, GetBackupData, and the non-voting replica management methods. Extend the existing lightweight lifecycle/RPC fixture with named public-method/error cases and result/error, no-extra-construction, and exact-close-count oracles. Repeating already-covered roots 100 times does not cover these missing behaviors. No new embedded cluster or reduced threshold is needed.

Design and implementation assessment:

  • The existing managed client is the right owner for admission, terminal close, transport publication and generation-conditional reset. The change repairs those responsibilities without adding a separate retry executor or background worker. The old prepare/get split was replaced coherently.
  • Native/wrapped reset and selected typed failures reuse the existing recovery path. Caller cancellation, application failures and the distinct MORPC creation-timeout sentinel remain outside positive retry classification.
  • Cached-ID admission, stale-generation failures, unpublished-client cleanup, concurrent Close, and completed-result/error precedence are coherent in the reviewed source and evidence. I found no additional confirmed production correctness defect.
  • The optional backend budget handling deliberately retains the existing EOF policy and stops only newly introduced retry classes from adding another managed attempt. Synchronous dial/cleanup and mutex waits can still exceed that budget. This is a documented scope limit; it must not be advertised as a hard end-to-end timeout.

Ownership and unhappy-path check:

Boundary Review result
Create/publish/reset/close One effective cleanup owner; a stale generation cannot close its replacement; closed managers cannot reopen.
Cancellation/retry/waits Retry waits observe context/terminal close. Existing synchronous construction, cleanup and allocator locking retain their documented latency limits.
Retained state/resources One lazy close signal/current transport per manager; no new worker, queue, or unbounded collection. Existing keyed cache and server ID semantics remain unchanged.

Validation:

  • Worked on 10.222.1.57, with HOME-owned temporary/build directories; no subagents.
  • Read all four changed files' complete deltas, linked issues, all discussions and both existing reviews. There are no outstanding human/inline review comments. Earlier design-review concerns about timeout identity, budget claims and discovery options are addressed within the stated scope.
  • Audited and reused author normal/race owner evidence (307 passing roots / 463 named passes, one existing skip per mode), focused race stress, MORPC/ID controls, and existing three-CN feature validation. Current-head CI UT, SCA, shared build and both BVT deployments passed.
  • Independently ran an overlay-only QA matrix through the real managed-method/request paths with injected RPC errors: 15 public methods x 6 scenarios = 90 leaf scenarios, all passed under -race, exit 0. Covered closed/canceled entry, preparation retry, native send reset, Close during a native failure, and preservation of an in-flight application error. These reviewer probes are not committed PR tests and do not turn its coverage gate green.
  • Audited the retained single-CPU cached-ID benchmark: approximately 7.2 ns/op to 9.3 ns/op, zero allocations. This is a small absolute admission-check cost; service-level throughput and contention were not measured.
  • No wire/catalog/disk format changes. Lost ordinary allocation responses can still create ID gaps; the initiating peer reset and general heartbeat command-response loss remain outside what this PR proves.

The PR body still says CI is pending; update it after the coverage gap is addressed. Production, tests and branch contents were not changed by this review.

GitHub review-state limitation: the authenticated account is also the PR author. GitHub rejected the formal REQUEST_CHANGES submission (HTTP 422: cannot request changes on your own pull request). This COMMENT review records the blocking assessment; it is not a formal changes-requested state.

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

Clarification following the user's review-scope instruction: excluding the coverage threshold, my assessment of 3644b98 is APPROVE / no production-code blocker found.

The prior review's only blocking finding was the required CI coverage threshold. No additional confirmed correctness, ownership, lifecycle, or design defect was found in the complete review and the independent 90-scenario race QA matrix on host 57. The managed client remains the appropriate owner, and the implementation does not introduce a separate retry executor or worker.

The stated limits still apply: synchronous construction/cleanup and allocator mutex waits do not provide a hard end-to-end timeout; ordinary lost allocation responses may leave ID gaps. The cached-ID microbenchmark adds approximately 2 ns/op with zero allocations; this does not establish service-level throughput or contention performance.

This is a code-review assessment with coverage excluded, not a claim that the failed CI gate passed or that repository merge requirements have been waived. GitHub cannot accept a formal APPROVE from the PR author's own account, so this clarification is recorded as a COMMENT review.

This branch had an error being deployed

1 failed deployment
ci — 3644b98d Deployed Nov 17, 2026 by XuPeng-SH
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 kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants