Documentation ¶
Index ¶
- Constants
- Variables
- func RegisterRaftServer(s *grpc.Server, srv RaftServer)
- type AppendEntriesReply
- func (*AppendEntriesReply) Descriptor() ([]byte, []int)deprecated
- func (x *AppendEntriesReply) GetBase() *RaftBase
- func (x *AppendEntriesReply) GetNextIndex() int32
- func (x *AppendEntriesReply) GetSuccess() bool
- func (x *AppendEntriesReply) GetTerm() int32
- func (*AppendEntriesReply) ProtoMessage()
- func (x *AppendEntriesReply) ProtoReflect() protoreflect.Message
- func (x *AppendEntriesReply) Reset()
- func (x *AppendEntriesReply) String() string
- type AppendEntriesRequest
- func (*AppendEntriesRequest) Descriptor() ([]byte, []int)deprecated
- func (x *AppendEntriesRequest) GetBase() *RaftBase
- func (x *AppendEntriesRequest) GetEntries() []*LogEntry
- func (x *AppendEntriesRequest) GetLeaderCommit() int32
- func (x *AppendEntriesRequest) GetLeaderName() string
- func (x *AppendEntriesRequest) GetPrevLogIndex() int32
- func (x *AppendEntriesRequest) GetPrevLogTerm() int32
- func (x *AppendEntriesRequest) GetTerm() int32
- func (*AppendEntriesRequest) ProtoMessage()
- func (x *AppendEntriesRequest) ProtoReflect() protoreflect.Message
- func (x *AppendEntriesRequest) Reset()
- func (x *AppendEntriesRequest) String() string
- type ApplyMsg
- type InstallSnapshotReply
- func (*InstallSnapshotReply) Descriptor() ([]byte, []int)deprecated
- func (x *InstallSnapshotReply) GetBase() *RaftBase
- func (x *InstallSnapshotReply) GetTerm() int32
- func (*InstallSnapshotReply) ProtoMessage()
- func (x *InstallSnapshotReply) ProtoReflect() protoreflect.Message
- func (x *InstallSnapshotReply) Reset()
- func (x *InstallSnapshotReply) String() string
- type InstallSnapshotRequest
- func (*InstallSnapshotRequest) Descriptor() ([]byte, []int)deprecated
- func (x *InstallSnapshotRequest) GetBase() *RaftBase
- func (x *InstallSnapshotRequest) GetData() [][]byte
- func (x *InstallSnapshotRequest) GetLastIncludedIndex() int32
- func (x *InstallSnapshotRequest) GetLastIncludedTerm() int32
- func (x *InstallSnapshotRequest) GetLeaderName() string
- func (x *InstallSnapshotRequest) GetTerm() int32
- func (*InstallSnapshotRequest) ProtoMessage()
- func (x *InstallSnapshotRequest) ProtoReflect() protoreflect.Message
- func (x *InstallSnapshotRequest) Reset()
- func (x *InstallSnapshotRequest) String() string
- type LogEntry
- func (*LogEntry) Descriptor() ([]byte, []int)deprecated
- func (x *LogEntry) GetCommand() []byte
- func (x *LogEntry) GetIndex() int32
- func (x *LogEntry) GetTerm() int32
- func (*LogEntry) ProtoMessage()
- func (x *LogEntry) ProtoReflect() protoreflect.Message
- func (x *LogEntry) Reset()
- func (x *LogEntry) String() string
- type Option
- func WithAddress(address string) Option
- func WithApplyInterval(t time.Duration) Option
- func WithCodecType(t string) Option
- func WithElectionTimeout(t time.Duration) Option
- func WithHeartBeatTimeout(t time.Duration) Option
- func WithMaxlogEntryLength(length int) Option
- func WithNativeName(name string) Option
- func WithRPCTimeout(t time.Duration) Option
- func WithRaftClient(name, addr string) Option
- func WithRaftPeers(m map[string]string) Option
- func WithSnapshotPath(path string) Option
- type Options
- type Persister
- func (ps *Persister) RaftStateSize() int
- func (ps *Persister) ReadRaftState() []byte
- func (ps *Persister) ReadSnapshot() [][]byte
- func (ps *Persister) ReadSnapshotByLastLength(lastLength int32) [][]byte
- func (ps *Persister) SaveRaftState(state []byte)
- func (ps *Persister) SaveSnapshot(snapshot [][]byte)
- func (ps *Persister) SaveStateAndSnapshot(state []byte, snapshot [][]byte)
- func (ps *Persister) SnapshotSize() int
- type Raft
- func (rf *Raft) AppendEntries(ctx context.Context, req *AppendEntriesRequest) (reply *AppendEntriesReply, err error)
- func (rf *Raft) ApplyChan() <-chan ApplyMsg
- func (rf *Raft) Info() *RaftInfo
- func (rf *Raft) InstallSnapshot(ctx context.Context, req *InstallSnapshotRequest) (reply *InstallSnapshotReply, err error)
- func (rf *Raft) Kill()
- func (rf *Raft) Put(command []byte) (int32, int32, bool)
- func (rf *Raft) ReadSnapshotToLogEntryByLastLength(lastLength int32) []*LogEntry
- func (rf *Raft) Start(peers map[string]RaftClient)
- func (rf *Raft) Vote(ctx context.Context, req *VoteRequest) (reply *VoteReply, err error)
- type RaftBase
- type RaftClient
- type RaftInfo
- type RaftServer
- type RaftState
- type Role
- type Server
- type UnimplementedRaftServer
- func (*UnimplementedRaftServer) AppendEntries(context.Context, *AppendEntriesRequest) (*AppendEntriesReply, error)
- func (*UnimplementedRaftServer) InstallSnapshot(context.Context, *InstallSnapshotRequest) (*InstallSnapshotReply, error)
- func (*UnimplementedRaftServer) Vote(context.Context, *VoteRequest) (*VoteReply, error)
- type VoteReply
- func (*VoteReply) Descriptor() ([]byte, []int)deprecated
- func (x *VoteReply) GetBase() *RaftBase
- func (x *VoteReply) GetTerm() int32
- func (x *VoteReply) GetVoteGranted() bool
- func (*VoteReply) ProtoMessage()
- func (x *VoteReply) ProtoReflect() protoreflect.Message
- func (x *VoteReply) Reset()
- func (x *VoteReply) String() string
- type VoteRequest
- func (*VoteRequest) Descriptor() ([]byte, []int)deprecated
- func (x *VoteRequest) GetBase() *RaftBase
- func (x *VoteRequest) GetCandidateName() string
- func (x *VoteRequest) GetLastLogIndex() int32
- func (x *VoteRequest) GetLastLogTerm() int32
- func (x *VoteRequest) GetTerm() int32
- func (*VoteRequest) ProtoMessage()
- func (x *VoteRequest) ProtoReflect() protoreflect.Message
- func (x *VoteRequest) Reset()
- func (x *VoteRequest) String() string
Constants ¶
View Source
const ( DefaultRaftStateLogName = "raft-state-log" DefaultSnapshotLogName = "raft-snapshot-log" )
View Source
const ( InstallSnapshotToStore = "installSnapShot" AddMemeberToRaft = "addMemberToRaft" )
Variables ¶
View Source
var File_raft_proto protoreflect.FileDescriptor
Functions ¶
func RegisterRaftServer ¶
func RegisterRaftServer(s *grpc.Server, srv RaftServer)
Types ¶
type AppendEntriesReply ¶
type AppendEntriesReply struct { Term int32 `protobuf:"varint,1,opt,name=Term,proto3" json:"Term,omitempty"` Success bool `protobuf:"varint,2,opt,name=Success,proto3" json:"Success,omitempty"` NextIndex int32 `protobuf:"varint,3,opt,name=NextIndex,proto3" json:"NextIndex,omitempty"` Base *RaftBase `protobuf:"bytes,4,opt,name=Base,proto3" json:"Base,omitempty"` // contains filtered or unexported fields }
func (*AppendEntriesReply) Descriptor
deprecated
func (*AppendEntriesReply) Descriptor() ([]byte, []int)
Deprecated: Use AppendEntriesReply.ProtoReflect.Descriptor instead.
func (*AppendEntriesReply) GetBase ¶
func (x *AppendEntriesReply) GetBase() *RaftBase
func (*AppendEntriesReply) GetNextIndex ¶
func (x *AppendEntriesReply) GetNextIndex() int32
func (*AppendEntriesReply) GetSuccess ¶
func (x *AppendEntriesReply) GetSuccess() bool
func (*AppendEntriesReply) GetTerm ¶
func (x *AppendEntriesReply) GetTerm() int32
func (*AppendEntriesReply) ProtoMessage ¶
func (*AppendEntriesReply) ProtoMessage()
func (*AppendEntriesReply) ProtoReflect ¶
func (x *AppendEntriesReply) ProtoReflect() protoreflect.Message
func (*AppendEntriesReply) Reset ¶
func (x *AppendEntriesReply) Reset()
func (*AppendEntriesReply) String ¶
func (x *AppendEntriesReply) String() string
type AppendEntriesRequest ¶
type AppendEntriesRequest struct { Term int32 `protobuf:"varint,1,opt,name=Term,proto3" json:"Term,omitempty"` LeaderName string `protobuf:"bytes,2,opt,name=LeaderName,proto3" json:"LeaderName,omitempty"` PrevLogIndex int32 `protobuf:"varint,3,opt,name=PrevLogIndex,proto3" json:"PrevLogIndex,omitempty"` PrevLogTerm int32 `protobuf:"varint,4,opt,name=PrevLogTerm,proto3" json:"PrevLogTerm,omitempty"` Entries []*LogEntry `protobuf:"bytes,5,rep,name=Entries,proto3" json:"Entries,omitempty"` LeaderCommit int32 `protobuf:"varint,6,opt,name=LeaderCommit,proto3" json:"LeaderCommit,omitempty"` Base *RaftBase `protobuf:"bytes,7,opt,name=Base,proto3" json:"Base,omitempty"` // contains filtered or unexported fields }
func (*AppendEntriesRequest) Descriptor
deprecated
func (*AppendEntriesRequest) Descriptor() ([]byte, []int)
Deprecated: Use AppendEntriesRequest.ProtoReflect.Descriptor instead.
func (*AppendEntriesRequest) GetBase ¶
func (x *AppendEntriesRequest) GetBase() *RaftBase
func (*AppendEntriesRequest) GetEntries ¶
func (x *AppendEntriesRequest) GetEntries() []*LogEntry
func (*AppendEntriesRequest) GetLeaderCommit ¶
func (x *AppendEntriesRequest) GetLeaderCommit() int32
func (*AppendEntriesRequest) GetLeaderName ¶
func (x *AppendEntriesRequest) GetLeaderName() string
func (*AppendEntriesRequest) GetPrevLogIndex ¶
func (x *AppendEntriesRequest) GetPrevLogIndex() int32
func (*AppendEntriesRequest) GetPrevLogTerm ¶
func (x *AppendEntriesRequest) GetPrevLogTerm() int32
func (*AppendEntriesRequest) GetTerm ¶
func (x *AppendEntriesRequest) GetTerm() int32
func (*AppendEntriesRequest) ProtoMessage ¶
func (*AppendEntriesRequest) ProtoMessage()
func (*AppendEntriesRequest) ProtoReflect ¶
func (x *AppendEntriesRequest) ProtoReflect() protoreflect.Message
func (*AppendEntriesRequest) Reset ¶
func (x *AppendEntriesRequest) Reset()
func (*AppendEntriesRequest) String ¶
func (x *AppendEntriesRequest) String() string
type InstallSnapshotReply ¶
type InstallSnapshotReply struct { Term int32 `protobuf:"varint,1,opt,name=Term,proto3" json:"Term,omitempty"` Base *RaftBase `protobuf:"bytes,2,opt,name=Base,proto3" json:"Base,omitempty"` // contains filtered or unexported fields }
func (*InstallSnapshotReply) Descriptor
deprecated
func (*InstallSnapshotReply) Descriptor() ([]byte, []int)
Deprecated: Use InstallSnapshotReply.ProtoReflect.Descriptor instead.
func (*InstallSnapshotReply) GetBase ¶
func (x *InstallSnapshotReply) GetBase() *RaftBase
func (*InstallSnapshotReply) GetTerm ¶
func (x *InstallSnapshotReply) GetTerm() int32
func (*InstallSnapshotReply) ProtoMessage ¶
func (*InstallSnapshotReply) ProtoMessage()
func (*InstallSnapshotReply) ProtoReflect ¶
func (x *InstallSnapshotReply) ProtoReflect() protoreflect.Message
func (*InstallSnapshotReply) Reset ¶
func (x *InstallSnapshotReply) Reset()
func (*InstallSnapshotReply) String ¶
func (x *InstallSnapshotReply) String() string
type InstallSnapshotRequest ¶
type InstallSnapshotRequest struct { Term int32 `protobuf:"varint,1,opt,name=Term,proto3" json:"Term,omitempty"` LeaderName string `protobuf:"bytes,2,opt,name=LeaderName,proto3" json:"LeaderName,omitempty"` LastIncludedIndex int32 `protobuf:"varint,3,opt,name=LastIncludedIndex,proto3" json:"LastIncludedIndex,omitempty"` LastIncludedTerm int32 `protobuf:"varint,4,opt,name=LastIncludedTerm,proto3" json:"LastIncludedTerm,omitempty"` Data [][]byte `protobuf:"bytes,5,rep,name=Data,proto3" json:"Data,omitempty"` Base *RaftBase `protobuf:"bytes,6,opt,name=Base,proto3" json:"Base,omitempty"` // contains filtered or unexported fields }
func (*InstallSnapshotRequest) Descriptor
deprecated
func (*InstallSnapshotRequest) Descriptor() ([]byte, []int)
Deprecated: Use InstallSnapshotRequest.ProtoReflect.Descriptor instead.
func (*InstallSnapshotRequest) GetBase ¶
func (x *InstallSnapshotRequest) GetBase() *RaftBase
func (*InstallSnapshotRequest) GetData ¶
func (x *InstallSnapshotRequest) GetData() [][]byte
func (*InstallSnapshotRequest) GetLastIncludedIndex ¶
func (x *InstallSnapshotRequest) GetLastIncludedIndex() int32
func (*InstallSnapshotRequest) GetLastIncludedTerm ¶
func (x *InstallSnapshotRequest) GetLastIncludedTerm() int32
func (*InstallSnapshotRequest) GetLeaderName ¶
func (x *InstallSnapshotRequest) GetLeaderName() string
func (*InstallSnapshotRequest) GetTerm ¶
func (x *InstallSnapshotRequest) GetTerm() int32
func (*InstallSnapshotRequest) ProtoMessage ¶
func (*InstallSnapshotRequest) ProtoMessage()
func (*InstallSnapshotRequest) ProtoReflect ¶
func (x *InstallSnapshotRequest) ProtoReflect() protoreflect.Message
func (*InstallSnapshotRequest) Reset ¶
func (x *InstallSnapshotRequest) Reset()
func (*InstallSnapshotRequest) String ¶
func (x *InstallSnapshotRequest) String() string
type LogEntry ¶
type LogEntry struct { Term int32 `protobuf:"varint,1,opt,name=Term,proto3" json:"Term,omitempty"` Index int32 `protobuf:"varint,2,opt,name=Index,proto3" json:"Index,omitempty"` Command []byte `protobuf:"bytes,3,opt,name=Command,proto3" json:"Command,omitempty"` // contains filtered or unexported fields }
func (*LogEntry) ProtoReflect ¶
func (x *LogEntry) ProtoReflect() protoreflect.Message
type Options ¶
type Options struct { NativeName string Address string `yaml:"address"` CodecType string `yaml:"codec_type"` ApplyMsgLength int `yaml:"apply_msg_length"` SnapshotPath string `yaml:"snapshot_path"` MaxLogEntryLength int `yaml:"max_log_entry_length"` ElectionTimeout time.Duration `yaml:"election_timeout"` HeartBeatTimeout time.Duration `yaml:"heartbeat_timeout"` ApplyInterval time.Duration `yaml:"apply_interval"` RPCTimeout time.Duration `yaml:"rpc_timeout"` RaftPeers map[string]string InfoCh chan *RaftInfo }
type Persister ¶
type Persister struct {
// contains filtered or unexported fields
}
func (*Persister) ReadSnapshotByLastLength ¶
func (*Persister) SaveStateAndSnapshot ¶
type Raft ¶
type Raft struct { UnimplementedRaftServer // contains filtered or unexported fields }
func (*Raft) AppendEntries ¶
func (rf *Raft) AppendEntries(ctx context.Context, req *AppendEntriesRequest) (reply *AppendEntriesReply, err error)
func (*Raft) InstallSnapshot ¶
func (rf *Raft) InstallSnapshot(ctx context.Context, req *InstallSnapshotRequest) (reply *InstallSnapshotReply, err error)
func (*Raft) ReadSnapshotToLogEntryByLastLength ¶
func (*Raft) Start ¶
func (rf *Raft) Start(peers map[string]RaftClient)
type RaftBase ¶
type RaftBase struct { To string `protobuf:"bytes,1,opt,name=To,proto3" json:"To,omitempty"` From string `protobuf:"bytes,2,opt,name=From,proto3" json:"From,omitempty"` // contains filtered or unexported fields }
func (*RaftBase) ProtoReflect ¶
func (x *RaftBase) ProtoReflect() protoreflect.Message
type RaftClient ¶
type RaftClient interface { InstallSnapshot(ctx context.Context, in *InstallSnapshotRequest, opts ...grpc.CallOption) (*InstallSnapshotReply, error) AppendEntries(ctx context.Context, in *AppendEntriesRequest, opts ...grpc.CallOption) (*AppendEntriesReply, error) Vote(ctx context.Context, in *VoteRequest, opts ...grpc.CallOption) (*VoteReply, error) }
RaftClient is the client API for Raft service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewRaftClient ¶
func NewRaftClient(cc grpc.ClientConnInterface) RaftClient
type RaftServer ¶
type RaftServer interface { InstallSnapshot(context.Context, *InstallSnapshotRequest) (*InstallSnapshotReply, error) AppendEntries(context.Context, *AppendEntriesRequest) (*AppendEntriesReply, error) Vote(context.Context, *VoteRequest) (*VoteReply, error) }
RaftServer is the server API for Raft service.
type RaftState ¶
type Server ¶
type UnimplementedRaftServer ¶
type UnimplementedRaftServer struct { }
UnimplementedRaftServer can be embedded to have forward compatible implementations.
func (*UnimplementedRaftServer) AppendEntries ¶
func (*UnimplementedRaftServer) AppendEntries(context.Context, *AppendEntriesRequest) (*AppendEntriesReply, error)
func (*UnimplementedRaftServer) InstallSnapshot ¶
func (*UnimplementedRaftServer) InstallSnapshot(context.Context, *InstallSnapshotRequest) (*InstallSnapshotReply, error)
func (*UnimplementedRaftServer) Vote ¶
func (*UnimplementedRaftServer) Vote(context.Context, *VoteRequest) (*VoteReply, error)
type VoteReply ¶
type VoteReply struct { Term int32 `protobuf:"varint,1,opt,name=Term,proto3" json:"Term,omitempty"` VoteGranted bool `protobuf:"varint,2,opt,name=VoteGranted,proto3" json:"VoteGranted,omitempty"` Base *RaftBase `protobuf:"bytes,3,opt,name=Base,proto3" json:"Base,omitempty"` // contains filtered or unexported fields }
func (*VoteReply) ProtoReflect ¶
func (x *VoteReply) ProtoReflect() protoreflect.Message
type VoteRequest ¶
type VoteRequest struct { Term int32 `protobuf:"varint,1,opt,name=Term,proto3" json:"Term,omitempty"` CandidateName string `protobuf:"bytes,2,opt,name=CandidateName,proto3" json:"CandidateName,omitempty"` LastLogIndex int32 `protobuf:"varint,3,opt,name=LastLogIndex,proto3" json:"LastLogIndex,omitempty"` LastLogTerm int32 `protobuf:"varint,4,opt,name=LastLogTerm,proto3" json:"LastLogTerm,omitempty"` Base *RaftBase `protobuf:"bytes,5,opt,name=Base,proto3" json:"Base,omitempty"` // contains filtered or unexported fields }
func (*VoteRequest) Descriptor
deprecated
func (*VoteRequest) Descriptor() ([]byte, []int)
Deprecated: Use VoteRequest.ProtoReflect.Descriptor instead.
func (*VoteRequest) GetBase ¶
func (x *VoteRequest) GetBase() *RaftBase
func (*VoteRequest) GetCandidateName ¶
func (x *VoteRequest) GetCandidateName() string
func (*VoteRequest) GetLastLogIndex ¶
func (x *VoteRequest) GetLastLogIndex() int32
func (*VoteRequest) GetLastLogTerm ¶
func (x *VoteRequest) GetLastLogTerm() int32
func (*VoteRequest) GetTerm ¶
func (x *VoteRequest) GetTerm() int32
func (*VoteRequest) ProtoMessage ¶
func (*VoteRequest) ProtoMessage()
func (*VoteRequest) ProtoReflect ¶
func (x *VoteRequest) ProtoReflect() protoreflect.Message
func (*VoteRequest) Reset ¶
func (x *VoteRequest) Reset()
func (*VoteRequest) String ¶
func (x *VoteRequest) String() string
Click to show internal directories.
Click to hide internal directories.