diff --git a/conanfile.py b/conanfile.py index 606d1a6ea..99e129017 100644 --- a/conanfile.py +++ b/conanfile.py @@ -9,7 +9,7 @@ class HomestoreConan(ConanFile): name = "homestore" - version = "6.5.17" + version = "6.5.18" homepage = "https://github.com/eBay/Homestore" description = "HomeStore Storage Engine" diff --git a/src/include/homestore/replication/repl_dev.h b/src/include/homestore/replication/repl_dev.h index 30b437182..335cda834 100644 --- a/src/include/homestore/replication/repl_dev.h +++ b/src/include/homestore/replication/repl_dev.h @@ -124,6 +124,8 @@ struct snapshot_obj { bool is_last_obj{false}; }; +//HomeStore has some meta information to be transmitted during the baseline resync, +//Although now only dsn needs to be synced, this structure is defined as a general message, and we can easily add data if needed in the future. struct snp_repl_dev_data { uint64_t magic_num{HOMESTORE_RESYNC_DATA_MAGIC}; uint32_t protocol_version{HOMESTORE_RESYNC_DATA_PROTOCOL_VERSION_V1}; diff --git a/src/lib/replication/repl_dev/raft_repl_dev.cpp b/src/lib/replication/repl_dev/raft_repl_dev.cpp index 7ec8d5285..33dc11765 100644 --- a/src/lib/replication/repl_dev/raft_repl_dev.cpp +++ b/src/lib/replication/repl_dev/raft_repl_dev.cpp @@ -1510,15 +1510,19 @@ bool RaftReplDev::apply_snp_resync_data(nuraft::buffer& data) { return false; } auto received_crc = msg->crc; - msg->crc = 0; RD_LOGD("received snapshot resync msg, dsn={}, crc={}, received crc={}", msg->dsn, msg->crc, received_crc); + msg->crc = 0; auto computed_crc = crc32_ieee(0, 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); return false; } - m_next_dsn = msg->dsn; + if (msg->dsn > m_next_dsn) { + m_next_dsn = msg->dsn; + RD_LOGD("Update next_dsn from {} to {}", m_next_dsn.load(), msg->dsn); + return true; + } return true; } diff --git a/src/lib/replication/repl_dev/raft_state_machine.cpp b/src/lib/replication/repl_dev/raft_state_machine.cpp index b95912601..00048f895 100644 --- a/src/lib/replication/repl_dev/raft_state_machine.cpp +++ b/src/lib/replication/repl_dev/raft_state_machine.cpp @@ -297,6 +297,8 @@ void RaftStateMachine::create_snapshot(nuraft::snapshot& s, nuraft::async_result int RaftStateMachine::read_logical_snp_obj(nuraft::snapshot& s, void*& user_ctx, ulong obj_id, raft_buf_ptr_t& data_out, 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) { // This is the preserved msg for homestore to resync data m_rd.create_snp_resync_data(data_out); @@ -326,6 +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 (is_last_obj) { + //make sure the changes are flushed. + hs()->cp_mgr().trigger_cp_flush(true /* force */); + } if ((obj_id & snp_obj_id_type_mask) == 0) { // Homestore preserved msg if (m_rd.apply_snp_resync_data(data)) { diff --git a/src/lib/replication/repl_dev/raft_state_machine.h b/src/lib/replication/repl_dev/raft_state_machine.h index 2387f8457..fdb1c1b9f 100644 --- a/src/lib/replication/repl_dev/raft_state_machine.h +++ b/src/lib/replication/repl_dev/raft_state_machine.h @@ -86,7 +86,9 @@ class StateMachineStore; #define RD_LOGE(...) RD_LOG(ERROR, ##__VA_ARGS__) #define RD_LOGC(...) RD_LOG(CRITICAL, ##__VA_ARGS__) -static constexpr uint64_t snp_obj_id_type_mask = 0x8000000000000000; +// 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; using AsyncNotify = folly::SemiFuture< folly::Unit >; using AsyncNotifier = folly::Promise< folly::Unit >; diff --git a/src/tests/test_common/raft_repl_test_base.hpp b/src/tests/test_common/raft_repl_test_base.hpp index 690cbcc6f..7dc364411 100644 --- a/src/tests/test_common/raft_repl_test_base.hpp +++ b/src/tests/test_common/raft_repl_test_base.hpp @@ -183,10 +183,10 @@ class TestReplicatedDB : public homestore::ReplDevListener { } static int64_t get_next_lsn(uint64_t& obj_id) { - return obj_id & 0x7fffffffffffffff; + return obj_id & ((1ULL << 63) - 1); } static void set_resync_msg_type_bit(uint64_t& obj_id) { - obj_id |= 1ull << 63; + obj_id |= 1ULL << 63; } int read_snapshot_obj(shared< snapshot_context > context, shared< snapshot_obj > snp_data) override {