Skip to content

feat(hakeeper): implement catalog metadata capability barrier (#29004) - #29060

Merged
XuPeng-SH merged 12 commits into
matrixorigin:mainfrom
ck89119:issue-29004-impl-main
Sep 19, 2026
Merged

XuPeng-SH merged 12 commits into
matrixorigin:mainfrom
ck89119:issue-29004-impl-main

Conversation

@ck89119

@ck89119 ck89119 commented Sep 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:

Fixes #29004. Parent: #26227.

What this PR does / why we need it:

Completes the #29004 control-plane implementation following merged design PR #29049: approved revision 2d7420cdfc, XuPeng-SH approval 5233521645. This replaces the initial partial-checkpoint description; the runtime implementation is now included.

Implementation

  • Independent decoder obligation: update tag 23 retains floor 1 even for rejected/malformed requests. RSM field 46 and MOH3 feature bit 2 remain independent of business phase and the existing persisted-expression floor. Recovery validates feature/state agreement and durable evidence before publishing any state.
  • Replicated membership arbitration: allocator CAS; fence acquire/takeover/release/atomic consume; durable reservations; complete voting/non-voting membership and advanced config-index reconciliation. Incarnation revocation is sticky; timeout is not completion evidence.
  • Durable local execution: maintenance latch, serialized STARTING/STARTED/REVOKING/REVOKED supervisor, independent start permits, cancellation/redelivery, and restart recovery. Retirement can stop a failed restart without first completing it. HAKeeper replicas recover before data-shard zombie checks; retired permits and obsolete restart metadata are reclaimed.
  • Six-phase barrier: independent E/R/C, exact target-generation acknowledgements, fixed receipt slots and recovery-claim fencing. Supersession captures new participants without discarding unretired owners. Explicit trusted retirement proofs unblock replaced/deleted owners; pre-activation seal evidence does not retire authority issued after ACTIVATED.
  • CN/Proxy participation: generation-addressed monotonic observations, independent acknowledgements, and the legacy persisted-expression scalar mirror. Generic heartbeat observation cannot manufacture seal/retirement completion or bypass existing decoder-floor withdrawal.

Deployment and ownership boundaries

  • CatalogMetadataMaintenance defaults to false. First protocol entry requires the approved controlled maintenance cutover: stop legacy executors/HAKeeper processes, prevent old restart, restore admitted replicas with supporting binaries, and discard no-token legacy schedules. This is not zero-downtime mixed-version activation.
  • There is no automatic Begin or public SQL activation API. CN/Proxy advertise observation support, not ViewDependency/Recovery support; LogStore advertises barrier support only behind the maintenance gate.
  • View lifecycle remains runtime-disabled; MetadataReadsEnabled remains false. Catalog transactions/outbox producers belong to [Subtask]: Implement durable View metadata generations and recovery #29005; public authority/drain/retirement producers belong to [Subtask]: Validate and harden on-demand View metadata execution and plan reuse #29006. This PR implements their internal consumers and control contracts, not synthetic business completion.

Validation

Initial runtime validation: 721ec91342, after merging mo/main at 24e66eba12. See the review follow-up below for the current candidate. Darwin/arm64, Go 1.26.4, worktree-local native artifacts and that worktree's mo-cgo-test wrapper.

  • Full normal tests with coverage: passed for pkg/hakeeper, pkg/pb/logservice, pkg/logservice, pkg/cnservice, and pkg/proxy.
  • Catalog/snapshot race tests across all five packages: passed.
  • Race ×100: atomic participant observations, serialized start/cancel, retirement overtaking failed restart, and late-participant/retirement progress: passed.
  • Full race tests for all five owning packages: passed; final -vet=all -run '^$' checks: passed (the latter are vet-only evidence).
  • Changed coverage blocks, statement-weighted and excluding generated/test code: 981/1117 = 87.82%. New implementation files range from 80.93% to 100%; evidence validator and participant helper are 100%.
  • Incremental golangci-lint 2.6.2: 0 issues. The preinstalled analyzer was built with Go 1.27.1; package loading/compiler/tests/gofmt use Go 1.26.4.
  • License check: 0 invalid. Independent protobuf regeneration is byte-identical; formatting and diff checks pass.
  • Independent implementation review found three concrete defects; regression tests and fixes were added, and the scoped follow-up review is PASS.

Coverage includes real Update/RecoverFromSnapshot failure atomicity, mixed capabilities, rejected-entry floors, stale owner/claim/receipt evidence, complete configuration matching, lost delivery, contradictory retirement acknowledgements, same-UUID replacement, explicit retirement, and real Dragonboat start/stop/restart boundaries.

Earlier selector misses, tool timeouts, sandbox restrictions, and disk-capacity failures are not counted as passing tests. No SQL BVT or CI-success claim is made.

Review follow-up — ab51f14441

Merged latest mo/main at 780ef933f2 and addressed both reported findings:

  • P1: persist the confirmed membership config-change index atomically with completion. Reservations and replica readiness reject heartbeat configurations below this high-water mark; snapshot recovery preserves it and rejects contradictory reservations. Regression tests fail before the fix and pass after it, covering consecutive operations, delayed heartbeats, recovery, eventual successful completion, and fence progress.
  • P2: replace fmt.Errorf with moerr.NewInvalidStateNoCtx, with an error-class assertion. The exact Linux/arm64 CI failure at run 35225175541/job 105214874658 was verified and reproduced locally (make err-check exit 2); the corrected make err-check passes. The previous golangci result did not cover this separate repository gate.

New validation: HAKeeper/PB/LogService full normal tests with -vet=all and coverage; targeted race ×20 including the real executor lifecycle; molint for the affected three packages; incremental golangci for all five PR packages. All passed. Both pinned analyzers were rebuilt with Go 1.26.4, matching CI. Changed-block coverage in the three retested packages is 969/1104 = 87.77% (not a new five-package measurement). Independent protobuf regeneration remains byte-identical. The additional full-tree license rerun timed out locally; the only new file's header is byte-identical to the previously validated runtime header, and no new license-run success is claimed.

Review follow-up — tokenless stale schedules

A second tokenless membership command at the same epoch could remain pending forever after the first command advanced the confirmed configuration. The RSM now reclaims only tokenless HAKeeper membership commands whose epoch is strictly below ConfirmedConfigChangeIndex, both when successful replicated state makes them obsolete and when recovering snapshots written by the buggy version. Commands with a live token still use reservation identity; commands at the confirmed or a future epoch remain pending.

The deterministic regression uses the real queue, heartbeat delivery, Update completion, hasPendingHAKeeperAdmission, and RecoverFromSnapshot paths. It proves cleanup after completion, migration of inherited stale snapshots, and retention controls for equal/future epochs.

A follow-up closed the remaining admission edge: UpdateCommands now applies the same terminal-obsolescence predicate before queue lookup, deduplication, ID allocation, or append. The regression submits a late stale command through real Update after completion and immediately proves an empty queue and unblocked admission—without heartbeat, another catalog operation, or restart. The inherited-snapshot case now constructs legacy residue directly rather than using the fixed admission path.

The final review follow-up covers epoch-zero execution commands. Tokenless start commands survive only for the exact admitted, non-revoked identity and role. Tokenless stop/kill commands survive only for an exact active member, an unfinished retirement permit, or a locally observed pre-cutover zombie; KillZombie is rejected for admitted members. Removed/retired or role-mismatched identities are reclaimed at Update, completion, and snapshot recovery boundaries. Regression coverage uses real Update, heartbeat delivery, and RecoverFromSnapshot, with positive controls for an unfinished retirement stop and an observed legacy zombie. HAKeeper full normal+vet passed at 86.2% package coverage; focused race ×50 and Go1.26.4 incremental lint passed.

@ck89119 ck89119 changed the title [WIP] feat(hakeeper): implement catalog barrier runtime contracts (#29004) feat(hakeeper): implement catalog metadata capability barrier (#29004) Sep 17, 2026
@ck89119
ck89119 requested a review from XuPeng-SH September 17, 2026 13:07
@matrix-meow matrix-meow added size/XXL Denotes a PR that changes 2000+ lines and removed size/M Denotes a PR that changes [100,499] lines labels Sep 17, 2026

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 blocker at pkg/hakeeper/catalog_metadata_schedule.go:78-93: an admitted StartReplica/StartNonVotingReplica command without a permit can survive membership removal and retirement. The cleanup predicate handles tokenless add/remove commands and permit-bearing start commands, but not this tokenless start command. Delivery then rejects the removed replica while the command remains pending; snapshot/restart reuse the same predicate. This can keep hasPendingHAKeeperAdmission true and block later persisted-expression activation. Please reclaim the command using the removed/retired replica identity and add real Update, heartbeat-delivery, and snapshot-recovery regression coverage. Current head and CI were verified at ab94e11.

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codex automated review

Deep first-principles review of the control-plane barrier implementation (RSM arbitration runtime, schedule prepare/obsolete/attach paths, snapshot codec floors, logservice executor state machine, CN/proxy participant observation, heartbeat plumbing, recovery and fencing logic). The implementation is internally consistent: the whole runtime is dormant without an internal tag-23 entry (no public producer exists, matching the documented deployment boundary), decoder-floor retention on rejected entries is deliberate and validated, snapshot feature gating (MOH3 + runtime feature bit) is coherent, staged-validate-then-commit in handleCatalogMetadataRequest keeps rejected entries atomic, the executor's durable latch/serialized STARTING/STARTED/REVOKING/REVOKED supervisor handles crash and redelivery correctly, lock ordering (catalogExecutor -> store mu) is consistent, and heartbeat-driven state transitions are deterministic within replicated entries. Test coverage is extensive, including unhappy paths, snapshot corruption, race scenarios, and the previously reported P1/P2 fixes. I independently re-verified the outstanding CHANGES_REQUESTED finding from XuPeng-SH at head ab94e11 and confirm it is valid and unaddressed: catalogScheduleObsolete (pkg/hakeeper/catalog_metadata_schedule.go:68) never reclaims tokenless StartReplica/StartNonVotingReplica commands, so after membership removal such a command is undeliverable (prepareCatalogSchedule cannot grant a permit for a removed/revoked member) yet remains pending forever, keeping hasPendingHAKeeperAdmission true and blocking persisted-expression/view-admission progress. The same predicate gap also covers tokenless StopReplica/KillZombie remnants for removed replicas (e.g. when prepareCatalogStop's REVOKE_START is rejected), so the fix should reclaim by removed/retired replica identity for all tokenless HAKeeper config-change command types, not only start commands. Per review policy this is not duplicated as a new finding; the PR should not merge until that existing requested change is resolved. No additional blocking or non-blocking findings from my review.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Astra medium deep review at exact head a34095a.

此前 P2 finding 已闭合:catalogScheduleObsolete 现在按 replica ID、UUID、role 和 revoked 状态回收 tokenless epoch-zero StartReplica/StartNonVotingReplica;membership removal 不再依赖被移除 store 的后续 heartbeat。StopReplica/StopNonVotingReplica/KillZombie 的 retirement/permit 语义也已闭合,真实 zombie 仍保留必要清理路径。

同一 obsolete predicate 已覆盖 UpdateCommands admission、catalog commit 后 prune、heartbeat delivery 前过滤和 snapshot recovery。新增回归覆盖真实 Update、heartbeat、RecoverFromSnapshot,验证残留清理与 hasPendingHAKeeperAdmission()==false,并保留 unfinished retirement 和 observed zombie controls。

已复查完整 diff 及 RSM arbitration、prepare/obsolete/attach、snapshot floor、executor/latch、CN/proxy heartbeat、recovery/fencing、锁顺序、失败/重放/清理和状态有界性,未发现新增 P0/P1/P2 缺陷。注意 hasPendingHAKeeperAdmission 只统计 add/start,不直接统计 stop/kill。

exact-head CI 已通过,race short matrix artifact 确认五个相关包实际执行且 status=0。维护切换及未来 producer 的端到端验证不在本次结论内。

APPROVE。

@mergify mergify Bot added the queued label Sep 19, 2026
@mergify

mergify Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-19 15:33 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-19 15:35 UTC · at 7cbd3281a9c9597b4acc4a33179405864cee6521

This pull request spent 1 minute 31 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

This pull request seems to come from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request, or update the branch manually.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Subtask]: Implement HAKeeper catalog metadata capability barrier

4 participants