Documentation
¶
Index ¶
- Constants
- Variables
- func Adjust(id uint64, host string, peers string, keys string, isCluster bool) (map[uint64]string, error)
- func Create() *service
- func CreateRaftNode(id int, host string, service IService, peers string, keys string, join bool, ...) (*raftNode, error)
- func JoinCluster(local string, target string, service IService) (*raftNode, error)
- type Client
- type IService
- type JoinMsg
- type KV
- 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 Peers
- func (p *Peers) CheckExist(host string) (uint64, bool)
- func (p *Peers) DeletePeerByID(id uint64)
- func (p *Peers) GetAllPeers() map[uint64]string
- func (p *Peers) GetConfigCount() int
- func (p *Peers) GetPeerByID(id uint64) (string, bool)
- func (p *Peers) GetPeerNum() int
- func (p *Peers) SetPeer(id uint64, value string)
- func (p *Peers) UpdatePeerByID(id uint64, value string)
- type ProposeMsg
- type Response
- 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 ¶
func Adjust ¶
func Adjust(id uint64, host string, peers string, keys string, isCluster bool) (map[uint64]string, error)
Adjust 参数校验与调整
func CreateRaftNode ¶
func CreateRaftNode(id int, host string, service IService, peers string, keys string, join bool, isCluster bool) (*raftNode, error)
CreateRaftNode 初始化节点 peers至少会包括节点本身,如果join为true,isCluster也默认为true 已经切换到集群模式下的节点不会回到非集群模式,除非改变节点ID或删除相关日志文件 1、创建非集群节点,isCluster为false,此时peers可为空 2、创建集群节点,isCluster为true,若此时peers为空(或仅有节点本身),表示该集群仅有一个节点 peers也可以是其余集群中的其他节点,表示这是一个多节点集群,此时其他节点也需通过同样的配置和方式启动, 推荐使用JoinCluster来新建多节点集群节点 3、创建加入已知集群的节点,join为true,isCluster为true,此时peers需包括其他节点地址,推荐使用JoinCluster来新建非单点集群节点
Types ¶
type IService ¶
type IService interface {
// CommitHandler 节点commit信息前的处理
CommitHandler(cmd string, data []byte) (err error)
// ProcessHandler 节点propose信息前的处理
ProcessHandler(command string, propose []byte) (cmd string, data []byte, err error)
// GetInit 集群初始化时的将service缓存中的信息进行打包处理,只会在切换集群模式的时候调用一次
GetInit() (cmd string, data []byte, err error)
// ResetSnap 读取快照,用于恢复service数据
ResetSnap(data []byte) (err error)
// GetSnapshot 生成快照,用于快照文件的生成
GetSnapshot() (data []byte, err error)
}
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 Peers ¶
type Peers struct {
// contains filtered or unexported fields
}
func (*Peers) CheckExist ¶
CheckExist 判断host对应的ID是否存在
func (*Peers) GetConfigCount ¶
func (*Peers) GetPeerNum ¶
func (*Peers) UpdatePeerByID ¶
UpdatePeerByID 通过ID更新节点信息

