raft

package
v0.1.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2022 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	Id        raft.ServerID
	Raft      *raft.Raft
	Transport raft.Transport
}

func CreateNode

func CreateNode(id string, address string) (*Node, error)

* 创建新的节点

func (*Node) ApplyJoin

func (node *Node) ApplyJoin(address string)

* 发送申请加入的请求

func (*Node) Execute

func (node *Node) Execute(cmd []byte)

* 执行命令

func (*Node) Join

func (node *Node) Join(address string)

* 先启动的节点收到申请加入的请求后,加一个新的节点,参数为新节点的地址

func (*Node) Start

func (node *Node) Start(bootstrap bool)

* 最开始启动的节点,也是leader节点

type StoreFSM

type StoreFSM struct {
}

* FSM需要实现三个方法

func (*StoreFSM) Apply

func (f *StoreFSM) Apply(logEntry *raft.Log) interface{}

* 执行一个操作日志,包含数据或者sql

func (*StoreFSM) Restore

func (f *StoreFSM) Restore(serialized io.ReadCloser) error

* 从快照恢复

func (*StoreFSM) Snapshot

func (f *StoreFSM) Snapshot() (raft.FSMSnapshot, error)

* 产生快照

type StoreSnapshot

type StoreSnapshot struct {
}

func (*StoreSnapshot) Persist

func (s *StoreSnapshot) Persist(sink raft.SnapshotSink) error

* 产生快照的时候调用,把当前所有的数据进行序列化备份

func (*StoreSnapshot) Release

func (f *StoreSnapshot) Release()

* Persist操作完成后调用

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL