Skip to content

craft: S5 infrastructure — RAFT entry types, CraftPeerFetcher, write_counter - #172

Open
sbinmalek wants to merge 4 commits into
eBay:dev/v6.xfrom
sbinmalek:craft_S5_base
Open

craft: S5 infrastructure — RAFT entry types, CraftPeerFetcher, write_counter#172
sbinmalek wants to merge 4 commits into
eBay:dev/v6.xfrom
sbinmalek:craft_S5_base

Conversation

@sbinmalek

Copy link
Copy Markdown
Contributor

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)

…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)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/lib/craft/craft_raft_entries.hpp Outdated
Comment on lines +95 to +97
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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the check for corrupt entry

Comment thread src/lib/craft/craft_raft_entries.hpp Outdated
Comment on lines +87 to +91
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));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the check for empty empty_slots

Comment on lines +85 to +86
inline void serialize_sync_rs_commit_lsn(uint8_t* buf, int64_t rs_commit_lsn, uint64_t client_token,
const std::vector< int64_t >& empty_slots) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be covered in later PRs

  - 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.
@sbinmalek
sbinmalek marked this pull request as ready for review August 10, 2026 19:56
@sbinmalek
sbinmalek requested a balanced review from Copilot August 10, 2026 19:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@szmyd
szmyd requested a review from raakella1 August 18, 2026 16:34
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (dev/v6.x@7c7fa4f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/lib/craft/craft_repl_dev.cpp 0.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff             @@
##             dev/v6.x     #172   +/-   ##
===========================================
  Coverage            ?   45.00%           
===========================================
  Files               ?       18           
  Lines               ?     1020           
  Branches            ?      442           
===========================================
  Hits                ?      459           
  Misses              ?      273           
  Partials            ?      288           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants