craft: S5 infrastructure — RAFT entry types, CraftPeerFetcher, write_counter - #172
Conversation
There was a problem hiding this comment.
Pull request overview
Scaffolds CRAFT S5 RAFT metadata and peer-fetch infrastructure for later implementation.
Changes:
- Defines RAFT entry wire formats and serialization helpers.
- Adds peer-fetch and write-trigger state to
CraftReplDev. - Adds configurable SyncRSCommitLSN interval.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/lib/craft/craft_raft_entries.hpp |
Adds RAFT entry types, payloads, and helpers. |
src/lib/craft/craft_repl_dev.hpp |
Adds peer fetcher and S5 state scaffolding. |
src/lib/craft/craft_repl_dev.cpp |
Updates the apply-helper stub signature. |
src/lib/home_blks_config.fbs |
Adds the synchronization interval setting. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| inline std::vector< int64_t > parse_empty_slots(const SyncRSCommitLSNPayload* p) { | ||
| const auto* src = reinterpret_cast< const int64_t* >(p + 1); | ||
| return std::vector< int64_t >(src, src + p->num_empty_slots); |
There was a problem hiding this comment.
Added the check for corrupt entry
| auto* p = reinterpret_cast< SyncRSCommitLSNPayload* >(buf); | ||
| p->rs_commit_lsn = rs_commit_lsn; | ||
| p->client_token = client_token; | ||
| p->num_empty_slots = static_cast< uint32_t >(empty_slots.size()); | ||
| std::memcpy(p + 1, empty_slots.data(), empty_slots.size() * sizeof(int64_t)); |
There was a problem hiding this comment.
Added the check for empty empty_slots
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev/v6.x #172 +/- ##
===========================================
Coverage ? 45.60%
===========================================
Files ? 18
Lines ? 1035
Branches ? 451
===========================================
Hits ? 472
Misses ? 264
Partials ? 299 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
| class CraftPeerFetcher { | ||
| public: | ||
| virtual async_result< std::vector< JournalSlot > > fetch_from_peer(std::vector< int64_t > lsns) = 0; |
There was a problem hiding this comment.
const std::vector<int64_t>&
There was a problem hiding this comment.
Is this for return or param?
There was a problem hiding this comment.
this is for param
|
|
||
| // ─── header blob ───────────────────────────────────────────────────────────── | ||
|
|
||
| struct CraftEntryHeader { |
There was a problem hiding this comment.
carries no version/magic field
There was a problem hiding this comment.
Why do we need that?
…counter
Add the wire format definitions and scaffolding needed by S5
(SyncRSCommitLSN + InternalLogin RAFT state machine entries).
Implementations land in follow-up PRs; this PR makes the base branch
compile cleanly.
- craft_raft_entries.hpp: CraftEntryType enum, CraftEntryHeader,
SyncRSCommitLSNPayload (variable-length with trailing int64_t array),
InternalLoginPayload, and helpers (sync_rs_commit_lsn_key_size,
serialize_sync_rs_commit_lsn, parse_empty_slots)
- craft_repl_dev.hpp: add CraftPeerFetcher interface (server-to-server
fetch abstraction; production wired in S9), set_peer_fetcher() setter,
write_counter_ atomic (periodic SyncRSCommitLSN auto-fire trigger),
update apply_sync_rs_commit_lsn signature to carry empty_slots
- craft_repl_dev.cpp: match stub signature to updated header
- home_blks_config.fbs: add sync_rs_commit_lsn_interval setting (128)
- parse_empty_slots now takes the raw key blob instead of a trusted
struct pointer, and returns std::optional instead of an unconditional
vector. Validates the fixed prefix is present and that the persisted
num_empty_slots exactly accounts for the blob's actual size before
ever constructing the vector -- a corrupt/truncated RAFT entry no
longer risks an out-of-bounds read or a bogus multi-GB allocation
during replay.
- serialize_sync_rs_commit_lsn now zeroes the fixed prefix before
writing fields, so SyncRSCommitLSNPayload's compiler-inserted trailing
padding (20 real bytes, sizeof rounds to 24) can't leak prior buffer
contents into a persisted/replicated entry or make equivalent entries
byte-different.
- Guard the empty_slots memcpy: vector::data() may return null when
empty, and memcpy(dest, nullptr, 0) is UB even at zero length.
Bump the craft_client pin to 0.4.0 and reconcile CraftReplDev's peer-plane surface with craft_client's include/craft/peer.hpp: - CraftPeerFetcher now mirrors craft_peer's two methods 1:1 -- get_rs_commit_lsn(term, is_login) and fetch_data(lsns), replacing the single fetch_from_peer(lsns). No call sites existed yet. - CraftReplDev::get_rs_commit_lsn() (the responder side) gains the same (term, is_login) params craft_peer declares, unused for now, matching craft_client's own reference implementation. - Add test_craft_journal_slot_wire: round-trips homeblocks::JournalSlot through craft_client's real peer_codec.cpp instead of assuming layout compatibility. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
47393a5 to
f322ca7
Compare
* Also bumped conan version
f322ca7 to
7253e77
Compare
| hs_data_chunk_size_mb: uint32 = 2048; | ||
|
|
||
| // how often (in appended LSNs) the leader auto-proposes a SyncRSCommitLSN entry; | ||
| sync_rs_commit_lsn_interval: uint32 = 128; |
There was a problem hiding this comment.
nit: add unit to the identifier sync_rs_commit_lsn_interval_sec, sync_rs_commit_lsn_interval_ms ...
There was a problem hiding this comment.
This is not a timer. sync will be proposed every X number of log entries.
Add the wire format definitions and scaffolding needed by S5 (SyncRSCommitLSN + InternalLogin RAFT state machine entries). Implementations land in follow-up PRs; this PR makes the base branch compile cleanly.