Documentation ¶
Overview ¶
Package raft Core Raft implementation - Consensus Module.
Eli Bendersky [https://eli.thegreenplace.net] This code is in the public domain.
Package raft Server container for a Raft Consensus Module. Exposes Raft to the network and enables RPCs between Raft peers.
Eli Bendersky [https://eli.thegreenplace.net] This code is in the public domain.
Index ¶
- type AppendEntriesArgs
- type AppendEntriesReply
- type Application
- type CMState
- type CommitEntry
- type CommittedResult
- type ConsensusModule
- func (cm *ConsensusModule) AppendEntries(args AppendEntriesArgs, reply *AppendEntriesReply) error
- func (cm *ConsensusModule) Report() (id int, term int, isLeader bool)
- func (cm *ConsensusModule) RequestVote(args RequestVoteArgs, reply *RequestVoteReply) error
- func (cm *ConsensusModule) Stop()
- func (cm *ConsensusModule) Submit(command interface{}) (interface{}, bool)
- type LogEntry
- type RequestVoteArgs
- type RequestVoteReply
- type Server
- func (s *Server) Call(id int, serviceMethod string, args interface{}, reply interface{}) error
- func (s *Server) ConnectToPeer(peerId int, addr net.Addr) error
- func (s *Server) DisconnectAll()
- func (s *Server) DisconnectPeer(peerId int) error
- func (s *Server) GetListenAddr() net.Addr
- func (s *Server) Serve()
- func (s *Server) Shutdown()
- func (s *Server) Submit(command interface{}) (interface{}, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppendEntriesArgs ¶
type AppendEntriesArgs struct { Term int LeaderId int PrevLogIndex int PrevLogTerm int Entries []LogEntry LeaderCommit int }
AppendEntriesArgs See figure 2 in the paper.
type AppendEntriesReply ¶
type Application ¶
type Application interface {
ApplyCommand(interface{}) interface{}
}
type CommitEntry ¶
type CommitEntry struct { // Command is the client command being committed. Command interface{} // Index is the log index at which the client command is committed. Index int // Term is the Raft term at which the client command is committed. Term int }
CommitEntry is the data reported by Raft to the commit channel. Each commit entry notifies the client that consensus was reached on a command, and it can be applied to the client's state machine.
type CommittedResult ¶
type CommittedResult struct { Result interface{} Index int }
type ConsensusModule ¶
type ConsensusModule struct {
// contains filtered or unexported fields
}
ConsensusModule (CM) implements a single node of Raft consensus.
func NewConsensusModule ¶
func NewConsensusModule(server *Server) *ConsensusModule
NewConsensusModule creates a new CM with the given ID, list of peer IDs and server. The ready channel signals the CM that all peers are connected, and it's safe to start its state machine. commitChan is going to be used by the CM to send log entries that have been committed by the Raft cluster.
func (*ConsensusModule) AppendEntries ¶
func (cm *ConsensusModule) AppendEntries(args AppendEntriesArgs, reply *AppendEntriesReply) error
func (*ConsensusModule) Report ¶
func (cm *ConsensusModule) Report() (id int, term int, isLeader bool)
Report reports the state of this CM.
func (*ConsensusModule) RequestVote ¶
func (cm *ConsensusModule) RequestVote(args RequestVoteArgs, reply *RequestVoteReply) error
RequestVote RPC.
func (*ConsensusModule) Stop ¶
func (cm *ConsensusModule) Stop()
Stop stops this CM, cleaning up its state. This method returns quickly, but it may take a bit of time (up to ~election timeout) for all goroutines to exit.
func (*ConsensusModule) Submit ¶
func (cm *ConsensusModule) Submit(command interface{}) (interface{}, bool)
Submit submits a new command to the CM. This function doesn't block; clients read the commit channel passed in the constructor to be notified of new committed entries. It returns true iff this CM is the leader - in which case the command is accepted. If false is returned, the client will have to find a different CM to submit this command to.
type RequestVoteArgs ¶
RequestVoteArgs See figure 2 in the paper.
type RequestVoteReply ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps a raft.ConsensusModule along with a rpc.Server that exposes its methods as RPC endpoints. It also manages the peers of the Raft server. The main goal of this type is to simplify the code of raft.Server for presentation purposes. raft.ConsensusModule has a *Server to do its peer communication and doesn't have to worry about the specifics of running an RPC server.
func NewServer ¶
func NewServer(serverId int, num int, ready chan interface{}, app Application) *Server
func (*Server) DisconnectAll ¶
func (s *Server) DisconnectAll()
DisconnectAll closes all the client connections to peers for this server.
func (*Server) DisconnectPeer ¶
DisconnectPeer disconnects this server from the peer identified by peerId.