raft

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterStateNew      = "new"
	ClusterStateExisting = "existing"
)

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")

Functions

This section is empty.

Types

type Config

type Config struct {
	// ID is the identity of the local raft. ID cannot be 0.
	ID uint64 `yaml:"id"`
	// DataDir is the directory to store the raft data which includes snapshot and WALs.
	DataDir string `yaml:"data_dir"`
	// ClusterState is the state of the cluster, can be one of "new" and "existing".
	ClusterState string `yaml:"cluster_state"`
	// Peers is the list of raft peers.
	Peers []string `yaml:"peers"`
	// HeartbeatSeconds is the interval to send heartbeat message. Default is 2 seconds.
	HeartbeatSeconds int `yaml:"heartbeat_seconds"`
	// ElectionSeconds is the interval to start an election. Default is 10 * HeartBeat.
	ElectionSeconds int `yaml:"election_seconds"`
}

type DataStore

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

func NewDataStore

func NewDataStore(dir string) *DataStore

func (*DataStore) Close

func (ds *DataStore) Close()

func (*DataStore) Delete

func (ds *DataStore) Delete(key string)

func (*DataStore) Get

func (ds *DataStore) Get(key string) ([]byte, error)

func (*DataStore) GetDataStoreSnapshot

func (ds *DataStore) GetDataStoreSnapshot() ([]byte, error)

func (*DataStore) List

func (ds *DataStore) List(prefix string) []engine.Entry

func (*DataStore) Set

func (ds *DataStore) Set(key string, value []byte)

type Event

type Event struct {
	Op    int    `json:"op"`
	Key   string `json:"key"`
	Value []byte `json:"value"`
}

type Logger

type Logger struct {
	*zap.SugaredLogger
}

Logger is a wrapper around zap.SugaredLogger to implement the raft.Logger interface.

func (Logger) Debug

func (r Logger) Debug(v ...interface{})

func (Logger) Debugf

func (r Logger) Debugf(format string, v ...interface{})

func (Logger) Error

func (r Logger) Error(v ...interface{})

func (Logger) Errorf

func (r Logger) Errorf(format string, v ...interface{})

func (Logger) Fatal

func (r Logger) Fatal(v ...interface{})

func (Logger) Fatalf

func (r Logger) Fatalf(format string, v ...interface{})

func (Logger) Info

func (r Logger) Info(v ...interface{})

func (Logger) Infof

func (r Logger) Infof(format string, v ...interface{})

func (Logger) Panic

func (r Logger) Panic(v ...interface{})

func (Logger) Panicf

func (r Logger) Panicf(format string, v ...interface{})

func (Logger) Warning

func (r Logger) Warning(v ...interface{})

func (Logger) Warningf

func (r Logger) Warningf(format string, v ...interface{})

type Node

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

func New

func New(config *Config) (*Node, error)

func (*Node) AddPeer

func (n *Node) AddPeer(ctx context.Context, nodeID uint64, peer string) error

func (*Node) Addr

func (n *Node) Addr() string

func (*Node) Close

func (n *Node) Close() error

func (*Node) Delete

func (n *Node) Delete(ctx context.Context, key string) error

func (*Node) Exists

func (n *Node) Exists(_ context.Context, key string) (bool, error)

func (*Node) Get

func (n *Node) Get(_ context.Context, key string) ([]byte, error)

func (*Node) GetRaftLead

func (n *Node) GetRaftLead() uint64

func (*Node) ID

func (n *Node) ID() string

func (*Node) IsIDRemoved

func (n *Node) IsIDRemoved(_ uint64) bool

func (*Node) IsReady

func (n *Node) IsReady(ctx context.Context) bool

func (*Node) Leader

func (n *Node) Leader() string

func (*Node) LeaderChange

func (n *Node) LeaderChange() <-chan bool

func (*Node) List

func (n *Node) List(_ context.Context, prefix string) ([]engine.Entry, error)

func (*Node) ListPeers

func (n *Node) ListPeers() map[uint64]string

func (*Node) Process

func (n *Node) Process(ctx context.Context, m raftpb.Message) error

func (*Node) RemovePeer

func (n *Node) RemovePeer(ctx context.Context, nodeID uint64) error

func (*Node) ReportSnapshot

func (n *Node) ReportSnapshot(id uint64, status raft.SnapshotStatus)

func (*Node) ReportUnreachable

func (n *Node) ReportUnreachable(id uint64)

func (*Node) Set

func (n *Node) Set(ctx context.Context, key string, value []byte) error

func (*Node) SetSnapshotThreshold

func (n *Node) SetSnapshotThreshold(threshold uint64)

Jump to

Keyboard shortcuts

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