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 to bug in get_peer_info #246

Merged
merged 1 commit into from
Aug 5, 2021
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
14 changes: 14 additions & 0 deletions include/libnuraft/peer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public:
, rpc_backoff_( ctx.get_params()->rpc_failure_backoff_ )
, max_hb_interval_( ctx.get_params()->max_hb_interval() )
, next_log_idx_(0)
, last_accepted_log_idx_(0)
, next_batch_size_hint_in_bytes_(0)
, matched_idx_(0)
, busy_flag_(false)
Expand Down Expand Up @@ -151,6 +152,14 @@ public:
next_log_idx_ = idx;
}

uint64_t get_last_accepted_log_idx() const {
return last_accepted_log_idx_;
}

void set_last_accepted_log_idx(uint64_t to) {
last_accepted_log_idx_ = to;
}

int64 get_next_batch_size_hint_in_bytes() const {
return next_batch_size_hint_in_bytes_;
}
Expand Down Expand Up @@ -344,6 +353,11 @@ private:
*/
std::atomic<ulong> next_log_idx_;

/**
* The last log index accepted by this server.
*/
std::atomic<uint64_t> last_accepted_log_idx_;

/**
* Hint of the next log batch size in bytes.
*/
Expand Down
1 change: 1 addition & 0 deletions src/handle_append_entries.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ void raft_server::handle_append_entries_resp(resp_msg& resp) {
p_tr("peer %d, prev matched idx: %ld, new matched idx: %ld",
p->get_id(), prev_matched_idx, new_matched_idx);
p->set_matched_idx(new_matched_idx);
p->set_last_accepted_log_idx(new_matched_idx);
}
cb_func::Param param(id_, leader_, p->get_id());
param.ctx = &new_matched_idx;
Expand Down
4 changes: 2 additions & 2 deletions src/raft_server.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,7 @@ raft_server::peer_info raft_server::get_peer_info(int32 srv_id) const {
peer_info ret;
ptr<peer> pp = entry->second;
ret.id_ = pp->get_id();
ret.last_log_idx_ = pp->get_next_log_idx() - 1;
ret.last_log_idx_ = pp->get_last_accepted_log_idx();
ret.last_succ_resp_us_ = pp->get_resp_timer_us();
return ret;
}
Expand All @@ -1538,7 +1538,7 @@ std::vector<raft_server::peer_info> raft_server::get_peer_info_all() const {
peer_info pi;
ptr<peer> pp = entry.second;
pi.id_ = pp->get_id();
pi.last_log_idx_ = pp->get_next_log_idx() - 1;
pi.last_log_idx_ = pp->get_last_accepted_log_idx();
pi.last_succ_resp_us_ = pp->get_resp_timer_us();
ret.push_back(pi);
}
Expand Down