Skip to content

fix: finish forwarded proposals after transport send failures - #20

Merged
volgariver6 merged 1 commit into
matrixorigin:masterfrom
jiangxinmeng1:codex/pending-proposal-send-failure
Nov 6, 2026
Merged

volgariver6 merged 1 commit into
matrixorigin:masterfrom
jiangxinmeng1:codex/pending-proposal-send-failure

Conversation

@jiangxinmeng1

Copy link
Copy Markdown

Summary

Complete a local forwarded proposal when its Raft transport send fails:

  • A synchronous rejection (unknown target, open circuit breaker, rate limit, or full queue) reports Dropped, because the message was not sent.
  • A failed batch write reports Timeout, because delivery and commit are unknown.
  • A connection failure drains accepted messages still in its queue and reports them as not sent. Queue lookup, enqueue, and removal share one lock so no sender can enqueue after the worker drains the old queue.

The pending proposal map still chooses a single terminal outcome when send failure races with apply, expiry, or shutdown. No proposal is automatically replayed.

Motivation

matrixorigin/matrixone#32133 records a surviving LogService replica waiting for a forwarded WAL proposal's full deadline after transport rejects or fails its send, despite a healthy majority. This change lets the caller retry promptly while preserving an unknown outcome for ambiguous writes.

Validation

  • go test -count=1 -timeout=300s ./
  • go test -count=1 -timeout=180s ./internal/transport
  • Focused proposal and transport failure tests with -race.
  • go build ./...
  • go vet ./ ./internal/transport

The tests cover direct rejection, circuit breaker rejection, connection failure with queued messages, batch write failure, local replica ownership, and late apply after failure. A three voter MatrixOne chaos run has not yet been repeated with this dependency revision.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review:Approve(限定本 PR 的修复范围)

审查基线:master@0b20c95f67f8e5eb119d1913b18fa8c9b09612b9 → fe9153104101ce6ce3c61209d9845cacecf61973。已读完 6 个文件全部改动,并追踪 transport → messageHandler → pendingProposal/RequestState,以及 MatrixOne 上层的错误处理。当前没有历史 review thread 需要关闭,也没有确认的新增阻断问题。

设计与正确性

  • 修复放在已有 transport 失败出口和 pending map 的完成责任上,复用现有终态竞争机制,没有新建重试器、登记表或第二套状态机。作为集中 bug fix,不需要额外的大型设计框架。
  • 确定没有发送的请求返回 Dropped;已经进入失败 batch write 的请求保留 Timeout/结果未知,不能解释为未提交。拆成两批时,第一批失败不会把尚未尝试发送的第二批错误标成“可能送达”;第二批失败也不会终结第一批已经成功发送的请求。
  • queue lookup/enqueue/removal 使用同一把锁,worker 移除旧 queue 后再清空它,封住了 enqueue 到已清空旧队列的窗口;失败通知在 transport 锁外执行。
  • 本地完成仍按 shard、发送 replica 和 client/series/key 匹配,并由 pending map 的移除选择终态。晚到 apply、重复失败和 close 不会再次完成已经取走的 pending。
  • 未改 Raft 选举/复制/提交规则、wire 或持久化格式,也没有在 Dragonboat 中自动重投。非 proposal 消息不会进入新的 pending 完成路径。MO 的既有上层逻辑将 Dropped 映射为 ErrShardNotReady 并退避重试,而 Timeout 仍作为未知结果向上传递;两者没有混为“安全回滚”。

生命周期检查

维度 结论
Q1:完成/清理责任 未发送队列项与失败写入批次分开报告;pending map 保留唯一终态责任。
Q2:等待退出 新增 enqueue 是非阻塞发送,回调不持 transport 锁;没有新增等待远端确认的边。原连接 I/O 超时不由本补丁缩短。
Q3:增长边界 复用既有有界队列和 pending 清理机制,没有新增无限队列、重试任务或持久化状态。

正常发送的临界区比原来略长,包含限流判断、计数和非阻塞入队,但不包住网络连接或 batch write。未发现可据此确认的性能回退;不承诺未经测量的零性能影响。

