raft

package
v0.0.0-...-71b6798 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ElectionWaitDuration    = time.Duration(time.Millisecond * 10)
	AddVoterTimeoutDuration = time.Duration(time.Millisecond * 500)
	ApplyTimeout            = time.Duration(time.Second)
)

Variables

View Source
var (
	LogStoreFilePath     = "logstore.db" + fmt.Sprintf("%d", rand.Int())
	StableStoreFilePath  = "stablestore.db" + fmt.Sprintf("%d", rand.Int())
	SnapshotStoreBaseDir = "snapshot_data/" + fmt.Sprintf("%d", rand.Int())

	LogStore         = NewLogStore()
	StableStore      = NewStableStore()
	SnapshotStore, _ = raft_lib.NewFileSnapshotStore(SnapshotStoreBaseDir, 3, nil)
)

Functions

func NewLogStore

func NewLogStore() *raftboltdb.BoltStore

LogStore is used by Raft to record log entries

func NewStableStore

func NewStableStore() *raftboltdb.BoltStore

Stable store is used intenally by Raft

func NewTransport

func NewTransport(address string) *raft_lib.NetworkTransport

Creates a Transport, used to communicate with other nodes inside a cluster If it faces errors while doing, it will panic

func SplitHostPort

func SplitHostPort(address string) (string, string)

Types

type Raft

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

Raft defines an adapter which will be used to manage the hashicorp/raft cluster

func NewRaft

func NewRaft(raftID, address string, fsm raft_lib.FSM) *Raft

Creates a new raft node TODO : Currently using default config, provide a way to configure the Raft node

func (*Raft) AddVoter

func (r *Raft) AddVoter(raftID, address string)

Add voter to our cluster, Note: this must be called from a leader if the caller is not a leader, then it fails silently logging the error

func (*Raft) Apply

func (r *Raft) Apply(cmd []byte) raft_lib.ApplyFuture

Apply is used to apply a command to the FSM in a highly consistent manner. This returns a future that can be used to wait on the application. This must be run on the leader or it will fail.

func (*Raft) BootstrapCluster

func (r *Raft) BootstrapCluster()

Bootstrap Cluster

func (*Raft) GetLeader

func (r *Raft) GetLeader() raft_lib.ServerAddress

GetLeader will return the Address of the current leader If there is no leader, it will wait till new leader is elected.

func (*Raft) IsLeader

func (r *Raft) IsLeader() bool

Jump to

Keyboard shortcuts

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