Skip to content

refactor: dedupe WAL crc verification and fault-injection helpers - #597

Merged
t0k0sh1 merged 2 commits into
mainfrom
588-wal-duplication
Aug 12, 2026
Merged

refactor: dedupe WAL crc verification and fault-injection helpers#597
t0k0sh1 merged 2 commits into
mainfrom
588-wal-duplication

Conversation

@t0k0sh1

@t0k0sh1 t0k0sh1 commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • crc検証が3箇所(tail_record_is_complete / parse_log / shippable_records)に重複しており、エラー文言が既に3通りに drift していた(shipper側は「the bytes changed after they were written」節が欠落)。verify_record_crc + corrupt_record の2ヘルパに統合し、同型の parse-error/heuristic-error のラップも同じ helper に寄せた。
  • append/truncate/newline-heal 用の3つの #[cfg(test)] フォールト注入 thread_local が、文言以外バイト単位で同一だった。storage::injected_persistence_failure が既に採用している「文言を引数化」の形に揃えた(CREATE_FSYNC_FAULT はセマンティクスが異なるため対象外)。

Refs #588(残り: PR-B が wal.rs の正当性・doc修正、PR-C が registry/storage の重複統合・doc修正)

Test plan

  • cargo fmt
  • cargo clippy --all-targets -- -D warnings
  • cargo nextest run(3487 tests passed)
  • pre-PR mutation gate: diff の関数レベル膨張(parse_log/shippable_records/tail_record_is_complete の戻り値バリアント)を --exclude-re で除外し、新規変更分15件を実行 → 初回2件missed(shippable_recordsのエラー行番号 index + 1index * 1)、行番号を明示的に assert するテストを追加して --iterate で再検証 → 全件 caught

Summary by CodeRabbit

  • バグ修正
    • WAL(先行書き込みログ)の破損検出とCRC検証を統一し、読み込みや復元時に一貫したエラーを表示するよう改善しました。
    • 空行、未知のフィールド、CRC不一致などのエラーに、対象ファイルのパスと行番号を含めて原因を特定しやすくしました。

Three call sites (tail classification, interior replay, and the
replication shipper) each rebuilt canonical bytes, computed crc32c,
and formatted a mismatch error independently — the wording had
already drifted into three variants, with the shipper silently
missing the "the bytes changed after they were written" clause.
Extracted verify_record_crc + corrupt_record so all three (and the
adjacent parse-error/heuristic-error sites sharing the same
"corrupt WAL record at ..." prefix) go through one wording.

Also collapsed the three near-identical #[cfg(test)] fault-injection
thread_locals (append/truncate/newline-heal) into one parameterized
injected_fault helper, matching the pattern storage.rs's
injected_persistence_failure already uses.

Refs #588
cargo mutants --in-diff caught two mutants the refactor left uncovered:
replacing `index + 1` with `index * 1` in shippable_records' two
corrupt_record call sites went undetected, because no test asserted
the specific line number reported — only that "corrupt WAL record"
or "checksum mismatch" appeared somewhere in the message.

Refs #588
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1737f180-dacf-4794-aecf-532d5ac2f48f

📥 Commits

Reviewing files that changed from the base of the PR and between 1d7b0c8 and f45dd69.

📒 Files selected for processing (1)
  • src/wal.rs

📝 Walkthrough

Walkthrough

WALのCRC検証と破損エラー生成を共通ヘルパーへ集約しました。末尾レコード、通常レコード、レプリケーション対象レコードで共通処理を使用します。エラーにはパスと行番号を含めます。テストは先頭レコードと空行の行番号を検証します。

Changes

WAL検証フロー

Layer / File(s) Summary
共通ヘルパーとfault injection
src/wal.rs
CRC検証、破損エラー生成、テスト用fault injectionを共通化しました。append、truncate、改行補完のfault injectionが共通ヘルパーを呼び出します。
レコード検証とエラー報告
src/wal.rs
末尾レコードと通常レコードの解析で共通CRC検証と破損エラー生成を使用します。パスと行番号を含むエラーを返します。先頭レコードと空行の行番号をテストで検証します。
レプリケーション対象の検証
src/wal.rs
レプリケーション対象レコードの解析とCRC検証で共通ヘルパーを使用します。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • Issue 588: WALの重複したCRC検証とfault injection処理を共通化する目的が一致します。

Possibly related PRs

  • t0k0sh1/taguru#589: src/wal.rsのWAL解析、末尾検証、エラー処理を変更しており、コード領域が重なります。
  • t0k0sh1/taguru#595: WALの解析、CRC検証、リプレイ、破損エラー処理を扱っており、本変更の共通化対象と重なります。
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは、WALのCRC検証とfault-injectionヘルパーの重複排除という主要変更を簡潔かつ正確に示しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 588-wal-duplication

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

@t0k0sh1
t0k0sh1 merged commit 18b04fc into main Aug 12, 2026
15 checks passed
@t0k0sh1
t0k0sh1 deleted the 588-wal-duplication branch August 12, 2026 14:20
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