本轮验证

环境:Go 1.24.2 / Darwin arm64;限制 GOMAXPROCS=2、GOMEMLIMIT=1GiB、-p=1,没有启动 MO 集群或重型全量测试。

  • PR 的四个新增测试,以及 proposal apply/drop/commit/expiry、初次发送、失败连接移除和 circuit-breaker 对照:定向 normal 测试通过。
  • 新增测试及下述临时 review probes 的定向 -race 检查通过。
  • TestAcceptedProposalsAreReportedWhenConnectionFails、TestProposalSendFailureFeedback 和临时 TestReviewFailureTerminalCompetition 分别以 -race -count=100 运行通过,未对整个包重复压测。
  • 临时 probes 覆盖:full queue/rate limit 的确定失败;split batch 第一/第二批失败分类;失败与 apply/expiry/close 的终态竞争;getRequestState 的错误映射;已收到 commit 通知后的 uncertain completion。使用真实生产方法及既有轻量 fixture,没有改生产代码;这些 probes 不属于 PR 已提交测试。
  • go vet -mod=readonly -p=1 ./ ./internal/transport、提交 diff whitespace 检查通过。

非阻断建议:把 split-batch 分类及终态竞争这几个反例保留为仓库回归测试,避免后续只靠串行 late-apply 测试守护并发边界。

证据边界

  • 没有将作者列出的全量包测试/go build ./... 当成本轮重新执行的结果;GitHub 当前也没有 reported checks。
  • 尝试既有 BenchmarkTransport16 时,未修改的 base 已在 benchmarkMessageHandler.wait 卡住;已采集栈并终止本轮拥有的进程,未得到有效 base/head 性能对照,不归因于本 PR。
  • 本 PR 可以修复 #32133 评论中“本地转发 transport 已拒绝/失败,但 pending 仍等完整 deadline”的通知缺口;不覆盖所有连接黑洞、中间副本转发失败或已经成功发送却没有完成的情况。不能据此直接关闭整个事故或承诺全部 60 秒长尾消失。
  • MO 消费该依赖后,仍应做三 voter leader 停止/连接隔离、unknown Append 与 WAL 去重、确认提交数据的恢复核对。这是集成/上线验收边界,不把未运行 Chaos 本身写成本 PR 的代码 blocker。

结论:认可该范围内的修复,Approve;不等同于客户镜像或最终集成版本已经完成发布验收。

