consul: Ensure FSM stores data in the data dir

This commit is contained in:
Armon Dadgar 2014-10-15 14:57:59 -07:00
parent 7380216911
commit bb3324dd85
1 changed files with 14 additions and 4 deletions

View File

@ -34,6 +34,7 @@ const (
serfLANSnapshot = "serf/local.snapshot"
serfWANSnapshot = "serf/remote.snapshot"
raftState = "raft/"
tmpStatePath = "tmp/"
snapshotsRetained = 2
raftDBSize32bit uint64 = 64 * 1024 * 1024 // Limit Raft log to 64MB
raftDBSize64bit uint64 = 8 * 1024 * 1024 * 1024 // Limit Raft log to 8GB
@ -298,15 +299,18 @@ func (s *Server) setupRaft() error {
s.config.RaftConfig.EnableSingleNode = true
}
// Create the base path
path := filepath.Join(s.config.DataDir, raftState)
if err := ensurePath(path, true); err != nil {
// Create the base state path
statePath := filepath.Join(s.config.DataDir, tmpStatePath)
if err := os.RemoveAll(statePath); err != nil {
return err
}
if err := ensurePath(statePath, true); err != nil {
return err
}
// Create the FSM
var err error
s.fsm, err = NewFSM(s.config.LogOutput)
s.fsm, err = NewFSM(statePath, s.config.LogOutput)
if err != nil {
return err
}
@ -319,6 +323,12 @@ func (s *Server) setupRaft() error {
dbSize = raftDBSize64bit
}
// Create the base raft path
path := filepath.Join(s.config.DataDir, raftState)
if err := ensurePath(path, true); err != nil {
return err
}
// Create the MDB store for logs and stable storage
store, err := raftmdb.NewMDBStoreWithSize(path, dbSize)
if err != nil {