Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export SkipStartup + add raft.Raft.Start() #518

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func RecoverCluster(conf *Config, fsm FSM, logs LogStore, stable StableStore,
// has identical behavior to Raft.GetConfiguration.
func GetConfiguration(conf *Config, fsm FSM, logs LogStore, stable StableStore,
snaps SnapshotStore, trans Transport) (Configuration, error) {
conf.skipStartup = true
conf.SkipStartup = true
r, err := NewRaft(conf, fsm, logs, stable, snaps, trans)
if err != nil {
return Configuration{}, err
Expand Down Expand Up @@ -594,14 +594,18 @@ func NewRaft(conf *Config, fsm FSM, logs LogStore, stable StableStore, snaps Sna
// to be called concurrently with a blocking RPC.
trans.SetHeartbeatHandler(r.processHeartbeat)

if conf.skipStartup {
if conf.SkipStartup {
return r, nil
}
// Start the background work.
r.Start()
return r, nil
}

// Start the background work.
func (r *Raft) Start() {
r.goFunc(r.run)
r.goFunc(r.runFSM)
r.goFunc(r.runSnapshots)
return r, nil
}

// restoreSnapshot attempts to restore the latest snapshots, and fails if none
Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ type Config struct {
// raft's configuration and index values.
NoSnapshotRestoreOnStart bool

// skipStartup allows NewRaft() to bypass all background work goroutines
skipStartup bool
// SkipStartup allows NewRaft() to bypass all background work goroutines
SkipStartup bool
}

func (conf *Config) getOrCreateLogger() hclog.Logger {
Expand Down
4 changes: 2 additions & 2 deletions raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2822,7 +2822,7 @@ func TestRaft_runFollower_State_Transition(t *testing.T) {
tt.fields.conf.CommitTimeout = 5 * time.Millisecond
tt.fields.conf.SnapshotThreshold = 100
tt.fields.conf.TrailingLogs = 10
tt.fields.conf.skipStartup = true
tt.fields.conf.SkipStartup = true

// Create a raft instance and set the latest configuration
env1 := MakeRaft(t, tt.fields.conf, false)
Expand Down Expand Up @@ -2850,7 +2850,7 @@ func TestRaft_runFollower_ReloadTimeoutConfigs(t *testing.T) {
conf.CommitTimeout = 5 * time.Millisecond
conf.SnapshotThreshold = 100
conf.TrailingLogs = 10
conf.skipStartup = true
conf.SkipStartup = true

env := MakeRaft(t, conf, false)
servers := []Server{{Voter, "first", ""}}
Expand Down