Пример #1
0
void RaftConsensus::handleInstallSnapShotResponse(const InstallSnapShotResponse& resp, const grpc::Status& status) {
    if (!status.ok() && status.error_code() != grpc::StatusCode::CANCELLED) {
        std::cerr << "InstallSnapShot RCP failed: " << status.error_message() << std::endl;
        return;
    }

    std::lock_guard<std::mutex> lock(mu_);

}
Пример #2
0
void RaftConsensus::handleAppendEntriesResponse(const AppendEntriesResponse& resp, const grpc::Status& status) {
    if (!status.ok() && status.error_code() != grpc::StatusCode::CANCELLED) {
        std::cerr << "AppendEntries RPC failed: " << status.error_message() << std::endl;
        return;
    }

    std::lock_guard<std::mutex> lock(mu_);
    //TODO
}
Пример #3
0
// src_term: 本地发起投票请求时当时本地的term
void RaftConsensus::handleVoteResponse(uint64_t src_term, const VoteResponse& resp, const grpc::Status& status) {
    if (!status.ok() && status.error_code() != grpc::StatusCode::CANCELLED) {
        std::cerr << "RequestVote RPC failed: " << status.error_message() << std::endl;
        return;
    }

    std::lock_guard<std::mutex> lock(mu_);
    if (src_term != term_) {
        std::cout << "Mismatched term in VoteResponse:" << src_term <<
            ", cur:" << term_ << std::endl;
        return;
    }
    else if (StateCandidate == state_) {
        if (resp.votegranted()) {
            ++votes_;
            if (votes_ >= majority_)
                becomeLeader();
        }
    }

    //TODO
}