From 0cb90b81eb03bd8625034fc635cd8995c119262e Mon Sep 17 00:00:00 2001 From: yuwmao Date: Tue, 3 Dec 2024 11:49:00 +0800 Subject: [PATCH] fix comments --- conanfile.py | 2 +- src/lib/replication/repl_dev/raft_repl_dev.cpp | 5 +++-- src/lib/replication/repl_dev/raft_state_machine.cpp | 8 ++++---- src/lib/replication/repl_dev/raft_state_machine.h | 4 +++- src/tests/test_common/raft_repl_test_base.hpp | 8 ++++++-- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/conanfile.py b/conanfile.py index 99e129017..bc914e16c 100644 --- a/conanfile.py +++ b/conanfile.py @@ -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" diff --git a/src/lib/replication/repl_dev/raft_repl_dev.cpp b/src/lib/replication/repl_dev/raft_repl_dev.cpp index 33dc11765..72a39a27a 100644 --- a/src/lib/replication/repl_dev/raft_repl_dev.cpp +++ b/src/lib/replication/repl_dev/raft_repl_dev.cpp @@ -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); @@ -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); diff --git a/src/lib/replication/repl_dev/raft_state_machine.cpp b/src/lib/replication/repl_dev/raft_state_machine.cpp index b214fbf17..b64a32c24 100644 --- a/src/lib/replication/repl_dev/raft_state_machine.cpp +++ b/src/lib/replication/repl_dev/raft_state_machine.cpp @@ -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; @@ -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; @@ -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; } diff --git a/src/lib/replication/repl_dev/raft_state_machine.h b/src/lib/replication/repl_dev/raft_state_machine.h index fdb1c1b9f..8f00cec43 100644 --- a/src/lib/replication/repl_dev/raft_state_machine.h +++ b/src/lib/replication/repl_dev/raft_state_machine.h @@ -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 >; @@ -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); }; diff --git a/src/tests/test_common/raft_repl_test_base.hpp b/src/tests/test_common/raft_repl_test_base.hpp index 7dc364411..7445568b8 100644 --- a/src/tests/test_common/raft_repl_test_base.hpp +++ b/src/tests/test_common/raft_repl_test_base.hpp @@ -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; } @@ -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; }