Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix raft repl dev ut #543

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4.56"
version = "6.4.57"

homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
Expand Down
19 changes: 13 additions & 6 deletions src/tests/test_raft_repl_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class TestReplicatedDB : public homestore::ReplDevListener {
std::unique_lock lk(db_mtx_);
inmem_db_.insert_or_assign(k, v);
lsn_index_.emplace(lsn, v);
last_data_committed_lsn = lsn;
++commit_count_;
}

Expand Down Expand Up @@ -213,7 +214,7 @@ class TestReplicatedDB : public homestore::ReplDevListener {
sisl::io_blob_safe blob{static_cast< uint32_t >(kv_snapshot_data_size)};
std::memcpy(blob.bytes(), kv_snapshot_data.data(), kv_snapshot_data_size);
snp_data->blob = std::move(blob);
snp_data->is_last_obj = true;
snp_data->is_last_obj = false;
LOGINFOMOD(replication, "[Replica={}] Read logical snapshot callback obj_id={} term={} idx={} num_items={}",
g_helper->replica_num(), snp_data->offset, s->get_last_log_term(), s->get_last_log_idx(),
kv_snapshot_data.size());
Expand All @@ -233,10 +234,8 @@ class TestReplicatedDB : public homestore::ReplDevListener {

void write_snapshot_data(shared< snapshot_context > context, shared< snapshot_data > snp_data) override {
auto s = std::dynamic_pointer_cast< nuraft_snapshot_context >(context)->nuraft_snapshot();
auto last_committed_idx =
std::dynamic_pointer_cast< RaftReplDev >(repl_dev())->raft_server()->get_committed_log_idx();
if (snp_data->offset == 0) {
snp_data->offset = last_committed_idx + 1;
snp_data->offset = last_data_committed_lsn + 1;
LOGINFOMOD(replication, "[Replica={}] Save logical snapshot callback return obj_id={}",
g_helper->replica_num(), snp_data->offset);
return;
Expand All @@ -260,6 +259,7 @@ class TestReplicatedDB : public homestore::ReplDevListener {
snapshot_data_write(value.data_size_, value.data_pattern_, out_blkids);
value.blkid_ = out_blkids;
}
last_data_committed_lsn = value.lsn_;
inmem_db_.insert_or_assign(key, value);
++commit_count_;
ptr++;
Expand All @@ -269,7 +269,10 @@ class TestReplicatedDB : public homestore::ReplDevListener {
"[Replica={}] Save logical snapshot callback obj_id={} term={} idx={} is_last={} num_items={}",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Move log one line after updating the snp_data->offset.

Copy link
Contributor Author

@JacksonYao287 JacksonYao287 Sep 11, 2024

Choose a reason for hiding this comment

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

this log wants to print out what we receive from leader , so I think we should keep it as this

g_helper->replica_num(), snp_data->offset, s->get_last_log_term(), s->get_last_log_idx(),
snp_data->is_last_obj, num_items);
snp_data->offset = last_committed_idx + 1;

xiaoxichen marked this conversation as resolved.
Show resolved Hide resolved
// before we finish install snapshot, raft_server()->get_committed_log_idx() will always be the same. so we need
// last_data_committed_lsn to notify leader to transfer new data to follower.
snp_data->offset = last_data_committed_lsn + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggesting snapshot_write_to_lsn instead of last_data_committed_lsn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is will be updated in on_commit

}

bool apply_snapshot(shared< snapshot_context > context) override {
Expand Down Expand Up @@ -391,6 +394,9 @@ class TestReplicatedDB : public homestore::ReplDevListener {
std::map< Key, Value > inmem_db_;
std::map< int64_t, Value > lsn_index_;
uint64_t commit_count_{0};
// this is the last lsn for data, might not be the same with the real last committed lsn
// which should be get by raft_server()->get_committed_log_idx()
uint64_t last_data_committed_lsn{0};
std::shared_mutex db_mtx_;
std::shared_ptr< snapshot_context > m_last_snapshot{nullptr};
std::mutex m_snapshot_lock;
Expand Down Expand Up @@ -745,6 +751,7 @@ TEST_F(RaftReplDevTest, Resync_From_Non_Originator) {
g_helper->sync_for_cleanup_start();
}

#if 0
TEST_F(RaftReplDevTest, Leader_Restart) {
LOGINFO("Homestore replica={} setup completed", g_helper->replica_num());
g_helper->sync_for_test_start();
Expand All @@ -769,7 +776,7 @@ TEST_F(RaftReplDevTest, Leader_Restart) {
g_helper->sync_for_cleanup_start();
}

#if 0

TEST_F(RaftReplDevTest, Drop_Raft_Entry_Switch_Leader) {
LOGINFO("Homestore replica={} setup completed", g_helper->replica_num());
g_helper->sync_for_test_start();
Expand Down
Loading