raft

package
v0.0.0-...-009cb35 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRaftNode

func NewRaftNode(id int, peers []string, join bool, getSnapshot func() ([]byte, error), proposeC <-chan string,
	confChangeC <-chan raftpb.ConfChange) (<-chan *commit, <-chan error, <-chan *snap.Snapshotter)

newRaftNode initiates a raft instance and returns a committed log entry channel and error channel. Proposals for log updates are sent over the provided the proposal channel. All log entries are replayed over the commit channel, followed by a nil message (to indicate the channel is current), then new log entries. To shutdown, close proposeC and read errorC.

func ServeHttpKVAPI

func ServeHttpKVAPI(kv *KVStore, port int, confChangeC chan<- raftpb.ConfChange, errorC <-chan error)

serveHttpKVAPI starts a key-value server with a GET/PUT API and listens.

func ServeHttpSDAPI

func ServeHttpSDAPI()

serveHttpSDAPI starts a key-value server with a GET/PUT API and listens.

Types

type BoltStorage

type BoltStorage struct {
	sync.Mutex
	// contains filtered or unexported fields
}

BoltStorage implements the Storage interface backed by an boltdb

func NewBoltStorage

func NewBoltStorage(db *bolt.DB) *BoltStorage

func (*BoltStorage) Entries

func (bs *BoltStorage) Entries(lo, hi, maxSize uint64) ([]pb.Entry, error)

Entries returns a slice of log entries in the range [lo,hi). MaxSize limits the total size of the log entries returned, but Entries returns at least one entry if any.

func (*BoltStorage) FirstIndex

func (bs *BoltStorage) FirstIndex() (uint64, error)

FirstIndex returns the index of the first log entry that is possibly available via Entries (older entries have been incorporated into the latest Snapshot; if storage only contains the dummy entry the first log entry is not available).

func (*BoltStorage) InitialState

func (bs *BoltStorage) InitialState() (pb.HardState, pb.ConfState, error)

InitialState returns the saved HardState and ConfState information.

func (*BoltStorage) LastIndex

func (bs *BoltStorage) LastIndex() (uint64, error)

LastIndex returns the index of the last entry in the log.

func (*BoltStorage) Snapshot

func (bs *BoltStorage) Snapshot() (pb.Snapshot, error)

Snapshot returns the most recent snapshot. If snapshot is temporarily unavailable, it should return ErrSnapshotTemporarilyUnavailable, so raft state machine could know that Storage needs some time to prepare snapshot and call Snapshot later.

func (*BoltStorage) Term

func (bs *BoltStorage) Term(i uint64) (uint64, error)

Term returns the term of entry i, which must be in the range [FirstIndex()-1, LastIndex()]. The term of the entry before FirstIndex is retained for matching purposes even though the rest of that entry may not be available.

type KVStore

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

a key-value store backed by raft

func NewKVStore

func NewKVStore(snapshotter *snap.Snapshotter, proposeC chan<- string, commitC <-chan *commit, errorC <-chan error) *KVStore

func (*KVStore) GetSnapshot

func (s *KVStore) GetSnapshot() ([]byte, error)

func (*KVStore) Lookup

func (s *KVStore) Lookup(key string) (string, bool)

func (*KVStore) Propose

func (s *KVStore) Propose(k string, v string)

Jump to

Keyboard shortcuts

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