// ---------------------------------------------------------------------- // File: RaftUtils.hh // Author: Georgios Bitzes - CERN // ---------------------------------------------------------------------- /************************************************************************ * quarkdb - a redis-like highly available key-value store * * Copyright (C) 2016 CERN/Switzerland * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* ************************************************************************/ #ifndef QUARKDB_RAFT_UTILS_HH #define QUARKDB_RAFT_UTILS_HH #include "raft/RaftCommon.hh" #include "Common.hh" #include "raft/RaftTimeouts.hh" #include namespace quarkdb { //------------------------------------------------------------------------------ // Forward declarations //------------------------------------------------------------------------------ class RaftState; class RaftLease; class RaftContactDetails; class RaftParser { public: static bool appendEntries(RedisRequest &&source, RaftAppendEntriesRequest &dest); static bool appendEntriesResponse(const qclient::redisReplyPtr &source, RaftAppendEntriesResponse &dest); static bool heartbeat(const RedisRequest &source, RaftHeartbeatRequest &dest); static bool heartbeatResponse(const qclient::redisReplyPtr &source, RaftHeartbeatResponse &dest); static bool voteRequest(RedisRequest &source, RaftVoteRequest &dest); static bool voteResponse(const qclient::redisReplyPtr &source, RaftVoteResponse &dest); static bool fetchResponse(redisReply *source, RaftEntry &entry); static bool fetchLastResponse(const qclient::redisReplyPtr &source, std::vector &entries); }; class RaftElection { public: static ElectionOutcome performPreVote(RaftVoteRequest votereq, RaftState &state, const RaftContactDetails &contactDetails); static ElectionOutcome perform(RaftVoteRequest votereq, RaftState &state, RaftLease &lease, const RaftContactDetails &contactDetails); }; } #endif