Documentation ¶
Index ¶
- type RealRaftProtobufServer
- func (rpcs *RealRaftProtobufServer) AppendEntry(context context.Context, request *raftpb.AppendEntryRequest) (*raftpb.AppendEntryReply, error)
- func (rpcs *RealRaftProtobufServer) Destroy() error
- func (rpcs *RealRaftProtobufServer) Heartbeat(context context.Context, request *raftpb.HeartbeatRequest) (*raftpb.HeartbeatReply, error)
- func (rpcs *RealRaftProtobufServer) InstallSnapshot(stream raftpb.RaftProtocol_InstallSnapshotServer) error
- func (rpcs *RealRaftProtobufServer) RequestVote(context context.Context, request *raftpb.GrantVoteRequest) (*raftpb.GrantVoteReply, error)
- func (rpcs *RealRaftProtobufServer) Start() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RealRaftProtobufServer ¶
type RealRaftProtobufServer struct { // RPCPort is the port on which the protocol server // listens to. This must be different from API Port which // is the port API-server listens to RPCPort uint32 // Voter is responsible for making voting decisions // on behalf of the node *state.Voter // RaftStateManager is responsible for managing state related to raft state.RaftStateManager // LeaderElectionManager is needed to reset the election timeout election.LeaderElectionManager // SnapshotHandler is required to create new epoch and build // new snapshot when install snapshot is received log.SnapshotHandler // The component has lifecycle - it can be started and destroyed common.ComponentLifecycle // contains filtered or unexported fields }
RealRaftProtobufServer is responsible for handling all incoming communication to this node. In other words, all incoming messages must come here
func NewRealRaftProtobufServer ¶
func NewRealRaftProtobufServer( rpcPort uint32, voter *state.Voter, raftStateMgr state.RaftStateManager, electionMgr election.LeaderElectionManager, snapshotHandler log.SnapshotHandler, ) *RealRaftProtobufServer
NewRealRaftProtobufServer creates a new instance of RealRaftProtocolServer But this method does not start the server. In other words, server won't be listening to incoming messages at the given port.
func (*RealRaftProtobufServer) AppendEntry ¶
func (rpcs *RealRaftProtobufServer) AppendEntry(context context.Context, request *raftpb.AppendEntryRequest) (*raftpb.AppendEntryReply, error)
AppendEntry checks if it is possible to append entry to the log. If it is then it appends entry to the log at the given index in the given term. If there are any failures then the same will be returned and the client must retry.
func (*RealRaftProtobufServer) Destroy ¶
func (rpcs *RealRaftProtobufServer) Destroy() error
Destroy brings down the server so that other nodes can no longer connect to this node. The component becomes non-operational and this function is irreversible.
func (*RealRaftProtobufServer) Heartbeat ¶
func (rpcs *RealRaftProtobufServer) Heartbeat(context context.Context, request *raftpb.HeartbeatRequest) (*raftpb.HeartbeatReply, error)
Heartbeat tries to update maximum committed index obtained from the leader. If a heartbeat is received when the node is not a follower then it is not considered based on certain conditions arount TermID. In reply, it tells the node sending heartbeat if it accepts the node as the leader
func (*RealRaftProtobufServer) InstallSnapshot ¶
func (rpcs *RealRaftProtobufServer) InstallSnapshot(stream raftpb.RaftProtocol_InstallSnapshotServer) error
InstallSnapshot tries to obtain snapshot from the leader and applies it so that the write-ahead log can be fast-forwarded and older entries can be cleaned up. The snapshot transfer must be atomic. In other words, on failure, snapshot being transferred must be discarded.
func (*RealRaftProtobufServer) RequestVote ¶
func (rpcs *RealRaftProtobufServer) RequestVote(context context.Context, request *raftpb.GrantVoteRequest) (*raftpb.GrantVoteReply, error)
RequestVote decides if this node should grant vote to the remote node for the term based on certain criteria like the length of the log. If there is any failure in the component or network then it must be assumed that the node is not in a position to grant vote and is taken to be 'false'
func (*RealRaftProtobufServer) Start ¶
func (rpcs *RealRaftProtobufServer) Start() error
Start brings up the server so that it listens at the port specified by RPCPort and starts accepting connections and incoming protobuf messages.