raft

package
v0.0.0-...-975194c Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config, states ...StateSource) (*Raft, <-chan UnactionedMessage, *Peers)

Types

type Committer

type Committer interface {
	Add(id, parentId uint64, name string, mode store.FileMode) (bool, func())
	Change(id, version, offset uint64, size int64) (bool, func())
	Rename(id, oldParentId, newParentId uint64, oldName, newName string) (bool, func())
	Delete(id, parentId uint64, newName string) (bool, func())
}

Committer tries to commit the entry to raft. It returns true or false if the entry get completed in a timely manner. After proposing a change, which has been approved by raft, you need to invoke the callback function returned by the Committer's method. Even if you fail to action the result, you need to invoke the callback; otherwise bad things will happen. If the change wasn't approved you don't need to call the callback, and calling it will be a noop.

type Config

type Config struct {
	AllPeers   []string `toml:"all_peers"`
	ThisPeer   string   `toml:"this_peer"`
	Redundancy int      `toml:"redundancy"`
	DataDir    string
}

type Peers

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

func NewPeerList

func NewPeerList(cfg Config) *Peers

func (Peers) ForEach

func (p Peers) ForEach(f func(peer string) error) error

ForEach will call the function for every available peer. If the function returns a non-nil error, the iterations will be stopped immediately and the error will be returned directly.

func (Peers) GetPeerRaft

func (p Peers) GetPeerRaft(id uint64) string

GetPeerRaft is used for compliance with the type of raft id's being uint64 and 0 not being an acceptable peer id

func (Peers) IsLocalFile

func (p Peers) IsLocalFile(id uint64) bool

func (Peers) Len

func (p Peers) Len() int

func (Peers) PeersWithFile

func (p Peers) PeersWithFile(id uint64) []string

PeersWithFile will return the peers which are supposed to hold the provided fileId. It will exclude this peer from that list

func (Peers) ThisPeer

func (p Peers) ThisPeer() string

type Raft

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

func (*Raft) Add

func (r *Raft) Add(id, parentId uint64, name string, mode store.FileMode) (bool, func())

func (*Raft) Change

func (r *Raft) Change(id, version, offset uint64, size int64) (bool, func())

func (*Raft) Delete

func (r *Raft) Delete(id, parentId uint64, name string) (bool, func())

func (*Raft) Rename

func (r *Raft) Rename(id, oldParentId, newParentId uint64, oldName, newName string) (bool, func())

func (*Raft) Shutdown

func (r *Raft) Shutdown()

func (*Raft) Step

func (r *Raft) Step(ctx context.Context, e *etcdraftpb.Message) (*raftpb.Empty, error)

type StateSource

type StateSource interface {
	Name() string

	// GetState should return a reader to a copy of the current state. If the state changes, after the call
	// to GetState, the Read() behaviour of the returned io.Reader shouldn't change.
	GetState() (io.Reader, error)
	SetState(io.Reader) error
}

StateSource is an interface that may be implemented by sources of state for RAFT.

type UnactionedMessage

type UnactionedMessage struct {
	*raftpb.Entry

	Action func()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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