Documentation ¶
Index ¶
- Variables
- func NewRaftStorage(walDir string, sync bool, nodeId uint64, sm StateMachine, shotter *snapshotter) (*raftStorage, error)
- type ConfChange
- type Config
- type Generator
- type Member
- func (*Member) Descriptor() ([]byte, []int)
- func (m *Member) GetContext() []byte
- func (m *Member) GetHost() string
- func (m *Member) GetLearner() bool
- func (m *Member) GetNodeID() uint64
- func (m *Member) Marshal() (dAtA []byte, err error)
- func (m *Member) MarshalTo(dAtA []byte) (int, error)
- func (m *Member) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*Member) ProtoMessage()
- func (m *Member) Reset()
- func (m *Member) Size() (n int)
- func (m *Member) String() string
- func (m *Member) Unmarshal(dAtA []byte) error
- func (m *Member) XXX_DiscardUnknown()
- func (m *Member) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Member) XXX_Merge(src proto.Message)
- func (m *Member) XXX_Size() int
- func (m *Member) XXX_Unmarshal(b []byte) error
- type Members
- type Peer
- type RaftServer
- type Snapshot
- type SnapshotMeta
- func (*SnapshotMeta) Descriptor() ([]byte, []int)
- func (m *SnapshotMeta) GetIndex() uint64
- func (m *SnapshotMeta) GetLearners() []uint64
- func (m *SnapshotMeta) GetMbs() []*Member
- func (m *SnapshotMeta) GetName() string
- func (m *SnapshotMeta) GetTerm() uint64
- func (m *SnapshotMeta) GetVoters() []uint64
- func (m *SnapshotMeta) Marshal() (dAtA []byte, err error)
- func (m *SnapshotMeta) MarshalTo(dAtA []byte) (int, error)
- func (m *SnapshotMeta) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*SnapshotMeta) ProtoMessage()
- func (m *SnapshotMeta) Reset()
- func (m *SnapshotMeta) Size() (n int)
- func (m *SnapshotMeta) String() string
- func (m *SnapshotMeta) Unmarshal(dAtA []byte) error
- func (m *SnapshotMeta) XXX_DiscardUnknown()
- func (m *SnapshotMeta) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *SnapshotMeta) XXX_Merge(src proto.Message)
- func (m *SnapshotMeta) XXX_Size() int
- func (m *SnapshotMeta) XXX_Unmarshal(b []byte) error
- type StateMachine
- type Status
- type Transport
- type WaitTime
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidData = errors.New("raftserver: Invalid data") ErrStopped = errors.New("raftserver: server stopped") ErrNotFoundNotifier = errors.New("raftserver: not found notifier") ErrTimeout = errors.New("raftserver: request timed out") ErrNoPeers = errors.New("raftserver: no peers in config") )
Functions ¶
func NewRaftStorage ¶
func NewRaftStorage(walDir string, sync bool, nodeId uint64, sm StateMachine, shotter *snapshotter) (*raftStorage, error)
Types ¶
type ConfChange ¶
type ConfChange pb.ConfChange
type Config ¶
type Config struct { // NodeID is the identity of the local node. NodeID cannot be 0. // This parameter is required. NodeId uint64 `json:"nodeId"` ListenPort int `json:"listen_port"` WalDir string `json:"raft_wal_dir"` WalSync bool `json:"raft_wal_sync"` // TickIntervalMs is the milliseconds interval only configure in testing cases. TickIntervalMs int `json:"-"` // TickInterval is the interval of timer which check heartbeat and election timeout. // The default value is 2s. TickInterval int `json:"tick_interval"` // HeartbeatTick is the heartbeat interval. A leader sends heartbeat // message to maintain the leadership every heartbeat interval. // The default value is 1. HeartbeatTick int `json:"heartbeat_tick"` // ElectionTick is the election timeout. If a follower does not receive any message // from the leader of current term during ElectionTick, it will become candidate and start an election. // ElectionTick must be greater than HeartbeatTick. // We suggest to use ElectionTick = 5 * HeartbeatTick to avoid unnecessary leader switching. // The default value is 5. ElectionTick int `json:"election_tick"` // MaxSnapConcurrency limits the max number of snapshot concurrency. // the default value is 10. MaxSnapConcurrency int `json:"max_snapshots"` // SnapshotTimeout is the snapshot timeout in memory. // the default value is 10s SnapshotTimeout int `json:"snapshot_timeout"` ProposeTimeout int `json:"propose_timeout"` Members []Member `json:"-"` // Applied is the last applied index. It should only be set when restarting Applied uint64 `json:"-"` SM StateMachine `json:"-"` }
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
| prefix | suffix | | 2 bytes | 5 bytes | 1 byte | | memberID | timestamp | cnt |
type Member ¶
type Member struct { NodeID uint64 `protobuf:"varint,1,opt,name=nodeID,proto3" json:"nodeID,omitempty"` Host string `protobuf:"bytes,2,opt,name=host,proto3" json:"host,omitempty"` Learner bool `protobuf:"varint,3,opt,name=learner,proto3" json:"learner,omitempty"` Context []byte `protobuf:"bytes,4,opt,name=context,proto3" json:"context,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Member) Descriptor ¶
func (*Member) GetContext ¶
func (*Member) GetLearner ¶
func (*Member) MarshalToSizedBuffer ¶
func (*Member) ProtoMessage ¶
func (*Member) ProtoMessage()
func (*Member) XXX_DiscardUnknown ¶
func (m *Member) XXX_DiscardUnknown()
func (*Member) XXX_Marshal ¶
func (*Member) XXX_Unmarshal ¶
type Peer ¶
type Peer struct { Id uint64 `json:"id"` Host string `json:"host"` Match uint64 `json:"match"` Next uint64 `json:"next"` State string `json:"state"` Paused bool `json:"paused"` PendingSnapshot uint64 `json:"pendingSnapshot"` RecentActive bool `json:"active"` IsLearner bool `json:"isLearner"` InflightFull bool `json:"isInflightFull"` InflightCount int `json:"inflightCount"` }
type RaftServer ¶
type RaftServer interface { Stop() Propose(ctx context.Context, data []byte) error ReadIndex(ctx context.Context) error TransferLeadership(ctx context.Context, leader, transferee uint64) AddMember(ctx context.Context, member Member) error RemoveMember(ctx context.Context, nodeID uint64) error IsLeader() bool Status() Status // In order to prevent log expansion, the application needs to call this method. Truncate(index uint64) error }
func NewRaftServer ¶
func NewRaftServer(cfg *Config) (RaftServer, error)
type SnapshotMeta ¶
type SnapshotMeta struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Index uint64 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` Term uint64 `protobuf:"varint,3,opt,name=term,proto3" json:"term,omitempty"` Mbs []*Member `protobuf:"bytes,4,rep,name=mbs,proto3" json:"mbs,omitempty"` Voters []uint64 `protobuf:"varint,5,rep,packed,name=voters,proto3" json:"voters,omitempty"` Learners []uint64 `protobuf:"varint,6,rep,packed,name=learners,proto3" json:"learners,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*SnapshotMeta) Descriptor ¶
func (*SnapshotMeta) Descriptor() ([]byte, []int)
func (*SnapshotMeta) GetIndex ¶
func (m *SnapshotMeta) GetIndex() uint64
func (*SnapshotMeta) GetLearners ¶
func (m *SnapshotMeta) GetLearners() []uint64
func (*SnapshotMeta) GetMbs ¶
func (m *SnapshotMeta) GetMbs() []*Member
func (*SnapshotMeta) GetName ¶
func (m *SnapshotMeta) GetName() string
func (*SnapshotMeta) GetTerm ¶
func (m *SnapshotMeta) GetTerm() uint64
func (*SnapshotMeta) GetVoters ¶
func (m *SnapshotMeta) GetVoters() []uint64
func (*SnapshotMeta) Marshal ¶
func (m *SnapshotMeta) Marshal() (dAtA []byte, err error)
func (*SnapshotMeta) MarshalToSizedBuffer ¶
func (m *SnapshotMeta) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*SnapshotMeta) ProtoMessage ¶
func (*SnapshotMeta) ProtoMessage()
func (*SnapshotMeta) Reset ¶
func (m *SnapshotMeta) Reset()
func (*SnapshotMeta) Size ¶
func (m *SnapshotMeta) Size() (n int)
func (*SnapshotMeta) String ¶
func (m *SnapshotMeta) String() string
func (*SnapshotMeta) Unmarshal ¶
func (m *SnapshotMeta) Unmarshal(dAtA []byte) error
func (*SnapshotMeta) XXX_DiscardUnknown ¶
func (m *SnapshotMeta) XXX_DiscardUnknown()
func (*SnapshotMeta) XXX_Marshal ¶
func (m *SnapshotMeta) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*SnapshotMeta) XXX_Merge ¶
func (m *SnapshotMeta) XXX_Merge(src proto.Message)
func (*SnapshotMeta) XXX_Size ¶
func (m *SnapshotMeta) XXX_Size() int
func (*SnapshotMeta) XXX_Unmarshal ¶
func (m *SnapshotMeta) XXX_Unmarshal(b []byte) error
type StateMachine ¶
type StateMachine interface { Apply(data [][]byte, index uint64) error ApplyMemberChange(cc ConfChange, index uint64) error Snapshot() (Snapshot, error) ApplySnapshot(meta SnapshotMeta, st Snapshot) error LeaderChange(leader uint64, host string) }
The StateMachine interface is supplied by the application to persist/snapshot data of application.
type Status ¶
type Status struct { Id uint64 `json:"nodeId"` Term uint64 `json:"term"` Vote uint64 `json:"vote"` Commit uint64 `json:"commit"` Leader uint64 `json:"leader"` RaftState string `json:"raftState"` Applied uint64 `json:"applied"` RaftApplied uint64 `json:"raftApplied"` LeadTransferee uint64 `json:"transferee"` ApplyingLength int `json:"applyingLength"` Peers []Peer `json:"peers"` }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.