Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwmao committed Nov 28, 2024
1 parent 4b4418e commit a5f8054
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 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.17"
version = "6.5.18"

homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
Expand Down
2 changes: 2 additions & 0 deletions src/include/homestore/replication/repl_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
8 changes: 6 additions & 2 deletions src/lib/replication/repl_dev/raft_repl_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions src/lib/replication/repl_dev/raft_state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
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 @@ -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 >;
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_common/raft_repl_test_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a5f8054

Please sign in to comment.