Skip to content

refactor(storage): 删除未接入写路径的 storage WAL#112

Merged
NeverENG merged 1 commit into
mainfrom
refactor/drop-storage-wal
Jun 1, 2026
Merged

refactor(storage): 删除未接入写路径的 storage WAL#112
NeverENG merged 1 commit into
mainfrom
refactor/drop-storage-wal

Conversation

@NeverENG
Copy link
Copy Markdown
Owner

@NeverENG NeverENG commented Jun 1, 2026

@

背景

排查写路径优化 (#111) 时发现: storage/zstorage/WAL.go 并未接入实际写路径。

  • 写路径 Engine.Put → MemTable.Put → skiplist.insert 全程不写 WAL;
  • WAL.Writewal_test.go 调用;
  • 恢复时 recoverFromWAL 读到的永远是空文件;
  • 真正的持久性由 Raft 日志 (Raft/raft_wal.go) 提供。

该 WAL 属死代码, 留着误导"持久性靠它"。删除。

改动 (外科手术式)

  • 删除 storage/zstorage/WAL.gostorage/zstorage/wal_test.gostorage/istorage/IWal.go
  • memtable.go: 移除 wal 字段、NewWAL()recoverFromWALSyncClear, 及 Flush 内 WAL 清除调用; Close 保留 stopCh 关闭
  • LogEntry (SSTable 共用)、config.WALPath 保留, 不顺带改动

验证

  • go build ./... / go vet ./storage/... 干净
  • go test ./storage/... 全绿

🤖 Generated with Claude Code
@

Summary by CodeRabbit

  • Refactor

    • Removed write-ahead log infrastructure from the storage subsystem to streamline internal architecture.
  • Tests

    • Removed associated test coverage for write-ahead log functionality.

storage/zstorage/WAL.go 只在恢复时被 Read, Write 仅测试调用——
实际写路径 Engine.Put→MemTable.Put→skiplist.insert 从不落 WAL,
持久性由 Raft 日志提供。移除该死代码及 IWal 接口、wal_test,
并清理 MemTable 中 wal 字段/recoverFromWAL/Sync/Clear 及 Flush 内
的 WAL 清除调用; Close 保留 stopCh 关闭。

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

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 76f9b467-a5ea-4e35-8b91-ffaf5b942af9

📥 Commits

Reviewing files that changed from the base of the PR and between c6a5132 and d334511.

📒 Files selected for processing (4)
  • storage/istorage/IWal.go
  • storage/zstorage/WAL.go
  • storage/zstorage/memtable.go
  • storage/zstorage/wal_test.go

📝 Walkthrough

Walkthrough

This PR removes the write-ahead log (WAL) feature entirely from the storage subsystem. The IWal interface contract is deleted, the WAL implementation file is removed, and MemTable is decoupled from WAL state initialization, recovery, syncing, and clearing operations.

Changes

WAL Feature Removal

Layer / File(s) Summary
MemTable struct and initialization without WAL
storage/zstorage/memtable.go
The wal field is removed from MemTable struct, and the NewMemTable constructor no longer initializes WAL or runs WAL recovery after SSTable metadata is loaded.
MemTable lifecycle methods updated
storage/zstorage/memtable.go
Close() method stops background processing without closing WAL, and Flush() cleanup removes the WAL-clear step, leaving only dirty-state management after SSTable write.

Possibly related PRs

  • NeverENG/BanDB#106: Modifies WAL handling in memtable around replay and tombstone preservation, directly affected by this removal.
  • NeverENG/BanDB#24: Relies on WAL interactions during MemTable.Put, Flush, and recovery that are being removed by this PR.
  • NeverENG/BanDB#31: Directly modifies WAL.Clear and WAL.Read behavior that this PR removes entirely.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 The WAL logs fade away,
No more checkpoints to replay,
MemTable stands alone and lean,
Cleanest storage ever seen!
Simplicity, thy name is speed. ✨

✨ 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 refactor/drop-storage-wal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@NeverENG NeverENG merged commit 90737d3 into main Jun 1, 2026
3 of 4 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

🐯 BanGD 数据库内核评审

整体风险:🟢 低

变更总结:该 PR 对外科手术式删除了 storage/zstorage/WAL.go 及其接口 istorage/IWal.go、测试文件 wal_test.go,并清理了 MemTable 中所有与 WAL 相关的字段、方法调用和恢复逻辑。核心动机是:该 WAL 从未接入实际写路径(Engine.Put → MemTable.Put → skiplist.insert 全程无 WAL 写入),真正的持久性由 Raft 日志提供,此 WAL 属于死代码。改动还保留了 LogEntry 结构体和 config.WALPath(因 SSTable 共用 LogEntry),未破坏构建和已有测试。

本评审不阻塞合入;架构级建议以 Issue 形式跟踪。

架构问题(共 3 项)


本次评审消耗 token:共 13155 tokens(输入 7310,输出 1365,缓存命中 4480,缓存写入 0)|维度 [concurrency, memory, lock, storage, performance]

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