diff --git a/src/kvstore/Listener.cpp b/src/kvstore/Listener.cpp index 3121031e043..523e733c00b 100644 --- a/src/kvstore/Listener.cpp +++ b/src/kvstore/Listener.cpp @@ -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 { diff --git a/src/kvstore/raftex/RaftPart.h b/src/kvstore/raftex/RaftPart.h index 83b097e454b..a495cdf1c20 100644 --- a/src/kvstore/raftex/RaftPart.h +++ b/src/kvstore/raftex/RaftPart.h @@ -557,6 +557,17 @@ class RaftPart : public std::enable_shared_from_this { */ 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 -- the index of the peer @@ -625,17 +636,6 @@ class RaftPart : public std::enable_shared_from_this { */ 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 diff --git a/src/kvstore/raftex/SnapshotManager.cpp b/src/kvstore/raftex/SnapshotManager.cpp index 7589e0b2747..0a38eb93e7b 100644 --- a/src/kvstore/raftex/SnapshotManager.cpp +++ b/src/kvstore/raftex/SnapshotManager.cpp @@ -78,11 +78,10 @@ folly::Future>> 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()