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