Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwmao committed Dec 3, 2024
1 parent 4124863 commit 0cb90b8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class HomestoreConan(ConanFile):
name = "homestore"
version = "6.5.18"
version = "6.5.19"

homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
Expand Down
5 changes: 3 additions & 2 deletions src/lib/replication/repl_dev/raft_repl_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ void RaftReplDev::create_snp_resync_data(raft_buf_ptr_t& data_out) {
snp_repl_dev_data msg;
auto msg_size = sizeof(snp_repl_dev_data);
msg.dsn = m_next_dsn;
auto crc = crc32_ieee(0, reinterpret_cast< const unsigned char* >(&msg), msg_size);
auto crc = crc32_ieee(init_crc32, reinterpret_cast< const unsigned char* >(&msg), msg_size);
RD_LOGD("create snapshot resync msg, dsn={}, crc={}", msg.dsn, crc);
msg.crc = crc;
data_out = nuraft::buffer::alloc(msg_size);
Expand All @@ -1511,8 +1511,9 @@ bool RaftReplDev::apply_snp_resync_data(nuraft::buffer& data) {
}
auto received_crc = msg->crc;
RD_LOGD("received snapshot resync msg, dsn={}, crc={}, received crc={}", msg->dsn, msg->crc, received_crc);
// Clear the crc field before verification, because the crc value computed by leader doesn't contain it.
msg->crc = 0;
auto computed_crc = crc32_ieee(0, reinterpret_cast< const unsigned char* >(msg),
auto computed_crc = crc32_ieee(init_crc32, reinterpret_cast< const unsigned char* >(msg),
sizeof(snp_repl_dev_data));
if (received_crc != computed_crc) {
RD_LOGE("Snapshot resync data crc mismatch, received_crc={}, computed_crc={}", received_crc, computed_crc);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/replication/repl_dev/raft_state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ int RaftStateMachine::read_logical_snp_obj(nuraft::snapshot& s, void*& user_ctx,
bool& is_last_obj) {
// For Nuraft baseline resync, we separate the process into two layers: HomeStore layer and Application layer.
// We use the highest bit of the obj_id to indicate the message type: 0 is for HS, 1 is for Application.
if ((obj_id & snp_obj_id_type_mask) == 0) {
if (is_hs_snp_obj(obj_id)) {
// This is the preserved msg for homestore to resync data
m_rd.create_snp_resync_data(data_out);
is_last_obj = false;
Expand Down Expand Up @@ -328,10 +328,10 @@ int RaftStateMachine::read_logical_snp_obj(nuraft::snapshot& s, void*& user_ctx,

void RaftStateMachine::save_logical_snp_obj(nuraft::snapshot& s, ulong& obj_id, nuraft::buffer& data, bool is_first_obj,
bool is_last_obj) {
if ((obj_id & snp_obj_id_type_mask) == 0) {
if (is_hs_snp_obj(obj_id)) {
// Homestore preserved msg
if (m_rd.apply_snp_resync_data(data)) {
obj_id = snp_obj_id_type_mask;
obj_id = snp_obj_id_type_app;
LOGDEBUG("apply_snp_resync_data success, next obj_id={}", obj_id);
}
return;
Expand Down Expand Up @@ -367,7 +367,7 @@ bool RaftStateMachine::apply_snapshot(nuraft::snapshot& s) {
auto snp_ctx = std::make_shared< nuraft_snapshot_context >(s);
auto res = m_rd.m_listener->apply_snapshot(snp_ctx);
//make sure the changes are flushed.
hs()->cp_mgr().trigger_cp_flush(true /* force */);
hs()->cp_mgr().trigger_cp_flush(true /* force */).get();
return res;
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/replication/repl_dev/raft_state_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class StateMachineStore;

// For the logic snapshot obj_id, we use the highest bit to indicate the type of the snapshot message.
// 0 is for HS, 1 is for Application.
static constexpr uint64_t snp_obj_id_type_mask = 1ULL << 63;
static constexpr uint64_t snp_obj_id_type_app = 1ULL << 63;

using AsyncNotify = folly::SemiFuture< folly::Unit >;
using AsyncNotifier = folly::Promise< folly::Unit >;
Expand Down Expand Up @@ -139,6 +139,8 @@ class RaftStateMachine : public nuraft::state_machine {

std::string rdev_name() const;

static bool is_hs_snp_obj(uint64_t obj_id) { return (obj_id & snp_obj_id_type_app) == 0; }

private:
void after_precommit_in_leader(const nuraft::raft_server::req_ext_cb_params& params);
};
Expand Down
8 changes: 6 additions & 2 deletions src/tests/test_common/raft_repl_test_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ class TestReplicatedDB : public homestore::ReplDevListener {

int read_snapshot_obj(shared< snapshot_context > context, shared< snapshot_obj > snp_data) override {
auto s = std::dynamic_pointer_cast< nuraft_snapshot_context >(context)->nuraft_snapshot();
if ((snp_data->offset & snp_obj_id_type_mask) == 0) {
if(RaftStateMachine::is_hs_snp_obj(snp_data->offset)) {
LOGERRORMOD(replication, "invalid snapshot offset={}", snp_data->offset);
return -1;
}
if ((snp_data->offset & snp_obj_id_type_app) == 0) {
LOGERRORMOD(replication, "invalid snapshot offset={}", snp_data->offset);
return -1;
}
Expand Down Expand Up @@ -247,7 +251,7 @@ class TestReplicatedDB : public homestore::ReplDevListener {
}

void write_snapshot_obj(shared< snapshot_context > context, shared< snapshot_obj > snp_data) override {
if ((snp_data->offset & snp_obj_id_type_mask) == 0) {
if (RaftStateMachine::is_hs_snp_obj(snp_data->offset)) {
LOGERRORMOD(replication, "invalid snapshot offset={}", snp_data->offset);
return;
}
Expand Down

0 comments on commit 0cb90b8

Please sign in to comment.