Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxi Chen <[email protected]>
  • Loading branch information
xiaoxichen committed Dec 18, 2024
1 parent 04f2915 commit 30668dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/lib/replication/repl_dev/raft_repl_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,11 +1286,11 @@ nuraft::cb_func::ReturnCode RaftReplDev::raft_event(nuraft::cb_func::Type type,
if (ret == nuraft::cb_func::ReturnCode::Ok) { m_state_machine->inc_next_batch_size_hint(); }
return ret;
}
case nuraft::cb_func::Type::JoinedCluster:
case nuraft::cb_func::Type::BecomeFollower: {
become_follower_cb();
return nuraft::cb_func::ReturnCode::Ok;
}
case nuraft::cb_func::Type::JoinedCluster:
case nuraft::cb_func::Type::BecomeLeader: {
become_leader_cb();
return nuraft::cb_func::ReturnCode::Ok;
Expand Down
28 changes: 14 additions & 14 deletions src/lib/replication/repl_dev/raft_repl_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ class RaftReplDev : public ReplDev,
cshared< ReplDevCPContext > get_cp_ctx(CP* cp);
void cp_cleanup(CP* cp);
void become_ready();
void become_leader_cb() {
auto new_gate = raft_server()->get_last_log_idx();
repl_lsn_t existing_gate = 0;
if (!m_traffic_ready_lsn.compare_exchange_strong(existing_gate, new_gate)) {
// was a follower, m_traffic_ready_lsn should be zero on follower.
RD_REL_ASSERT(existing_gate == 0, "existing gate should be zero");
}
RD_LOGD("become_leader_cb: setting traffic_ready_lsn from {} to {}", existing_gate, new_gate);
};
void become_follower_cb() {
// m_traffic_ready_lsn should be zero on follower.
m_traffic_ready_lsn.store(0);
RD_LOGD("become_follower_cb setting traffic_ready_lsn to 0");
}

/// @brief This method is called when the data journal is compacted
///
Expand Down Expand Up @@ -275,20 +289,6 @@ class RaftReplDev : public ReplDev,
nuraft::ptr< nuraft::log_store > load_log_store() override;
int32_t server_id() override;
void system_exit(const int exit_code) override { LOGINFO("System exiting with code [{}]", exit_code); }
void become_leader_cb() {
auto new_gate = get_last_commit_lsn();
repl_lsn_t existing_gate = 0;
if (!m_traffic_ready_lsn.compare_exchange_strong(existing_gate, new_gate)) {
// was a follower, m_traffic_ready_lsn should be zero on follower.
RD_REL_ASSERT(existing_gate == 0, "existing gate should be zero");
}
RD_LOGD("become_leader_cb: setting traffic_ready_lsn from {} to {}", existing_gate, new_gate);
};
void become_follower_cb() {
// m_traffic_ready_lsn should be zero on follower.
m_traffic_ready_lsn.store(0);
RD_LOGD("become_follower_cb setting traffic_ready_lsn to 0");
}

//////////////// All nuraft_mesg::mesg_state_mgr overrides ///////////////////////
uint32_t get_logstore_id() const override;
Expand Down

0 comments on commit 30668dc

Please sign in to comment.