Skip to content

fix(hakeeper): retry pending TN start operators [4.2-dev] - #30444

Merged
XuPeng-SH merged 4 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:fix/30443-tn-command-redelivery-4.2
Oct 17, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:fix/30443-tn-command-redelivery-4.2

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 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:

Refs #30443. Parallel main fix: #30445.

What this PR does / why we need it:

A lost committed heartbeat response or a later unrelated legacy scheduling batch can discard a TN startup command. The controller owns its unfinished operator but previously dispatched only fresh operators, delaying recovery until the initial-shard timeout.

Retry the existing singleton TN-add operator on each healthy checker pass. Its checker owns placement reservations and termination by reported startup, target loss, cancellation, or teardown; it does not allocate another replica for a pending shard. Different-ID reports cancel stale intent. Other operator kinds retain their existing expiry policy.

A TN retry also preserves currently desired Log work that the Log checker suppressed as already executing. The owner-local projection reuses the existing parser for voting/nonvoting add, remove, start, and bootstrap candidates. It checks current epochs, working targets, add-slot bounds, and partial bootstrap progress; main also reuses its existing storage-incarnation exclusion. It does not replay retained TN removals or unrelated one-shot commands. Existing Log/TN pointers are admitted and emitted once per retry cohort using temporary linear pointer sets; ordinary fresh batches keep their normal admission cost.

The RSM matches the target base byte for byte. Historical heartbeat consumption and snapshot replay are preserved. No Raft, protobuf, activation protocol, persistent queue, timer, worker, or SQL-path change is introduced. The additional candidate parsing/temporary pointer sets run only when a registered TN start requests a retry.

Validation

Base: e2c99334fd23b9260728695e29befd35ab26b454; Linux/amd64, Go 1.26.4, matching branch native inputs.

  • Relevant owning packages passed normal UT and go test -race -count=1: coordinator/checkers, Log checker, operator; unchanged HAKeeper/TN-checker behavior retains matching-source prior normal/race evidence.
  • Real Coordinator → RSM → Log heartbeat regression covers pending TN, an already-running TN control, already-consumed Log response, and completion after a real report. The V2 mixed-service loss was reproduced before correction; clean 4.2 base passed its control.
  • Candidate tests cover all seven suppressed Log step kinds, stale membership/epoch/role, expired/missing targets, add-slot bounds, partial bootstrap, current-step progression, and terminal operations. Repeated cohorts retain one registration per pointer; obsolete TN removal is excluded. Main additionally checks changed storage incarnation and mixed Preparing/Enabled command identity.
  • Real LogService start/bootstrap/add/nonvoting-add/remove fixtures passed normal and race with duplicate deliveries. Existing matching-source TN receiver evidence covers duplicate/different-ID starts and cancellation/close.
  • Incremental SCA: 0 new issues across all seven affected packages. go vet and molint passed for changed owning packages/receiver. Frozen historical snapshots still use unchanged RSM production code; prior recovery/replay evidence remains valid.
  • Unfiltered lint has four existing prealloc suggestions in unchanged operator/builder.go; the identical diagnostics were reproduced on the clean target base. They are not incremental findings.
  • Independent design and final overall review: gpt-6.1-sol / xhigh.

Retries require eventual delivery and viable targets. Existing epoch checks and replica identity make eligible control-plane retries idempotent; this is not an exactly-once guarantee. The fix preserves the extra TN-retry batch, without redesigning historical replacement between unrelated fresh batches. Performance evidence is structural and bounded command/operator assertions; no SQL benchmark or live rolling-upgrade test was run. The original CI incident's precise lost-response mechanism remains unproven. CI was not rerun or waited on.

@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 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 505f6ddaa958927034c78b0a9d0537d255ebba36

Review completed. Read the assessment.

@mergify mergify Bot added the kind/bug Something isn't working label Oct 17, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Oct 17, 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.

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

Commit: 505f6ddaa958927034c78b0a9d0537d255ebba36

Assessment: request_changes

Reviewed the complete delta and producer/RSM/receiver lifecycle. Retaining bounded intent in ScheduleCommands is a coherent design, but heartbeat acknowledgment breaks the supported stop-then-start ordering contract.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

  • P2 pkg/hakeeper/rsm.go:629: An accepted controller batch contains StopReplica(shard=2, replica=10) followed by StartReplica(shard=2, replica=11) for the same TN. Its next heartbeat still reports replica 10.
    Impact: The shard-only match discards the later start while delivering the preceding stop. The TN therefore removes its working shard without receiving the requested restart, and no pending start remains. Account for preceding stop/removal commands before treating the heartbeat as completion of a later start.
    Evidence: TestReviewControllerOrderedRestart reproduces this through Controller.Dispatch and RSM Update/heartbeat entrypoints: candidate fails, exact base rsm.go control passes. Receipts: checks/1792195976158256475-4.json (exit 1) and checks/1792196018753409130-3.json (exit 0); corresponding head-controller-probe.log and base-controller-probe.log. The added stop-then-start table case uses an empty heartbeat and misses this reported-old-replica state.

