Documentation ¶
Index ¶
- Constants
- Variables
- func JoinCluster(rc *Node, broadCastIP string, broadPort int, address string, protocol string) error
- type IRaftSender
- type IRaftService
- type IService
- 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 Message
- 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) 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) ProcessInitData(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(msg []byte) (interface{}, 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 ¶
const INIT commandType = 1
const PROPOSE commandType = 2
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.
Functions ¶
Types ¶
type IRaftSender ¶ added in v0.1.0
type IRaftService ¶ added in v0.1.0
type IRaftService interface { IService }
type IService ¶
type IService interface { // Commit 节点commit信息前的处理 Commit(data []byte) (err error) // PreProcessData 转发到leader时的处理 PreProcessData(body []byte) (object interface{}, data []byte, err error) // GetInit 集群初始化时的将service缓存中的信息进行打包处理,只会在切换集群模式的时候调用一次 GetInit() (data []byte, err error) // ResetSnap 读取快照,用于恢复service数据 ResetSnap(data []byte) (err error) // GetSnapshot 生成快照,用于快照文件的生成 GetSnapshot() (data []byte, err error) SetRaft(raft IRaftSender) }
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 (*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) ProcessInitData ¶ 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) Send ¶ added in v0.1.0
Send 客户端发送propose请求的处理 由客户端API调用或Leader收到转发后调用 如果是非集群模式(isCluster为false),直接处理(即service.ProcessHandler后直接service.Commit) 如果是集群模式,分两种情况 1、当前节点是leader,经service.ProcessHandler后由node.Propose处理后返回, 后续会由各个节点的node.Ready读取后进行Commit时由service.CommitHandler处理 2、当前节点不是leader,获取当前leader节点地址,转发至leader进行处理(rc.proposeHandler), leader收到请求后经service.ProcessHandler后由node.Propose处理后返回, 后续会由各个节点的node.Ready读取后进行Commit时由service.CommitHandler处理
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"`
}