Documentation
¶
Index ¶
- Variables
- func RegisterRaftStateMachineServer(s *grpc.Server, srv RaftStateMachineServer)
- type ClusterManager
- type Entry
- func (*Entry) Descriptor() ([]byte, []int)
- func (m *Entry) GetData() []byte
- func (m *Entry) GetIndex() int64
- func (m *Entry) GetTerm() int64
- func (m *Entry) GetType() Entry_Type
- func (*Entry) ProtoMessage()
- func (m *Entry) Reset()
- func (m *Entry) String() string
- func (m *Entry) XXX_DiscardUnknown()
- func (m *Entry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Entry) XXX_Merge(src proto.Message)
- func (m *Entry) XXX_Size() int
- func (m *Entry) XXX_Unmarshal(b []byte) error
- type Entry_Type
- type LogStore
- type Network
- type RaftStateMachineClient
- type RaftStateMachineServer
- type RequestAppendEntries
- func (*RequestAppendEntries) Descriptor() ([]byte, []int)
- func (m *RequestAppendEntries) GetEntries() [][]byte
- func (m *RequestAppendEntries) GetLeaderCommit() int64
- func (m *RequestAppendEntries) GetLeaderId() string
- func (m *RequestAppendEntries) GetPrevLogIndex() int64
- func (m *RequestAppendEntries) GetPrevLogTerm() int64
- func (m *RequestAppendEntries) GetTerm() int64
- func (*RequestAppendEntries) ProtoMessage()
- func (m *RequestAppendEntries) Reset()
- func (m *RequestAppendEntries) String() string
- func (m *RequestAppendEntries) XXX_DiscardUnknown()
- func (m *RequestAppendEntries) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RequestAppendEntries) XXX_Merge(src proto.Message)
- func (m *RequestAppendEntries) XXX_Size() int
- func (m *RequestAppendEntries) XXX_Unmarshal(b []byte) error
- type RequestInstallSnapshot
- func (*RequestInstallSnapshot) Descriptor() ([]byte, []int)
- func (m *RequestInstallSnapshot) GetData() []byte
- func (m *RequestInstallSnapshot) GetDone() bool
- func (m *RequestInstallSnapshot) GetLastIncludedIndex() int64
- func (m *RequestInstallSnapshot) GetLastIncludedTerm() int64
- func (m *RequestInstallSnapshot) GetLeaderId() string
- func (m *RequestInstallSnapshot) GetOffset() int64
- func (m *RequestInstallSnapshot) GetTerm() int64
- func (*RequestInstallSnapshot) ProtoMessage()
- func (m *RequestInstallSnapshot) Reset()
- func (m *RequestInstallSnapshot) String() string
- func (m *RequestInstallSnapshot) XXX_DiscardUnknown()
- func (m *RequestInstallSnapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RequestInstallSnapshot) XXX_Merge(src proto.Message)
- func (m *RequestInstallSnapshot) XXX_Size() int
- func (m *RequestInstallSnapshot) XXX_Unmarshal(b []byte) error
- type RequestVote
- func (*RequestVote) Descriptor() ([]byte, []int)
- func (m *RequestVote) GetCandidateId() string
- func (m *RequestVote) GetLastLogIndex() int64
- func (m *RequestVote) GetLastLogTerm() int64
- func (m *RequestVote) GetTerm() int64
- func (*RequestVote) ProtoMessage()
- func (m *RequestVote) Reset()
- func (m *RequestVote) String() string
- func (m *RequestVote) XXX_DiscardUnknown()
- func (m *RequestVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *RequestVote) XXX_Merge(src proto.Message)
- func (m *RequestVote) XXX_Size() int
- func (m *RequestVote) XXX_Unmarshal(b []byte) error
- type ResponseAppendEntries
- func (*ResponseAppendEntries) Descriptor() ([]byte, []int)
- func (m *ResponseAppendEntries) GetSuccess() bool
- func (m *ResponseAppendEntries) GetTerm() int64
- func (*ResponseAppendEntries) ProtoMessage()
- func (m *ResponseAppendEntries) Reset()
- func (m *ResponseAppendEntries) String() string
- func (m *ResponseAppendEntries) XXX_DiscardUnknown()
- func (m *ResponseAppendEntries) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ResponseAppendEntries) XXX_Merge(src proto.Message)
- func (m *ResponseAppendEntries) XXX_Size() int
- func (m *ResponseAppendEntries) XXX_Unmarshal(b []byte) error
- type ResponseInstallSnapshot
- func (*ResponseInstallSnapshot) Descriptor() ([]byte, []int)
- func (*ResponseInstallSnapshot) ProtoMessage()
- func (m *ResponseInstallSnapshot) Reset()
- func (m *ResponseInstallSnapshot) String() string
- func (m *ResponseInstallSnapshot) XXX_DiscardUnknown()
- func (m *ResponseInstallSnapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ResponseInstallSnapshot) XXX_Merge(src proto.Message)
- func (m *ResponseInstallSnapshot) XXX_Size() int
- func (m *ResponseInstallSnapshot) XXX_Unmarshal(b []byte) error
- type ResponseVote
- func (*ResponseVote) Descriptor() ([]byte, []int)
- func (m *ResponseVote) GetTerm() int64
- func (m *ResponseVote) GetVoteGranted() bool
- func (*ResponseVote) ProtoMessage()
- func (m *ResponseVote) Reset()
- func (m *ResponseVote) String() string
- func (m *ResponseVote) XXX_DiscardUnknown()
- func (m *ResponseVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ResponseVote) XXX_Merge(src proto.Message)
- func (m *ResponseVote) XXX_Size() int
- func (m *ResponseVote) XXX_Unmarshal(b []byte) error
- type Status
Constants ¶
This section is empty.
Variables ¶
View Source
var Entry_Type_name = map[int32]string{
0: "normal",
1: "changeCluster",
}
View Source
var Entry_Type_value = map[string]int32{
"normal": 0,
"changeCluster": 1,
}
View Source
var Status_name = map[int32]string{
0: "Leader",
1: "Follower",
2: "Candidate",
}
View Source
var Status_value = map[string]int32{
"Leader": 0,
"Follower": 1,
"Candidate": 2,
}
Functions ¶
func RegisterRaftStateMachineServer ¶
func RegisterRaftStateMachineServer(s *grpc.Server, srv RaftStateMachineServer)
Types ¶
type ClusterManager ¶
ClusterManager .
type Entry ¶
type Entry struct {
Index int64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"`
Term int64 `protobuf:"varint,2,opt,name=term,proto3" json:"term,omitempty"`
Type Entry_Type `protobuf:"varint,3,opt,name=type,proto3,enum=raft.Entry_Type" json:"type,omitempty"`
Data []byte `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (*Entry) Descriptor ¶
func (*Entry) GetType ¶
func (m *Entry) GetType() Entry_Type
func (*Entry) ProtoMessage ¶
func (*Entry) ProtoMessage()
func (*Entry) XXX_DiscardUnknown ¶
func (m *Entry) XXX_DiscardUnknown()
func (*Entry) XXX_Marshal ¶
func (*Entry) XXX_Unmarshal ¶
type Entry_Type ¶
type Entry_Type int32
const ( Entry_normal Entry_Type = 0 Entry_changeCluster Entry_Type = 1 )
func (Entry_Type) EnumDescriptor ¶
func (Entry_Type) EnumDescriptor() ([]byte, []int)
func (Entry_Type) String ¶
func (x Entry_Type) String() string
type LogStore ¶
type LogStore interface {
// Get log entries by term id
GetByTerm(term int64) ([]*Entry, error)
// Get log entry by offset index
Get(index int64) (*Entry, error)
// Store entries
Save(entries []*Entry) error
// Commit logs before index (include index self)
Commit(index int64) error
// Last commited entry
LastCommitted() (*Entry, error)
// Create snapshot
CreateSnapshot() error
// Get snapshot stream
Snapshot() (chan *RequestInstallSnapshot, error)
// Install snapshot
InstallSnapshot(chan *RequestInstallSnapshot) error
}
LogStore .
type Network ¶
type Network interface {
// Connect to remote raft peer
Connect(remote *cap.Peer) (RaftStateMachineClient, error)
Serve(local *cap.Peer, server RaftStateMachineServer) error
}
Network .
type RaftStateMachineClient ¶
type RaftStateMachineClient interface {
Vote(ctx context.Context, in *RequestVote, opts ...grpc.CallOption) (*ResponseVote, error)
AppendEntries(ctx context.Context, in *RequestAppendEntries, opts ...grpc.CallOption) (*ResponseAppendEntries, error)
InstallSnapshot(ctx context.Context, in *RequestInstallSnapshot, opts ...grpc.CallOption) (*ResponseInstallSnapshot, error)
}
RaftStateMachineClient is the client API for RaftStateMachine service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewRaftStateMachineClient ¶
func NewRaftStateMachineClient(cc *grpc.ClientConn) RaftStateMachineClient
type RaftStateMachineServer ¶
type RaftStateMachineServer interface {
Vote(context.Context, *RequestVote) (*ResponseVote, error)
AppendEntries(context.Context, *RequestAppendEntries) (*ResponseAppendEntries, error)
InstallSnapshot(context.Context, *RequestInstallSnapshot) (*ResponseInstallSnapshot, error)
}
RaftStateMachineServer is the server API for RaftStateMachine service.
type RequestAppendEntries ¶
type RequestAppendEntries struct {
Term int64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
LeaderId string `protobuf:"bytes,2,opt,name=leaderId,proto3" json:"leaderId,omitempty"`
PrevLogIndex int64 `protobuf:"varint,3,opt,name=prevLogIndex,proto3" json:"prevLogIndex,omitempty"`
PrevLogTerm int64 `protobuf:"varint,4,opt,name=prevLogTerm,proto3" json:"prevLogTerm,omitempty"`
Entries [][]byte `protobuf:"bytes,5,rep,name=entries,proto3" json:"entries,omitempty"`
// send more than one for efficiency)
LeaderCommit int64 `protobuf:"varint,6,opt,name=leaderCommit,proto3" json:"leaderCommit,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
Receiver implementation:
- Reply false if term < currentTerm (§5.1)
- Reply false if log doesn’t contain an entry at prevLogIndex whose term matches prevLogTerm (§5.3)
- If an existing entry conflicts with a new one (same index but different terms), delete the existing entry and all that follow it (§5.3)
- Append any new entries not already in the log
- If leaderCommit > commitIndex, set commitIndex = min(leaderCommit, index of last new entry)
func (*RequestAppendEntries) Descriptor ¶
func (*RequestAppendEntries) Descriptor() ([]byte, []int)
func (*RequestAppendEntries) GetEntries ¶
func (m *RequestAppendEntries) GetEntries() [][]byte
func (*RequestAppendEntries) GetLeaderCommit ¶
func (m *RequestAppendEntries) GetLeaderCommit() int64
func (*RequestAppendEntries) GetLeaderId ¶
func (m *RequestAppendEntries) GetLeaderId() string
func (*RequestAppendEntries) GetPrevLogIndex ¶
func (m *RequestAppendEntries) GetPrevLogIndex() int64
func (*RequestAppendEntries) GetPrevLogTerm ¶
func (m *RequestAppendEntries) GetPrevLogTerm() int64
func (*RequestAppendEntries) GetTerm ¶
func (m *RequestAppendEntries) GetTerm() int64
func (*RequestAppendEntries) ProtoMessage ¶
func (*RequestAppendEntries) ProtoMessage()
func (*RequestAppendEntries) Reset ¶
func (m *RequestAppendEntries) Reset()
func (*RequestAppendEntries) String ¶
func (m *RequestAppendEntries) String() string
func (*RequestAppendEntries) XXX_DiscardUnknown ¶
func (m *RequestAppendEntries) XXX_DiscardUnknown()
func (*RequestAppendEntries) XXX_Marshal ¶
func (m *RequestAppendEntries) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*RequestAppendEntries) XXX_Merge ¶
func (m *RequestAppendEntries) XXX_Merge(src proto.Message)
func (*RequestAppendEntries) XXX_Size ¶
func (m *RequestAppendEntries) XXX_Size() int
func (*RequestAppendEntries) XXX_Unmarshal ¶
func (m *RequestAppendEntries) XXX_Unmarshal(b []byte) error
type RequestInstallSnapshot ¶
type RequestInstallSnapshot struct {
Term int64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
LeaderId string `protobuf:"bytes,2,opt,name=leaderId,proto3" json:"leaderId,omitempty"`
LastIncludedIndex int64 `protobuf:"varint,3,opt,name=lastIncludedIndex,proto3" json:"lastIncludedIndex,omitempty"`
// and including this index
LastIncludedTerm int64 `protobuf:"varint,4,opt,name=lastIncludedTerm,proto3" json:"lastIncludedTerm,omitempty"`
Offset int64 `protobuf:"varint,5,opt,name=offset,proto3" json:"offset,omitempty"`
// where chunk is positioned in the snapshot file
Data []byte `protobuf:"bytes,6,opt,name=data,proto3" json:"data,omitempty"`
Done bool `protobuf:"varint,7,opt,name=done,proto3" json:"done,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
Invoked by leader to send chunks of a snapshot to a follower. Leaders always send chunks in order. Receiver implementation:
- Reply immediately if term < currentTerm
- Create new snapshot file if first chunk (offset is 0)
- Write data into snapshot file at given offset
- Reply and wait for more data chunks if done is false
- Save snapshot file, discard any existing or partial snapshot with a smaller index
- If existing log entry has same index and term as snapshot’s last included entry, retain log entries following it and reply
- Discard the entire log
- Reset state machine using snapshot contents (and load snapshot’s cluster configuration)
func (*RequestInstallSnapshot) Descriptor ¶
func (*RequestInstallSnapshot) Descriptor() ([]byte, []int)
func (*RequestInstallSnapshot) GetData ¶
func (m *RequestInstallSnapshot) GetData() []byte
func (*RequestInstallSnapshot) GetDone ¶
func (m *RequestInstallSnapshot) GetDone() bool
func (*RequestInstallSnapshot) GetLastIncludedIndex ¶
func (m *RequestInstallSnapshot) GetLastIncludedIndex() int64
func (*RequestInstallSnapshot) GetLastIncludedTerm ¶
func (m *RequestInstallSnapshot) GetLastIncludedTerm() int64
func (*RequestInstallSnapshot) GetLeaderId ¶
func (m *RequestInstallSnapshot) GetLeaderId() string
func (*RequestInstallSnapshot) GetOffset ¶
func (m *RequestInstallSnapshot) GetOffset() int64
func (*RequestInstallSnapshot) GetTerm ¶
func (m *RequestInstallSnapshot) GetTerm() int64
func (*RequestInstallSnapshot) ProtoMessage ¶
func (*RequestInstallSnapshot) ProtoMessage()
func (*RequestInstallSnapshot) Reset ¶
func (m *RequestInstallSnapshot) Reset()
func (*RequestInstallSnapshot) String ¶
func (m *RequestInstallSnapshot) String() string
func (*RequestInstallSnapshot) XXX_DiscardUnknown ¶
func (m *RequestInstallSnapshot) XXX_DiscardUnknown()
func (*RequestInstallSnapshot) XXX_Marshal ¶
func (m *RequestInstallSnapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*RequestInstallSnapshot) XXX_Merge ¶
func (m *RequestInstallSnapshot) XXX_Merge(src proto.Message)
func (*RequestInstallSnapshot) XXX_Size ¶
func (m *RequestInstallSnapshot) XXX_Size() int
func (*RequestInstallSnapshot) XXX_Unmarshal ¶
func (m *RequestInstallSnapshot) XXX_Unmarshal(b []byte) error
type RequestVote ¶
type RequestVote struct {
Term int64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
CandidateId string `protobuf:"bytes,2,opt,name=candidateId,proto3" json:"candidateId,omitempty"`
LastLogIndex int64 `protobuf:"varint,3,opt,name=lastLogIndex,proto3" json:"lastLogIndex,omitempty"`
LastLogTerm int64 `protobuf:"varint,4,opt,name=lastLogTerm,proto3" json:"lastLogTerm,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
Receiver implementation:
- Reply false if term < currentTerm (§5.1)
- If votedFor is null or candidateId, and candidate’s log is at least as up-to-date as receiver’s log, grant vote (§5.2, §5.4)
func (*RequestVote) Descriptor ¶
func (*RequestVote) Descriptor() ([]byte, []int)
func (*RequestVote) GetCandidateId ¶
func (m *RequestVote) GetCandidateId() string
func (*RequestVote) GetLastLogIndex ¶
func (m *RequestVote) GetLastLogIndex() int64
func (*RequestVote) GetLastLogTerm ¶
func (m *RequestVote) GetLastLogTerm() int64
func (*RequestVote) GetTerm ¶
func (m *RequestVote) GetTerm() int64
func (*RequestVote) ProtoMessage ¶
func (*RequestVote) ProtoMessage()
func (*RequestVote) Reset ¶
func (m *RequestVote) Reset()
func (*RequestVote) String ¶
func (m *RequestVote) String() string
func (*RequestVote) XXX_DiscardUnknown ¶
func (m *RequestVote) XXX_DiscardUnknown()
func (*RequestVote) XXX_Marshal ¶
func (m *RequestVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*RequestVote) XXX_Merge ¶
func (m *RequestVote) XXX_Merge(src proto.Message)
func (*RequestVote) XXX_Size ¶
func (m *RequestVote) XXX_Size() int
func (*RequestVote) XXX_Unmarshal ¶
func (m *RequestVote) XXX_Unmarshal(b []byte) error
type ResponseAppendEntries ¶
type ResponseAppendEntries struct {
Term int64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
Success bool `protobuf:"varint,2,opt,name=success,proto3" json:"success,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (*ResponseAppendEntries) Descriptor ¶
func (*ResponseAppendEntries) Descriptor() ([]byte, []int)
func (*ResponseAppendEntries) GetSuccess ¶
func (m *ResponseAppendEntries) GetSuccess() bool
func (*ResponseAppendEntries) GetTerm ¶
func (m *ResponseAppendEntries) GetTerm() int64
func (*ResponseAppendEntries) ProtoMessage ¶
func (*ResponseAppendEntries) ProtoMessage()
func (*ResponseAppendEntries) Reset ¶
func (m *ResponseAppendEntries) Reset()
func (*ResponseAppendEntries) String ¶
func (m *ResponseAppendEntries) String() string
func (*ResponseAppendEntries) XXX_DiscardUnknown ¶
func (m *ResponseAppendEntries) XXX_DiscardUnknown()
func (*ResponseAppendEntries) XXX_Marshal ¶
func (m *ResponseAppendEntries) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ResponseAppendEntries) XXX_Merge ¶
func (m *ResponseAppendEntries) XXX_Merge(src proto.Message)
func (*ResponseAppendEntries) XXX_Size ¶
func (m *ResponseAppendEntries) XXX_Size() int
func (*ResponseAppendEntries) XXX_Unmarshal ¶
func (m *ResponseAppendEntries) XXX_Unmarshal(b []byte) error
type ResponseInstallSnapshot ¶
type ResponseInstallSnapshot struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (*ResponseInstallSnapshot) Descriptor ¶
func (*ResponseInstallSnapshot) Descriptor() ([]byte, []int)
func (*ResponseInstallSnapshot) ProtoMessage ¶
func (*ResponseInstallSnapshot) ProtoMessage()
func (*ResponseInstallSnapshot) Reset ¶
func (m *ResponseInstallSnapshot) Reset()
func (*ResponseInstallSnapshot) String ¶
func (m *ResponseInstallSnapshot) String() string
func (*ResponseInstallSnapshot) XXX_DiscardUnknown ¶
func (m *ResponseInstallSnapshot) XXX_DiscardUnknown()
func (*ResponseInstallSnapshot) XXX_Marshal ¶
func (m *ResponseInstallSnapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ResponseInstallSnapshot) XXX_Merge ¶
func (m *ResponseInstallSnapshot) XXX_Merge(src proto.Message)
func (*ResponseInstallSnapshot) XXX_Size ¶
func (m *ResponseInstallSnapshot) XXX_Size() int
func (*ResponseInstallSnapshot) XXX_Unmarshal ¶
func (m *ResponseInstallSnapshot) XXX_Unmarshal(b []byte) error
type ResponseVote ¶
type ResponseVote struct {
Term int64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
VoteGranted bool `protobuf:"varint,2,opt,name=voteGranted,proto3" json:"voteGranted,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (*ResponseVote) Descriptor ¶
func (*ResponseVote) Descriptor() ([]byte, []int)
func (*ResponseVote) GetTerm ¶
func (m *ResponseVote) GetTerm() int64
func (*ResponseVote) GetVoteGranted ¶
func (m *ResponseVote) GetVoteGranted() bool
func (*ResponseVote) ProtoMessage ¶
func (*ResponseVote) ProtoMessage()
func (*ResponseVote) Reset ¶
func (m *ResponseVote) Reset()
func (*ResponseVote) String ¶
func (m *ResponseVote) String() string
func (*ResponseVote) XXX_DiscardUnknown ¶
func (m *ResponseVote) XXX_DiscardUnknown()
func (*ResponseVote) XXX_Marshal ¶
func (m *ResponseVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ResponseVote) XXX_Merge ¶
func (m *ResponseVote) XXX_Merge(src proto.Message)
func (*ResponseVote) XXX_Size ¶
func (m *ResponseVote) XXX_Size() int
func (*ResponseVote) XXX_Unmarshal ¶
func (m *ResponseVote) XXX_Unmarshal(b []byte) error
Click to show internal directories.
Click to hide internal directories.