Validation:

  • Isolation preflight passed; native prerequisites were built through repository Makefiles from fingerprinted frozen inputs. Source remained unchanged.

  • Full race suites passed for hakeeper, operator, TN checker and tnservice; five focused logservice integration tests passed.

  • TestStartReplica passed 100 race repetitions. Changed-package go vet, formatting and diff checks passed.

  • Commands, source fingerprints, exit receipts, terminal logs and diagnostic overlays were reconciled in /home/xupeng/.local/state/mo-bot/jobs/2f2e9549bcad08b99e6d21f3/attempt-1/evidence-audit.json. Audit receipt: checks/1792196133832844264-4.json.

Limitations:

  • The regression is an accepted ordered-batch contract failure reproduced at controller/RSM entrypoints, not a reproduction of the reported CI incident.

  • Mixed-version HAKeeper rollout and full distributed-cluster behavior were not tested; the linked issue body was absent from frozen evidence.

  • No performance benchmark was run. Added merging and retries affect control-plane work; SQL execution paths are unchanged.

@XuPeng-SH XuPeng-SH changed the title [4.2-dev] fix(hakeeper): retain TN starts until shard readiness fix(hakeeper): retry pending TN start operators [4.2-dev] Oct 17, 2026
@XuPeng-SH

XuPeng-SH commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 9a558c2f33cc8b63fa70efcc967a5d6c5a190fd5

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: 9a558c2f33cc8b63fa70efcc967a5d6c5a190fd5

Assessment: request_changes

Reviewed the complete 12-file delta and producer/receiver lifecycle. Keeping retry ownership in the existing controller and restoring base RSM semantics is reasonable, but TN-only retry batches introduce a confirmed log-command delivery regression.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

  • P2 pkg/hakeeper/checkers/tnservice/check.go:104: A checker pass schedules both a TN start and a log-replica start. The TN remains unreported, and the healthy log target sends its next heartbeat after another checker pass.
    Impact: The new TN-only retry batch replaces the RSM's entire pending-command map, discarding the undelivered log start. The log checker suppresses re-emission while its operator remains active, delaying recovery until the generic 15-second expiry. Retry scheduling must preserve unrelated pending delivery; add mixed-service regression coverage.
    Evidence: TestReviewTNRetryPreservesPendingLogStart exercises Coordinator.Check → RSM.Update → log heartbeat, following healthCheck's nonempty-batch proposal rule. Candidate returns no log command; restoring all changed production files to the base preserves it. The TN-already-running control passes both. Retained candidate-delivery.log/base-delivery.log and receipts checks/1792200683594918148-4.json (exit 1) / checks/1792200708300237427-3.json (exit 0) reproduce the difference.

Validation:

  • Isolation preflight passed. Native inputs and library hash matched the repository build inputs; source remained unchanged.

  • Independently reconciled exact-candidate retained normal/race and vet/molint runs for checker/operator packages, plus five-package incremental SCA reporting zero new issues.

  • Verified RSM production source is identical to the target base, closing the earlier heartbeat-ordering concern.

  • Commands, fingerprints, overlays, exit receipts and logs are reconciled in /home/xupeng/.local/state/mo-bot/jobs/57e19f5e4af7461720d62128/attempt-1/final-evidence-audit.json; audit receipt checks/1792200788756701300-4.json exited 0.

Limitations:

  • The regression uses production coordinator/RSM entrypoints, not a full distributed cluster or live rolling upgrade.

  • Performance assessment is structural: bounded retry state and additional control-plane work; no timing benchmark or direct SQL-path change.

  • The linked issue body was absent from frozen evidence; its stated contract was assessed from the PR description. Substantive CI jobs were pending.

@XuPeng-SH

XuPeng-SH commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: b45a8008eab510dca4a72811fd1543be99749da8

PR closed or head changed

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

Review result

I re-reviewed head b45a8008eab510dca4a72811fd1543be99749da8 against 4.2-dev. I found no remaining blocking issue.

The two earlier findings are closed:

  • The ordered TN stop-then-start case preserves both commands when the heartbeat still reports the old replica. Verified through Controller → RSM → heartbeat.
  • A TN retry no longer drops suppressed pending Log work. Verified all seven pending Log command kinds (voting/non-voting start, add, remove, and bootstrap) through Coordinator → RSM → Log heartbeat. A negative control with the preservation branch disabled fails all seven assertions.

The exact-head local race run passed 12 top-level tests and 44 subtests across the affected checker, logservice, and operator packages. Exact-head CI run 38993706116 passed SCA, UT racing, coverage, and both multi-CN BVT jobs.

The implementation keeps retry ownership in the existing operator controller and reuses Log checker candidate rules; it adds no persistent or wire state. The extra work is in the HAKeeper control plane while a TN start is pending. No scale benchmark, mixed-version rollout, or full distributed packet-loss reproduction was run.

No blocking findings.

Copy link
Copy Markdown
Contributor Author

继续实测验证(2026-10-17):

