Documentation ¶
Index ¶
- Variables
- func JoinCluster(rc *Node, broadCastIP string, broadPort int, address string, protocol string) error
- type Command
- func (*Command) Descriptor() ([]byte, []int)deprecated
- func (x *Command) GetBody() []byte
- func (x *Command) GetCmd() string
- func (x *Command) GetKey() string
- func (x *Command) GetNamespace() string
- func (x *Command) GetVersion() string
- func (*Command) ProtoMessage()
- func (x *Command) ProtoReflect() protoreflect.Message
- func (x *Command) Reset()
- func (x *Command) String() string
- type IRaftService
- type IRaftStateHandler
- type IRaftStateHandlers
- type JoinRequest
- type JoinResponse
- type MemoryStorage
- func (ms *MemoryStorage) Append(entries []pb.Entry) error
- func (ms *MemoryStorage) ApplySnapshot(snap pb.Snapshot) error
- func (ms *MemoryStorage) Compact(compactIndex uint64) error
- func (ms *MemoryStorage) CreateSnapshot(i uint64, cs *pb.ConfState, data []byte) (pb.Snapshot, error)
- func (ms *MemoryStorage) Entries(lo, hi, maxSize uint64) ([]pb.Entry, error)
- func (ms *MemoryStorage) FirstIndex() (uint64, error)
- func (ms *MemoryStorage) InitialState() (pb.HardState, pb.ConfState, error)
- func (ms *MemoryStorage) LastIndex() (uint64, error)
- func (ms *MemoryStorage) SetHardState(st pb.HardState) error
- func (ms *MemoryStorage) Snapshot() (pb.Snapshot, error)
- func (ms *MemoryStorage) Term(i uint64) (uint64, error)
- func (ms *MemoryStorage) UpdateConState(cs *pb.ConfState) error
- type Node
- func (rc *Node) AddNode(nodeID uint64, data []byte) error
- func (rc *Node) Addr() string
- func (rc *Node) DeleteConfigChange() error
- func (rc *Node) GetPeers() (map[uint64]*NodeInfo, uint64, error)
- func (rc *Node) InitSend() error
- func (rc *Node) IsIDRemoved(id uint64) bool
- func (rc *Node) IsJoin() bool
- func (rc *Node) IsLeader() (bool, *NodeInfo, error)
- func (rc *Node) NodeID() uint64
- func (rc *Node) NodeKey() string
- func (rc *Node) Process(ctx context.Context, m raftpb.Message) error
- func (rc *Node) ProcessData(data []byte) error
- func (rc *Node) ReadSnap(snapshotter *snap.Snapshotter, init bool) error
- func (rc *Node) ReportSnapshot(id uint64, status raft.SnapshotStatus)
- func (rc *Node) ReportUnreachable(id uint64)
- func (rc *Node) Send(event string, namespace string, key string, data []byte) error
- func (rc *Node) ServeHTTP(writer http.ResponseWriter, request *http.Request)
- func (rc *Node) Status() raft.Status
- func (rc *Node) Stop()
- func (rc *Node) UpdateHostInfo(addr string) error
- type NodeInfo
- type NodeSecret
- type Peers
- func (p *Peers) CheckExist(host string) (uint64, bool)
- func (p *Peers) DeletePeerByID(id uint64)
- func (p *Peers) GetAllPeers() map[uint64]*NodeInfo
- func (p *Peers) GetPeerByID(id uint64) (*NodeInfo, bool)
- func (p *Peers) GetPeerNum() int
- func (p *Peers) Index() uint64
- func (p *Peers) SetPeer(id uint64, value *NodeInfo)
- type PostNodeRequest
- type ProposeMsg
- type Response
- type SNRequest
- type SNResponse
- type SnapStore
Constants ¶
This section is empty.
Variables ¶
var ErrCompacted = errors.New("requested index is unavailable due to compaction")
ErrCompacted is returned by Storage.Entries/Compact when a requested index is unavailable because it predates the last snapshot.
var ErrSnapOutOfDate = errors.New("requested index is older than the existing snapshot")
ErrSnapOutOfDate is returned by Storage.CreateSnapshot when a requested index is older than the existing snapshot.
ErrSnapshotTemporarilyUnavailable is returned by the Storage interface when the required snapshot is temporarily unavailable.
ErrUnavailable is returned by Storage interface when the requested log entries are unavailable.
var File_msg_proto protoreflect.FileDescriptor
Functions ¶
Types ¶
type Command ¶ added in v0.5.0
type Command struct { Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Cmd string `protobuf:"bytes,2,opt,name=cmd,proto3" json:"cmd,omitempty"` Body []byte `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"` Version string `protobuf:"bytes,5,opt,name=version,proto3" json:"version,omitempty"` // contains filtered or unexported fields }
func (*Command) Descriptor
deprecated
added in
v0.5.0
func (*Command) GetNamespace ¶ added in v0.5.0
func (*Command) GetVersion ¶ added in v0.5.0
func (*Command) ProtoMessage ¶ added in v0.5.0
func (*Command) ProtoMessage()
func (*Command) ProtoReflect ¶ added in v0.5.0
func (x *Command) ProtoReflect() protoreflect.Message
type IRaftService ¶ added in v0.1.0
type IRaftService interface { // Commit 节点commit信息前的处理 Commit(command string, namespace string, key string, data []byte) (err error) // GetInit 集群初始化时的将service缓存中的信息进行打包处理,只会在切换集群模式的时候调用一次 GetInit() (data []byte, err error) // ResetSnap 读取快照,用于恢复service数据 ResetSnap(data []byte, isInit bool) (err error) // GetSnapshot 生成快照,用于快照文件的生成 GetSnapshot() (data []byte, err error) }
type IRaftStateHandler ¶ added in v0.5.0
type IRaftStateHandler interface {
SetState(stateType raft.StateType)
}
func CreateRaftStateHandlers ¶ added in v0.5.0
func CreateRaftStateHandlers(handlers ...IRaftStateHandler) IRaftStateHandler
type IRaftStateHandlers ¶ added in v0.5.0
type IRaftStateHandlers []IRaftStateHandler
func (IRaftStateHandlers) SetState ¶ added in v0.5.0
func (hs IRaftStateHandlers) SetState(stateType raft.StateType)
type JoinRequest ¶ added in v0.1.0
type JoinResponse ¶ added in v0.1.0
type JoinResponse struct { *NodeSecret Peer map[uint64]*NodeInfo `json:"peer"` }
type MemoryStorage ¶
type MemoryStorage struct { // Protects access to all fields. Most methods of MemoryStorage are // run on the raft goroutine, but Append() is run on an application // goroutine. sync.Mutex // contains filtered or unexported fields }
MemoryStorage implements the Storage interface backed by an in-memory array.
func NewMemoryStorage ¶
func NewMemoryStorage() *MemoryStorage
NewMemoryStorage creates an empty MemoryStorage.
func (*MemoryStorage) Append ¶
func (ms *MemoryStorage) Append(entries []pb.Entry) error
Append the new entries to storage. TODO (xiangli): ensure the entries are continuous and entries[0].Index > ms.entries[0].Index
func (*MemoryStorage) ApplySnapshot ¶
func (ms *MemoryStorage) ApplySnapshot(snap pb.Snapshot) error
ApplySnapshot overwrites the contents of this Storage object with those of the given snapshot.
func (*MemoryStorage) Compact ¶
func (ms *MemoryStorage) Compact(compactIndex uint64) error
Compact discards all log entries prior to compactIndex. It is the application's responsibility to not attempt to compact an index greater than raftLog.applied.
func (*MemoryStorage) CreateSnapshot ¶
func (ms *MemoryStorage) CreateSnapshot(i uint64, cs *pb.ConfState, data []byte) (pb.Snapshot, error)
CreateSnapshot makes a snapshot which can be retrieved with Snapshot() and can be used to reconstruct the state at that point. If any configuration changes have been made since the last compaction, the result of the last ApplyConfChange must be passed in.
func (*MemoryStorage) Entries ¶
func (ms *MemoryStorage) Entries(lo, hi, maxSize uint64) ([]pb.Entry, error)
Entries implements the Storage interface.
func (*MemoryStorage) FirstIndex ¶
func (ms *MemoryStorage) FirstIndex() (uint64, error)
FirstIndex implements the Storage interface.
func (*MemoryStorage) InitialState ¶
InitialState implements the Storage interface.
func (*MemoryStorage) LastIndex ¶
func (ms *MemoryStorage) LastIndex() (uint64, error)
LastIndex implements the Storage interface.
func (*MemoryStorage) SetHardState ¶
func (ms *MemoryStorage) SetHardState(st pb.HardState) error
SetHardState saves the current HardState.
func (*MemoryStorage) Snapshot ¶
func (ms *MemoryStorage) Snapshot() (pb.Snapshot, error)
Snapshot implements the Storage interface.
func (*MemoryStorage) Term ¶
func (ms *MemoryStorage) Term(i uint64) (uint64, error)
Term implements the Storage interface.
func (*MemoryStorage) UpdateConState ¶
func (ms *MemoryStorage) UpdateConState(cs *pb.ConfState) error
UpdateConState eosc新增,快照更新snapshot的ConfState
type Node ¶ added in v0.1.0
type Node struct {
// contains filtered or unexported fields
}
raft节点结构
func NewNode ¶ added in v0.1.0
func NewNode(service IRaftService, stateHandler ...IRaftStateHandler) (*Node, error)
NewNode 新建raft节点
func (*Node) DeleteConfigChange ¶ added in v0.1.0
DeleteConfigChange 客户端发送删除节点的发送处理
func (*Node) IsIDRemoved ¶ added in v0.1.0
func (*Node) ProcessData ¶ added in v0.1.0
func (*Node) ReadSnap ¶ added in v0.1.0
func (rc *Node) ReadSnap(snapshotter *snap.Snapshotter, init bool) error
ReadSnap 读取快照内容到service
func (*Node) ReportSnapshot ¶ added in v0.1.0
func (*Node) ReportUnreachable ¶ added in v0.1.0
func (*Node) ServeHTTP ¶ added in v0.1.0
func (rc *Node) ServeHTTP(writer http.ResponseWriter, request *http.Request)
func (*Node) UpdateHostInfo ¶ added in v0.1.0
type NodeInfo ¶ added in v0.1.0
type NodeInfo struct { *NodeSecret BroadcastIP string `json:"broadcast_ip"` BroadcastPort int `json:"broadcast_port"` Addr string `json:"addr"` Protocol string `json:"protocol"` }
type NodeSecret ¶ added in v0.1.0
type Peers ¶
type Peers struct {
// contains filtered or unexported fields
}
func (*Peers) CheckExist ¶
CheckExist 判断host对应的ID是否存在
func (*Peers) GetPeerNum ¶
type PostNodeRequest ¶ added in v0.1.1
type ProposeMsg ¶
type SNResponse ¶ added in v0.1.1
type SNResponse struct {
SN string `json:"lastSN"`
}