raft

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRaftTimeout = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Fsm

type Fsm struct {
	// contains filtered or unexported fields
}

func NewFsm

func NewFsm() *Fsm

func (*Fsm) Apply

func (f *Fsm) Apply(l *raft.Log) interface{}

func (*Fsm) DelByNode

func (f *Fsm) DelByNode(node string) int

func (*Fsm) Restore

func (f *Fsm) Restore(ir io.ReadCloser) error

func (*Fsm) Search

func (f *Fsm) Search(key string) []string

func (*Fsm) Snapshot

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

type KVStore

type KVStore struct {
	Data map[string][]string
	// contains filtered or unexported fields
}

func NewKVStore

func NewKVStore() KVStore

func (*KVStore) Del

func (d *KVStore) Del(key, value string)

func (*KVStore) DelByValue

func (d *KVStore) DelByValue(value string) int

func (*KVStore) Get

func (d *KVStore) Get(key string) []string

func (*KVStore) Persist

func (d *KVStore) Persist(sink raft.SnapshotSink) error

func (*KVStore) Release

func (d *KVStore) Release()

func (*KVStore) Set

func (d *KVStore) Set(key, value string)

type Node

type Node struct {
	// contains filtered or unexported fields
}

func NewRaftNode

func NewRaftNode(raftAddr, raftId, raftDir string) (*Node, error)

func (*Node) Apply

func (n *Node) Apply(cmd []byte, timeout time.Duration) error

func (*Node) DelByNode

func (n *Node) DelByNode(node string) int

func (*Node) GetLeader

func (n *Node) GetLeader() (addr, id string)

func (*Node) IsLeader

func (n *Node) IsLeader() bool

func (*Node) Join

func (n *Node) Join(nodeID, addr string) error

func (*Node) Leave

func (n *Node) Leave(nodeID string) error

func (*Node) Search

func (n *Node) Search(key string) []string

func (*Node) SetListener

func (n *Node) SetListener(listener func(op, key, value string))

func (*Node) Shutdown

func (n *Node) Shutdown() error

func (*Node) Snapshot

func (n *Node) Snapshot() error

func (*Node) Status

func (n *Node) Status() ([]byte, error)

func (*Node) WaitForApplied

func (n *Node) WaitForApplied(timeout time.Duration) error

WaitForApplied waits for all Raft log entries to to be applied to the underlying database.

func (*Node) WaitForAppliedIndex

func (n *Node) WaitForAppliedIndex(idx uint64, timeout time.Duration) error

WaitForAppliedIndex blocks until a given log index has been applied, or the timeout expires.

func (*Node) WaitForLeader

func (n *Node) WaitForLeader(timeout time.Duration) (string, error)

WaitForLeader blocks until a leader is detected, or the timeout expires.

Jump to

Keyboard shortcuts

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