refactor: dedupe WAL crc verification and fault-injection helpers - #597
Merged
Conversation
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
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughWALのCRC検証と破損エラー生成を共通ヘルパーへ集約しました。末尾レコード、通常レコード、レプリケーション対象レコードで共通処理を使用します。エラーにはパスと行番号を含めます。テストは先頭レコードと空行の行番号を検証します。 ChangesWAL検証フロー
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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 に寄せた。#[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 fmtcargo clippy --all-targets -- -D warningscargo nextest run(3487 tests passed)parse_log/shippable_records/tail_record_is_completeの戻り値バリアント)を--exclude-reで除外し、新規変更分15件を実行 → 初回2件missed(shippable_recordsのエラー行番号index + 1→index * 1)、行番号を明示的に assert するテストを追加して--iterateで再検証 → 全件 caughtSummary by CodeRabbit