← Back to Pull requests

perf: log-store: append the whole batch in one WriteBatch #17

Closed
unknown closed this pull request without merging on Nov 06, 2026 03:06 UTC
View on GitHub
unknown unknown commented on Nov 04, 2026 03:35 UTC
Author

Finding

O-11 — append writes one put_cf per entry.

src/raft/store/log_store.rs:

for entry in entries {
    let id = id_to_bin(entry.index());
    self.db.put_cf(&self.cf_logs(), id, encode(&entry)?)?;
}

OpenRaft hands append a whole AppendEntries batch — up to
max_payload_entries (default 300) — and this turned each one into 300
independent writes, 300 WAL appends and 300 memtable inserts.

How to reproduce

Instrument RocksLogStore::append (or DB::put/DB::write) and run any
replication: a single batch of 300 entries shows 300 put_cf calls from one
append.

The fix

let mut batch = rocksdb::WriteBatch::default();
for entry in entries {
    let id = id_to_bin(entry.index());
    let data = encode(&entry).map_err(read_logs_err)?;
    batch.put_cf(&self.cf_logs(), id, data);
}
if !batch.is_empty() {
    self.db.write(batch).map_err(read_logs_err)?;
}

The write stays inside append rather than moving into the flush task, because
OpenRaft requires the entries to be readable as soon as append returns. The
flush and the IOFlushed callback are untouched: flush_wal(true) still runs in
a blocking task and still reports completion.

Two wins beyond the call count:

  • Atomicity. A crash during the loop could previously leave a prefix of the

  • batch durable, i.e. get_log_state() reporting a log that is missing entries
    the leader had already accepted (safe — Raft reconciles it — but it makes every
    partial append a conflict to resolve). One WriteBatch is all-or-nothing.
  • Empty batches cost nothing. An empty append skips the write entirely.
  • Test: test_append_is_readable_on_return — entries and get_log_state() agree
    immediately after append returns, and an empty append is a no-op.

    Verified: cargo fmt --all -- --check, cargo clippy --all-features -- -D
    warnings
    , cargo test --lib → 110 passed.

    <!-- x-pr-ship -->

    Diff: 242 lines (+181 / -61) across 3 files Reviewer: lichuang Review duration: 2851m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.39) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 242 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.329
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #17"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.8% (MEDIUM) · Higher = larger blast radius
    38.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%