Documentation ¶
Index ¶
Constants ¶
const ( ElectionWaitDuration = time.Duration(time.Millisecond * 10) AddVoterTimeoutDuration = time.Duration(time.Millisecond * 500) ApplyTimeout = time.Duration(time.Second) )
Variables ¶
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 ¶
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 ¶
Creates a new raft node TODO : Currently using default config, provide a way to configure the Raft node
func (*Raft) AddVoter ¶
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) 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.