Prevent snapshot recovery when exiting
Summary: Sometimes, when the leader resigns it's leadership, a newly elected leader would send the old leader `AppendEntriesRPC` that would cause the snapshot recovery to happen. This diff prevents that. Reviewers: mferencevic, ipaljak Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1943
This commit is contained in:
parent
6a9acb717d
commit
e1ad5cd803
@ -1,6 +1,7 @@
|
|||||||
#include "raft/raft_server.hpp"
|
#include "raft/raft_server.hpp"
|
||||||
|
|
||||||
#include <kj/std/iostream.h>
|
#include <kj/std/iostream.h>
|
||||||
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -128,7 +129,7 @@ void RaftServer::Start() {
|
|||||||
// [Raft paper 5.1]
|
// [Raft paper 5.1]
|
||||||
// "If a server receives a request with a stale term, it rejects the
|
// "If a server receives a request with a stale term, it rejects the
|
||||||
// request"
|
// request"
|
||||||
if (req.term < current_term_) {
|
if (exiting_ || req.term < current_term_) {
|
||||||
AppendEntriesRes res(false, current_term_);
|
AppendEntriesRes res(false, current_term_);
|
||||||
Save(res, res_builder);
|
Save(res, res_builder);
|
||||||
return;
|
return;
|
||||||
@ -744,9 +745,9 @@ void RaftServer::SendLogEntries(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!reply.success) {
|
if (!reply.success) {
|
||||||
DCHECK(next_index_[peer_id] > 1)
|
// Replication can fail for the first log entry if the peer that we're
|
||||||
<< "Log replication should not fail for first log entry";
|
// sending the entry is in the process of shutting down.
|
||||||
--next_index_[peer_id];
|
next_index_[peer_id] = std::max(next_index_[peer_id] - 1, 1UL);
|
||||||
} else {
|
} else {
|
||||||
uint64_t new_match_index = request_prev_log_index + request_entries.size();
|
uint64_t new_match_index = request_prev_log_index + request_entries.size();
|
||||||
DCHECK(match_index_[peer_id] <= new_match_index)
|
DCHECK(match_index_[peer_id] <= new_match_index)
|
||||||
|
Loading…
Reference in New Issue
Block a user