4.2-dev ac27db31696c0394ab1b2787b7b0a8f4933f088f(Go 1.26.4):checkers/coordinator、TN checker、Log checker、operator 完整普通与 race 测试均通过;真实 Coordinator → RSM 丢响应/批覆盖/重试与报告收敛测试实际执行通过。历史 RSM 重放和 bootstrap 重投对照也通过。LogService 重复 start/bootstrap/add/nonvoting-add/remove 及 TN 重复/不同 ID start 的 receiver 回归,普通与 race 均通过。均为 Linux/amd64、匹配分支 CGo 产物。

main a322466757b9b0165c59fbda565608653d923b2a(Go 1.27.1):用真实 operator producer 生成 TN StartReplica 后,丢弃首个已提交的心跳响应;-race 诊断再次确认 legacy 模式首次返回 1 条、第二次返回 0 条,仍失败。Preparing 和 Enabled 两个对照均连续返回 1 条,通过。该诊断不把 Coordinator 周期重试与 RSM 内保留混为一谈。

结论:#30444 的 4.2 修复已验证;main 对应 #30445 仍未合并,整个 #30443 的报告范围尚未全部解决。保留 @XuPeng-SH 开发指派,不整体转测。仍使用 #30443 跟踪,没有为同一缺口新建重复 issue。

XuPeng-SH added a commit that referenced this pull request Oct 17, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

Refs #30443. Parallel 4.2-dev fix: #30444.

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

A lost committed heartbeat response or a later unrelated legacy
scheduling batch can discard a TN startup command. The controller owns
its unfinished operator but previously dispatched only fresh operators,
delaying recovery until the initial-shard timeout.

Retry the existing singleton TN-add operator on each healthy checker
pass. Its checker owns placement reservations and termination by
reported startup, target loss, cancellation, or teardown; it does not
allocate another replica for a pending shard. Different-ID reports
cancel stale intent. Other operator kinds retain their existing expiry
policy.

A TN retry also preserves currently desired Log work that the Log
checker suppressed as already executing. The owner-local projection
reuses the existing parser for voting/nonvoting add, remove, start, and
bootstrap candidates. It checks current epochs, working targets,
add-slot bounds, and partial bootstrap progress; main also reuses its
existing storage-incarnation exclusion. It does not replay retained TN
removals or unrelated one-shot commands. Existing Log/TN pointers are
admitted and emitted once per retry cohort using temporary linear
pointer sets; ordinary fresh batches keep their normal admission cost.

The RSM matches the target base byte for byte. Historical heartbeat
consumption and snapshot replay are preserved. No Raft, protobuf,
activation protocol, persistent queue, timer, worker, or SQL-path change
is introduced. The additional candidate parsing/temporary pointer sets
run only when a registered TN start requests a retry.

Existing Preparing/Enabled ACK delivery remains the transport owner.
Repeated mixed Log/TN proposals preserve equivalent pending command
identities and queue bounds. Exact ACK retires TN work; a later retry
receives a new identity until a real report arrives, and stale ACK
cannot retire it.

### Validation

Base: `65bcea5d24610dde1a21bb9f4dea1efd82a8ce50`; Linux/amd64, Go
1.27.1, matching branch native inputs.

- Relevant owning packages passed normal UT and `go test -race
-count=1`: coordinator/checkers, Log checker, operator; unchanged
HAKeeper/TN-checker behavior retains matching-source prior normal/race
evidence.
- Real Coordinator → RSM → Log heartbeat regression covers pending TN,
an already-running TN control, already-consumed Log response, and
completion after a real report. The V2 mixed-service loss was reproduced
before correction; clean 4.2 base passed its control.
- Candidate tests cover all seven suppressed Log step kinds, stale
membership/epoch/role, expired/missing targets, add-slot bounds, partial
bootstrap, current-step progression, and terminal operations. Repeated
cohorts retain one registration per pointer; obsolete TN removal is
excluded. Main additionally checks changed storage incarnation and mixed
Preparing/Enabled command identity.
- Real LogService start/bootstrap/add/nonvoting-add/remove fixtures
passed normal and race with duplicate deliveries. Existing
matching-source TN receiver evidence covers duplicate/different-ID
starts and cancellation/close.
- Incremental SCA: **0 new issues** across all seven affected packages.
`go vet` and `molint` passed for changed owning packages/receiver.
Frozen historical snapshots still use unchanged RSM production code;
prior recovery/replay evidence remains valid.
- Independent design and final overall review: `gpt-6.1-sol` / `xhigh`.

Retries require eventual delivery and viable targets. Existing epoch
checks and replica identity make eligible control-plane retries
idempotent; this is not an exactly-once guarantee. The fix preserves the
extra TN-retry batch, without redesigning historical replacement between
unrelated fresh batches. Performance evidence is structural and bounded
command/operator assertions; no SQL benchmark or live rolling-upgrade
test was run. The original CI incident's precise lost-response mechanism
remains unproven. CI was not rerun or waited on.

This branch was previously deployed

1 inactive deployment
ci — 52e267b1 Deployed Oct 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 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