Skip to content

Commit

Permalink
set path properly in NewRaftBackend() (#9128) (#9754)
Browse files Browse the repository at this point in the history
* set path properly in NewRaftBackend()

* get rid of storeLatestState

Co-authored-by: Mike Jarmy <[email protected]>
  • Loading branch information
briankassouf and mjarmy authored Aug 17, 2020
1 parent b4d929f commit 3254fcb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 26 deletions.
8 changes: 2 additions & 6 deletions physical/raft/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ type FSM struct {
}

// NewFSM constructs a FSM using the given directory
func NewFSM(conf map[string]string, logger log.Logger) (*FSM, error) {
path, ok := conf["path"]
if !ok {
return nil, fmt.Errorf("'path' must be set")
}
func NewFSM(path string, logger log.Logger) (*FSM, error) {

// Initialize the latest term, index, and config values
latestTerm := new(uint64)
Expand All @@ -101,7 +97,7 @@ func NewFSM(conf map[string]string, logger log.Logger) (*FSM, error) {
latestConfig.Store((*ConfigurationValue)(nil))

f := &FSM{
path: conf["path"],
path: path,
logger: logger,

latestTerm: latestTerm,
Expand Down
4 changes: 1 addition & 3 deletions physical/raft/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ func getFSM(t testing.TB) (*FSM, string) {
Level: hclog.Trace,
})

fsm, err := NewFSM(map[string]string{
"path": raftDir,
}, logger)
fsm, err := NewFSM(raftDir, logger)
if err != nil {
t.Fatal(err)
}
Expand Down
11 changes: 6 additions & 5 deletions physical/raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,6 @@ func EnsurePath(path string, dir bool) error {

// NewRaftBackend constructs a RaftBackend using the given directory
func NewRaftBackend(conf map[string]string, logger log.Logger) (physical.Backend, error) {
// Create the FSM.
fsm, err := NewFSM(conf, logger.Named("fsm"))
if err != nil {
return nil, fmt.Errorf("failed to create fsm: %v", err)
}

path := os.Getenv(EnvVaultRaftPath)
if path == "" {
Expand All @@ -234,6 +229,12 @@ func NewRaftBackend(conf map[string]string, logger log.Logger) (physical.Backend
path = pathFromConfig
}

// Create the FSM.
fsm, err := NewFSM(path, logger.Named("fsm"))
if err != nil {
return nil, fmt.Errorf("failed to create fsm: %v", err)
}

// Build an all in-memory setup for dev mode, otherwise prepare a full
// disk-based setup.
var log raft.LogStore
Expand Down
16 changes: 4 additions & 12 deletions physical/raft/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,7 @@ func TestBoltSnapshotStore_Listing(t *testing.T) {
Level: hclog.Trace,
})

fsm, err := NewFSM(map[string]string{
"path": parent,
}, logger)
fsm, err := NewFSM(parent, logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -657,9 +655,7 @@ func TestBoltSnapshotStore_CreateInstallSnapshot(t *testing.T) {
Level: hclog.Trace,
})

fsm, err := NewFSM(map[string]string{
"path": parent,
}, logger)
fsm, err := NewFSM(parent, logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -757,9 +753,7 @@ func TestBoltSnapshotStore_CreateInstallSnapshot(t *testing.T) {
t.Fatal("expected snapshot installer object")
}

newFSM, err := NewFSM(map[string]string{
"path": filepath.Dir(installer.Filename()),
}, logger)
newFSM, err := NewFSM(filepath.Dir(installer.Filename()), logger)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -818,9 +812,7 @@ func TestBoltSnapshotStore_CreateInstallSnapshot(t *testing.T) {

// Close/Reopen the db and make sure we still match
fsm.Close()
fsm, err = NewFSM(map[string]string{
"path": parent,
}, logger)
fsm, err = NewFSM(parent, logger)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 3254fcb

Please sign in to comment.