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? |
2be15cb to
974fded
Compare
974fded to
302a504
Compare
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
Found four blocking recovery-safety bugs and two material limit issues. Focused tests were blocked locally by missing CGo headers.
P1 - Require a clean destination before initializing replay state (pkg/logservice/wal_recovery.go:800)
When no state file exists, BaseLSN and LastLSN are initialized to the destination's current latest LSN. Existing records are therefore treated as baseline, and the old WAL is appended after them and marked complete. The bootstrap path can run after HAKeeper and the Log shard are already initialized, so a restart or late recovery can silently duplicate WAL history instead of failing closed.
P1 - Reject recovery after HAKeeper has entered Running (pkg/hakeeper/rsm.go:808)
RestoreIDWatermarkUpdate sets LogServiceRecoveryPending even when the current state is HAKeeperRunning. The Running transition guard only applies while the current state is BootstrapCommandsReceived, and Running has no transition back to a gated state. With staggered startup, HAKeeper can reach Running from a quorum before the recovery pod heartbeats; the late pod then starts replay while the cluster is serving.
P1 - Invalidate the cached ID allocator after restoring watermarks (pkg/logservice/store_hakeeper_check.go:142)
This updates the replicated HAKeeper watermark but leaves l.alloc unchanged. updateIDAlloc preallocates a 10,240-ID range, and getScheduleCommand reuses any remaining range with capacity >=1024. If bootstrap scheduling allocates a low range before a late recovery pod applies a higher backup watermark, those cached low IDs are handed out after recovery and can collide with IDs referenced by restored data.
P1 - Fence user appends during WAL replay (pkg/logservice/wal_recovery.go:878)
Replay sends APPEND requests via doAppend, while the recovery status only gates HAKeeper state and ID allocation. LogService's normal append handler has no recovery-pending fence, so another valid writer can insert a user record between replay entries. The reconciliation loop explicitly rejects such records as unexpected or mismatched, leaving recovery failed and HAKeeper pending.
P2 - Bound accepted WAL entries by the actual RPC message limit (pkg/logservice/wal_recovery.go:51)
The parser accepts RawData up to defaultMaxMessageSize (100 MiB), but the recovery client uses cfg.RPC.MaxMessageSize and morpc validates RPCRequest.ProtoSize(), which includes the protobuf request plus the APPEND command header and payload. Thus an entry at the parser limit, and entries near it under the default RPC limit, are accepted from disk but rejected before transmission.
P2 - Avoid loading the full recovery artifact into memory (pkg/logservice/wal_recovery.go:339)
The code permits a 1 GiB file while retaining every RawData slice and WALEntry in memory. A valid artifact with millions of entries adds hundreds of megabytes of slice/struct/allocation overhead on top of the file contents, potentially exhausting a LogService before replay begins.
302a504 to
4af6aed
Compare
TN 持久化启动:不采纳。 离线恢复明确要求 TN 在 WAL 恢复完成前保持停止。修改 TN 通用启动流程会增加正常集群启动风险。 |
jiangxinmeng1
left a comment
There was a problem hiding this comment.
pkg/logservice/wal_recovery_status.go:113
This does not actually wait for every voting replica to report its recovery status. A
store may already exist in LogState.Stores from an earlier heartbeat while ConfigData
is nil or does not contain wal-recovery-status; continuing here allows election from a
partial candidate set.
For example, if store-b reports coordinator-pending first, it can elect itself while a
lexicographically smaller artifact-owning store-a has not published its recovery status
yet. Once store-a reports, it will also elect itself. The destination fence does not
serialize these coordinators when they use the same WAL digest and recovery lease
holder, so both can append the same source entry and corrupt the recovery sequence.
Please return not-ready unless every voting replica has a valid recovery status item,
and add a test where one replica has no status while another replica is coordinator-
pending.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
Found three blocking correctness issues. Focused tests could not build because required C headers are unavailable.
P1 - Existing backup-only restore is rejected without the new recovery flag (pkg/logservice/service_bootstrap.go:178)
With the existing restore.file-path configuration and restore.enabled=false, the initial request carries no recovery intent. If another initial member wins with default IDs, this unconditional watermark restore sends RestoreIDWatermarkUpdate, which HAKeeper rejects whenever LogServiceRecoveryPending is false. Bootstrap then retries and fails, regressing the pre-existing backup restore path.
P1 - Malformed skip records can panic during replay (pkg/logservice/wal_recovery.go:639)
Skip payloads are accepted whenever they are nonempty and a multiple of 16 bytes; DSN/PSN semantics are not checked. The downstream replayer panics when a skip DSN is absent from dsn2PSNMap or appears twice. A structurally valid but corrupt recovery artifact therefore crashes replay instead of failing closed.
P1 - Overlapping DSN ranges are not rejected (pkg/logservice/wal_recovery.go:546)
Cross-entry validation checks Raft indexes and arithmetic overflow but not overlap or duplicate normal DSN intervals. Two normal entries with distinct Raft indexes and the same DSN start pass validation; replay stores only one PSN per start DSN and overwrites the earlier record, allowing recovered WAL data to be silently omitted or applied incorrectly.
jiangxinmeng1
left a comment
There was a problem hiding this comment.
Re-reviewed the latest update. The coordinator election now correctly waits for every
voting replica to publish a valid recovery status, which addresses the partial-election
race. I also reviewed the new WAL sequence and skip DSN/PSN validation and did not find
any further blocking issues. The targeted recovery tests pass.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
Loaded all existing reviews, issue comments, and inline comments (none). Earlier blocking recovery findings are addressed; the retained-TN and truncate concerns are conditional on the explicit offline-recovery precondition. git diff --check passes. Focused Go tests could not run because the Go toolchain is unavailable.
P2 - Bound retained SkipDSN references during WAL scanning (pkg/logservice/wal_recovery.go:480)
Although recovery accepts files up to 10 GiB and streams normal payloads, every SkipDSN payload is decoded into a reference slice and retained in entry.skip until the entire file has been parsed, sorted, and validated. Valid skip-heavy artifacts can therefore retain nearly the full 10 GiB as Go allocations (plus slice overhead), causing the LogService to OOM rather than fail cleanly. Cap cumulative references/memory, or retain offsets and re-read the skip payload only after sorting.
P2 - Preserve missing custom backup behavior outside WAL recovery (pkg/logservice/service_bootstrap.go:343)
Before this change, getBackupData treated a missing restore file as no backup for every path. This branch now fails normal bootstrap for any missing custom path, even with restore.enabled=false and no WAL recovery configured; only the default hk_data path remains optional. That regresses existing backup-only/normal configurations and contradicts the stated unchanged normal startup behavior. Keep the coordinator-side missing-artifact requirement in getBackupDataForBootstrap, but preserve the prior optional behavior outside recovery.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed exact head c3a6a41 against current origin/main. The earlier recovery-integrity blockers are addressed, and fresh package plus race-focused tests pass, but two material gaps remain.
P1 - Preserve optional missing custom backup behavior outside WAL recovery (pkg/logservice/service_bootstrap.go:314-345)
When wal-data-path is absent and restore.enabled is false, getBackupDataForBootstrap does not take the non-coordinator exception. A missing non-default relative file now returns ErrFileNotFound here, and a missing absolute file returns os.ErrNotExist above. Before this PR, every missing restore path returned nil. An existing deployment can retain a custom restore.file-path after the one-time artifact is removed or temporarily unavailable; upgrading to this change then aborts BootstrapHAKeeper even though WAL recovery is not configured. This contradicts the PR contract that normal startup is unchanged without wal-data-path. The new TestGetBackupDataForBootstrap currently codifies the regression. Keep strict missing-artifact failure for the actual WAL recovery coordinator, but preserve the previous optional behavior outside recovery.
P2 - Bound retained SkipDSN references before semantic validation (pkg/logservice/wal_recovery.go:475-480)
The scanner permits a 10 GiB file and streams normal payloads, but each SkipDSN body is copied into a walRecoverySkipReference slice and retained on WALEntry until the entire file has been scanned and sorted. Unknown, duplicate, and wrong-PSN references are rejected only afterward by validateWALRecoveryEntries. Consequently, a structurally valid but semantically malformed skip-heavy artifact can make the process retain roughly the artifact size as Go heap and OOM before returning the promised validation error. Normal mo_br output is constrained by the number of live WAL entries, so this finding is specifically about the PR stated fail-closed behavior for malformed recovery input. Retain offsets and re-read skip bodies after sorting, validate incrementally where possible, or impose a safe cumulative reference bound.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed exact head fafe6f8 against base dae28be. No remaining blocking issue found.
I revalidated every previously raised recovery gap. The current implementation now preserves optional missing custom backups outside WAL recovery, bounds retained SkipDSN references before allocation, streams payloads, derives the actual RPC payload ceiling, binds completion to the destination RSM marker, rejects dirty destinations, persists/reconciles crash progress, fences normal appends and lease changes, preserves SafeDSN semantics, waits for complete voting membership before coordinator election, and holds HAKeeper scheduling/ID allocation behind replicated recovery preparation with allocator-generation invalidation.
Fresh validation on this exact head:
go build -mod=readonly ./pkg/hakeeper ./pkg/logservicego vet -mod=readonly ./pkg/hakeeper ./pkg/logservice- full
go test -count=1 -timeout=15m ./pkg/hakeeper ./pkg/logservice - focused
go test -race -count=1 -timeout=15m -run 'WAL|Recovery|Restore|Recovered|IDAllocatorDiscards' ./pkg/hakeeper ./pkg/logservice git diff --check
All passed. The full package run also covers the real TAE LogEntry writer/decoder replay test, not only synthetic byte validation.
The current Ubuntu UT rerun reports pkg/logservice PASS (387.81s). Its sole failure is a data race in pkg/vm/engine/tae/rpc/handle_debug.go triggered by pkg/tests/dml/TestDataBranchPickRetestCompositePKChunkProbe; neither path is modified by this PR.
Merge Queue Status
This pull request spent 25 minutes in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #25867 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #24966.
What this PR does / why we need it:
Adds an explicit offline LogService recovery path for rebuilding a three-replica LogService cluster from artifacts generated by
mo_br.The recovery path is enabled only when
logservice.BootstrapConfig.restore.wal-data-pathis configured. Normal LogService startup and heartbeat behavior are unchanged when the option is absent.Key behavior:
NextIDandNextIDByKeythrough replicated, max-only HAKeeper updates, including when another LogService is already the HAKeeper leader and the cluster has already entered bootstrap.Operational constraint: all three LogService pods must run this version during recovery. Only one pod should be configured with the recovery files.
Validation:
go test -count=1 -timeout=15m ./pkg/hakeeper/... ./pkg/logservice ./pkg/pb/logservice ./pkg/utilgo test -race -count=1 -timeout=20m ./pkg/hakeeper ./pkg/logservicego vet ./pkg/hakeeper/... ./pkg/logservice ./pkg/pb/logservice ./pkg/utilgo test ./cmd/mo-service ./pkg/embed -run '^$' -count=1go build ./cmd/mo-servicemake err-checkEnd-to-end validation on an isolated local kind cluster:
mo_br.hakeeper_backup.dataandwal_data.bintolog-0.log-1andlog-2first:log-2became HAKeeper leader andlog-1initialized the cluster beforelog-0started.log-0: all HAKeeper replicas appliedNextID=50000000and the completeNextIDByKey; 115/115 WAL entries were replayed.50000001and50000002.50010341and50010342.