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

lease: pre_vote should consider leader lease #17

Merged
merged 1 commit into from
Jul 11, 2024
Merged
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
17 changes: 12 additions & 5 deletions src/braft/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2196,17 +2196,24 @@ int NodeImpl::handle_pre_vote_request(const RequestVoteRequest* request,
break;
}

// get last_log_id outof node mutex
// get last_log_id and leader_in_lease outof node mutex
lck.unlock();
LogId last_log_id = _log_manager->last_log_id(true);
bool leader_in_lease = is_leader_lease_valid();
lck.lock();

// pre_vote not need ABA check after unlock&lock
int64_t votable_time = _follower_lease.votable_time_from_now();
bool grantable = (LogId(request->last_log_index(),
request->last_log_term()) >= last_log_id);
if (grantable) {
granted = (votable_time == 0);
rejected_by_lease = (votable_time > 0);
if (_state == STATE_LEADER) {
rejected_by_lease = leader_in_lease;
} else {
int64_t votable_time = _follower_lease.votable_time_from_now();
rejected_by_lease = (votable_time > 0);
}
// set granted to true if it is grantable and not rejected by lease.
granted = !rejected_by_lease;
}

LOG(INFO) << "node " << _group_id << ":" << _server_id
Expand Down Expand Up @@ -2273,7 +2280,7 @@ int NodeImpl::handle_request_vote_request(const RequestVoteRequest* request,
break;
}

// get last_log_id outof node mutex
// get last_log_id and leader lease outof node mutex
lck.unlock();
LogId last_log_id = _log_manager->last_log_id(true);
lck.lock();
Expand Down
Loading