mergify Bot pushed a commit to matrixorigin/matrixone that referenced this pull request Nov 6, 2026
…HAKeeper restart (#32149)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes #32148
Fixes #32144
Fixes #32159
Fixes #32151
Fixes #32161
Fixes #32235
Related to #32133

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

- Give each LogService `Read` attempt a seven-second child deadline. If an established data connection stops answering after the request is sent, reset that connection and retry the same LSN while the caller context remains live. Read can be repeated safely; writes retain their existing unknown-result behavior. Connection failures from MORPC also take this retry path, so this works alongside #32147's shared backend read window.
- Bound each `GetTruncatedLsn` attempt to seven seconds. A stalled read resets its LogService connection and retries while the caller is live; the WAL driver now keeps one overall replay deadline and cancels retry backoff promptly. This lets `ReplayForWrite` try another available replica when its first truncate-watermark read stalls. `Append` and `Truncate` write semantics are unchanged.
- During service restart, before starting each retained data replica, remove only canonical exported snapshot final directories that still contain Dragonboat's completion flag. A crash between final-directory rename and flag removal no longer leaves an untracked directory that blocks export at the same index. Valid exports and temporary directories remain available; filesystem cleanup errors fail startup visibly.
- When an exported snapshot finishes after its request times out, mark that replica for later disk reconciliation. Each truncation tick discovers complete final directories, includes them in import and quota decisions, and removes excess newest snapshots while keeping the oldest import candidate. Incomplete directories and I/O errors remain retryable; unaffected replicas do not scan.
- Reject a `Truncate` target at or beyond the Raft index of the truncate command when the state machine applies it. The persisted watermark cannot advance past entries already committed, so later acknowledged appends remain readable. The API keeps the `ErrInvalidTruncateLsn` error class.
- On ordinary HAKeeper cold restart, select the highest locally persisted replica ID that the peer membership check has not rejected. HAKeeper allocates replacement IDs monotonically; older local records are skipped so Dragonboat starts only one replica for shard 0. If a replacement is running, bootstrap does not replay the configured initial ID, even when its metadata record was removed.
- Add regressions for an established connection that stops answering, interrupted snapshot export, future truncate followed by append/read, a full three-voter cold restart with historical HAKeeper metadata, and an accepted snapshot request that times out before its final directory appears.

### Validation

- Native `make -j4 cgo`: passed on each original branch; native inputs are unchanged in the combined branch.
- Focused regressions for all four issues and complete `pkg/logservice` plus `pkg/common/moerr` packages: passed on the combined branch.
- Focused race repetitions and complete `pkg/logservice` race package for the original Read/snapshot changes: passed on the original #32149 head. The combined branch preserves those code paths.
- `go vet` for LogService and its WAL driver passed on the original #32149 head. The combined branch includes a separate `go vet` result for LogService and `moerr`.
- For #32161, the real Dragonboat post-admission timeout regression, late-completion/quota and scanner-error controls, complete `pkg/logservice` normal and race packages, focused race repetitions, and `go vet ./pkg/logservice` passed on that head.
- For #32235, a real LogService client with an established response-dropping connection recovered the expected truncate watermark through a healthy address. A short caller deadline stopped the blackholed request. `ReplayForWrite` retried a transient watermark error, and cancellation stopped the driver after one attempt. Complete `pkg/logservice` and WAL-driver packages passed in normal and race modes; focused race repetitions passed (client 3, replay 20, cancellation 20); `go vet` passed for both packages.
- Temporary overlay of #32147's shared eight-second MORPC backend read window, followed by the focused Read regression: passed on the original #32149 head; the overlay was removed afterward.
- On head `790bca9921`, upstream/main through `65b721e1b9` supplies #32147. The focused prior CI failures passed locally; the LIKE index case passed three consecutive runs after its deterministic test correction. Complete `pkg/logservice` and WAL-driver package tests, build, and vet passed against the MatrixOrigin Dragonboat dependency. The new MatrixOne CI is pending.

### Relationship and limits

The merged upstream/main includes #32147, which bounds the underlying data connection's read window for all operations. This PR adds `Read` and `GetTruncatedLsn` retry semantics without duplicating that patch. The child deadline is not a hard bound on every possible blocked send path inside MORPC; the reproduced failures stall after a small request is sent. A healthy `Read` or `GetTruncatedLsn` lasting more than seven seconds can be retried. Reconnect still uses existing randomized endpoint selection, so a single failed attempt does not guarantee a healthy endpoint on the next pick. The regressions use a single server behind a response-dropping proxy; the three-voter network-namespace chaos scenarios for `Read` and WAL replay have not been rerun on this branch. The pending-proposal transport fix for #32133 is in [matrixorigin/dragonboat#20](matrixorigin/dragonboat#20), which is still open and is not included in this PR. This PR uses the existing MatrixOrigin Dragonboat version. The three-voter network-namespace failure scenario has not been rerun, so #32133 is not claimed fully resolved. The WAL driver's `clientPool.Get()` remains context-unaware when the pool is empty, outside #32235's reproduced case with available pooled clients. Crash-marker cleanup remains a startup path; late valid exports are reconciled while the process runs on later truncation ticks. An affected replica continues to scan after an ambiguous request because the completion can arrive after any scan; disk quota can be exceeded transiently before the next tick.

When no peer can answer during HAKeeper cold restart, the choice among locally persisted replicas relies on monotonic replica IDs. The new three-voter regression verifies that this restores quorum with the issue's duplicate-metadata shape. The installed local `golangci-lint` was built with Go 1.26 and cannot lint this Go 1.27.1 repository; CI will run the configured lint check.




Approved-by: XuPeng-SH <[email protected]>
@volgariver6
volgariver6 merged commit 8ed6c83 into matrixorigin:master Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants