Skip to content

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

Merged
sbinmalek merged 6 commits into
eBay:dev/v6.xfrom
sbinmalek:craft_S5_base
Aug 31, 2026
Merged

craft: S5 infrastructure — RAFT entry types, CraftPeerFetcher, write_counter#172
sbinmalek merged 6 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)

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 thread src/lib/craft/craft_raft_entries.hpp
@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.

@codecov-commenter

codecov-commenter commented Aug 19, 2026

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 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (dev/v6.x@1181da7). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/lib/craft/craft_repl_dev.cpp 0.00% 1 Missing and 1 partial ⚠️
❗ 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.60%           
===========================================
  Files               ?       18           
  Lines               ?     1035           
  Branches            ?      451           
===========================================
  Hits                ?      472           
  Misses              ?      264           
  Partials            ?      299           

☔ 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.

Comment thread src/lib/craft/craft_raft_entries.hpp Outdated
Comment thread src/lib/craft/craft_repl_dev.hpp Outdated

class CraftPeerFetcher {
public:
virtual async_result< std::vector< JournalSlot > > fetch_from_peer(std::vector< int64_t > lsns) = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const std::vector<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.

Is this for return or param?

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.

this is for param

Comment thread src/lib/craft/craft_raft_entries.hpp

// ─── header blob ─────────────────────────────────────────────────────────────

struct CraftEntryHeader {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

carries no version/magic field

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.

Why do we need that?

Comment thread src/lib/craft/craft_raft_entries.hpp
sbinmalek and others added 5 commits August 31, 2026 12:40
…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>
* Also bumped conan version
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: add unit to the identifier sync_rs_commit_lsn_interval_sec, sync_rs_commit_lsn_interval_ms ...

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.

This is not a timer. sync will be proposed every X number of log entries.

@shosseinimotlagh shosseinimotlagh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@sbinmalek
sbinmalek merged commit 8aed11c into eBay:dev/v6.x Aug 31, 2026
22 checks passed
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.

4 participants