influxdb/request_vote.go

48 lines
1.4 KiB
Go
Raw Normal View History

2013-04-28 04:51:17 +00:00
package raft
//------------------------------------------------------------------------------
//
// Typedefs
//
//------------------------------------------------------------------------------
// The request sent to a server to vote for a candidate to become a leader.
type RequestVoteRequest struct {
2013-05-01 05:21:56 +00:00
peer *Peer
2013-04-28 21:23:21 +00:00
Term uint64 `json:"term"`
CandidateName string `json:"candidateName"`
LastLogIndex uint64 `json:"lastLogIndex"`
LastLogTerm uint64 `json:"lastLogTerm"`
2013-04-28 04:51:17 +00:00
}
// The response returned from a server after a vote for a candidate to become a leader.
type RequestVoteResponse struct {
2013-05-01 05:21:56 +00:00
peer *Peer
2013-04-28 21:23:21 +00:00
Term uint64 `json:"term"`
VoteGranted bool `json:"voteGranted"`
}
//------------------------------------------------------------------------------
//
// Constructors
//
//------------------------------------------------------------------------------
// Creates a new RequestVote request.
func NewRequestVoteRequest(term uint64, candidateName string, lastLogIndex uint64, lastLogTerm uint64) *RequestVoteRequest {
return &RequestVoteRequest{
Term: term,
CandidateName: candidateName,
LastLogIndex: lastLogIndex,
LastLogTerm: lastLogTerm,
}
}
// Creates a new RequestVote response.
func NewRequestVoteResponse(term uint64, voteGranted bool) *RequestVoteResponse {
return &RequestVoteResponse{
Term: term,
VoteGranted: voteGranted,
}
2013-04-28 04:51:17 +00:00
}