raft

package
v0.0.0-...-135b226 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SNAPSHOT_RETAIN = 3
	RAFT_TIMEOUT    = 10 * time.Second
)

Variables

This section is empty.

Functions

func NewPeer

func NewPeer(multiaddr string) (host.Host, error)

Types

type KVOperation

type KVOperation struct {
	Op    string
	Key   string
	Value string
}

all fields must be public otherwise raft will dismiss them in (de)serilization

func (*KVOperation) ApplyTo

func (s *KVOperation) ApplyTo(state consensus.State) (consensus.State, error)

type KVStore

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

Data is exported because it needs to be serialized

func NewKVStore

func NewKVStore(node *RaftNode) (*KVStore, error)

func (*KVStore) Delete

func (s *KVStore) Delete(key string) error

Delete deletes the given key.

func (*KVStore) Get

func (s *KVStore) Get(key string) (string, error)

Get returns the value for the given key.

func (*KVStore) Set

func (s *KVStore) Set(key, value string) error

type NotLeaderError

type NotLeaderError struct{}

func (*NotLeaderError) Error

func (e *NotLeaderError) Error() string

Implement the Error method for NotLeaderError

type RaftNode

type RaftNode struct {
	Raft        *raft.Raft
	Consensus   *raftp2p.Consensus
	Actor       *raftp2p.Actor
	Transport   *raft.NetworkTransport
	Config      raft.Config
	Snapshots   raft.SnapshotStore
	StableStore raft.StableStore
	LogStore    raft.LogStore
}

func NewRaftNode

func NewRaftNode(host host.Host, peers []*peer.AddrInfo, raftDir string) (*RaftNode, error)

func (*RaftNode) StartNode

func (node *RaftNode) StartNode(c *raftp2p.Consensus) error

type TestState

type TestState struct {
	Value int
}

Jump to

Keyboard shortcuts

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