Skip to content

Commit

Permalink
Merge pull request #216 from PFZheng/master
Browse files Browse the repository at this point in the history
fix leader timestamp value described in raft web page
  • Loading branch information
Edward-xk authored May 26, 2020
2 parents b26c4f6 + e1c00fa commit dd81e5b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/braft/lease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ void FollowerLease::renew(const PeerId& leader_id) {
_last_leader_timestamp = butil::monotonic_time_ms();
}

int64_t FollowerLease::last_leader_timestamp() {
return _last_leader_timestamp;
}

int64_t FollowerLease::votable_time_from_now() {
if (!FLAGS_raft_enable_leader_lease) {
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/braft/lease.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class FollowerLease {
bool expired();
void reset();
void reset_election_timeout_ms(int64_t election_timeout_ms, int64_t max_clock_drift_ms);
int64_t last_leader_timestamp();

private:
int64_t _election_timeout_ms;
Expand Down
4 changes: 1 addition & 3 deletions src/braft/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ static inline int heartbeat_timeout(int election_timeout) {
NodeImpl::NodeImpl(const GroupId& group_id, const PeerId& peer_id)
: _state(STATE_UNINITIALIZED)
, _current_term(0)
, _last_leader_timestamp(butil::monotonic_time_ms())
, _group_id(group_id)
, _server_id(peer_id)
, _conf_ctx(this)
Expand All @@ -155,7 +154,6 @@ NodeImpl::NodeImpl(const GroupId& group_id, const PeerId& peer_id)
NodeImpl::NodeImpl()
: _state(STATE_UNINITIALIZED)
, _current_term(0)
, _last_leader_timestamp(butil::monotonic_time_ms())
, _group_id()
, _server_id()
, _conf_ctx(this)
Expand Down Expand Up @@ -2537,7 +2535,7 @@ void NodeImpl::describe(std::ostream& os, bool use_html) {

// No replicator attached to nodes that are not leader;
_replicator_group.list_replicators(&replicators);
const int64_t leader_timestamp = _last_leader_timestamp;
const int64_t leader_timestamp = _follower_lease.last_leader_timestamp();
const bool readonly = (_node_readonly || _majority_nodes_readonly);
lck.unlock();
const char *newline = use_html ? "<br>" : "\r\n";
Expand Down
1 change: 0 additions & 1 deletion src/braft/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ friend class butil::RefCountedThreadSafe<NodeImpl>;

State _state;
int64_t _current_term;
int64_t _last_leader_timestamp;
PeerId _leader_id;
PeerId _voted_id;
VoteBallotCtx _vote_ctx; // candidate vote ctx
Expand Down

0 comments on commit dd81e5b

Please sign in to comment.