Skip to content

fix(raft): 新增 NewRaftWithDataDir, 修复 raft_test.go 编译#39

Merged
NeverENG merged 1 commit into
mainfrom
fix/raft-test
May 21, 2026
Merged

fix(raft): 新增 NewRaftWithDataDir, 修复 raft_test.go 编译#39
NeverENG merged 1 commit into
mainfrom
fix/raft-test

Conversation

@NeverENG
Copy link
Copy Markdown
Owner

@NeverENG NeverENG commented May 21, 2026

Summary

  • Raft/raft.go 新增 NewRaftWithDataDir(peers, me, dataDir), 让测试能注入隔离的数据目录
  • NewRaft(peers, me) 内部转调 NewRaftWithDataDir(..., \"raft_data\") 保持线上行为
  • raft_test.go 中 14 处调用现在能正常编译

Background

raft_test.go 一直在调一个不存在的 NewRaftWithDataDir 函数, 整个 Raft 包测试无法编译。CI 当前只跑 go vet/go build 没碰测试, 所以一直漏。

Test plan

  • `go build ./Raft/...` 通过
  • `go vet ./Raft/...` 通过
  • 清掉残留 `raft_data/raft_test_data_*` 后, raft_test.go 14 个用例本地全部通过

已知遗留(不在本 PR 内修)

  • `rpc_test.go` 的 `TestAppendEntriesRPC` 在本地存在跨用例污染 + 运行时 panic, 与 raft_test 编译失败无关; 单独 PR 处理。
  • `Raft/raft_test_data_*` 目录被意外签入历史, 建议补 `.gitignore` 规则 (单独 PR)。

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Raft data storage location is now configurable. Users can specify custom persistence paths instead of being limited to the default location, providing greater flexibility for deployment and infrastructure customization.

Review Change Stack

raft_test.go 在 14 处调用 NewRaftWithDataDir(peers, me, dataDir) 用以隔离测试数据目录, 但函数从未定义, 导致整个 Raft 包测试无法编译。

NewRaft 保留原签名, 直接转调 NewRaftWithDataDir(..., "raft_data") 保持现有行为。

清掉残留 raft_data/raft_test_data_* 后, raft_test.go 全部 14 个用例本地通过。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 76752253-6b16-4341-95fe-b1553d3d11b2

📥 Commits

Reviewing files that changed from the base of the PR and between 8686436 and d2799e8.

📒 Files selected for processing (1)
  • Raft/raft.go

📝 Walkthrough

Walkthrough

NewRaft now delegates to NewRaftWithDataDir with the default "raft_data" directory. NewRaftWithDataDir uses the provided dataDir parameter for WAL initialization instead of a hardcoded value, making the persistence location configurable.

Changes

WAL Directory Configuration

Layer / File(s) Summary
WAL directory parameterization
Raft/raft.go
NewRaft delegates to NewRaftWithDataDir with the default "raft_data" directory. NewRaftWithDataDir initializes the WAL using the provided dataDir parameter instead of hardcoded "raft_data", enabling configurable persistence locations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Flexibility blooms when paths are set free,
No longer bound to "raft_data" decree,
A simple delegation, a parameter's grace,
Now builders can choose their persistence place! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/raft-test

Comment @coderabbitai help to get the list of available commands and usage tips.

@NeverENG NeverENG merged commit bfff8bc into main May 21, 2026
2 of 3 checks passed
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.

1 participant