Skip to content

Commit

Permalink
fix listener can't receive snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 committed May 10, 2022
1 parent 1fd89af commit 6881810
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/kvstore/Listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ void Listener::doApply() {
if (isStopped()) {
return;
}
if (needToCleanupSnapshot()) {
cleanupSnapshot();
}
// todo(doodle): only put is handled, all remove is ignored for now
folly::via(executor_.get(), [this] {
SCOPE_EXIT {
Expand Down
22 changes: 11 additions & 11 deletions src/kvstore/raftex/RaftPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,17 @@ class RaftPart : public std::enable_shared_from_this<RaftPart> {
*/
void removePeer(const HostAddr& peer);

/**
* @brief Return whether need to clean snapshot when a node has not received the snapshot for a
* period of time
*/
bool needToCleanupSnapshot();

/**
* @brief Convert to follower when snapshot has been outdated
*/
void cleanupSnapshot();

private:
// A list of <idx, resp>
// idx -- the index of the peer
Expand Down Expand Up @@ -625,17 +636,6 @@ class RaftPart : public std::enable_shared_from_this<RaftPart> {
*/
bool needToStartElection();

/**
* @brief Return whether need to clean snapshot when a node has not received the snapshot for a
* period of time
*/
bool needToCleanupSnapshot();

/**
* @brief Convert to follower when snapshot has been outdated
*/
void cleanupSnapshot();

/**
* @brief The method sends out AskForVote request. Return true if I have been granted majority
* votes on proposedTerm, no matter isPreVote or not
Expand Down
7 changes: 3 additions & 4 deletions src/kvstore/raftex/SnapshotManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ folly::Future<StatusOr<std::pair<LogID, TermID>>> SnapshotManager::sendSnapshot(
}
return true;
} else {
VLOG(2) << part->idStr_ << "Sending snapshot failed, we don't retry anymore! "
<< "The error code is "
VLOG(2) << part->idStr_ << "Sending snapshot failed, the error code is "
<< apache::thrift::util::enumNameSafe(resp.get_error_code());
p.setValue(Status::Error("Send snapshot failed!"));
return false;
sleep(1);
continue;
}
} catch (const std::exception& e) {
VLOG(3) << part->idStr_ << "Send snapshot failed, exception " << e.what()
Expand Down

0 comments on commit 6881810

Please sign in to comment.