Ejemplo n.º 1
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
}
Ejemplo n.º 2
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_);

}
Ejemplo n.º 3
0
grpc::Status implement_status(Authorize &&authorize, F &&f) {
  try {
    const grpc::Status auth = authorize();
    if (!auth.ok()) return auth;
  } catch (std::exception &e) {
    return grpc::Status(grpc::UNKNOWN, "Unable to authorize");
  } catch (...) {
    return grpc::Status(grpc::UNKNOWN, "Unable to authorize");
  }
  try {
    return f();
  } catch (std::exception &e) {
    return grpc::Status(grpc::UNKNOWN, e.what());
  } catch (...) {
    return grpc::Status(grpc::UNKNOWN, "Unknown");
  }
}
Ejemplo n.º 4
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
}