mirror of https://github.com/status-im/consul.git
Touches up Raft integration after latest changes.
This commit is contained in:
parent
014649abb1
commit
aa4e9daf12
|
@ -310,8 +310,9 @@ func DefaultConfig() *Config {
|
|||
conf.SerfLANConfig.MemberlistConfig.BindPort = DefaultLANSerfPort
|
||||
conf.SerfWANConfig.MemberlistConfig.BindPort = DefaultWANSerfPort
|
||||
|
||||
// Enable interoperability with unversioned Raft library
|
||||
conf.RaftConfig.ProtocolVersion = 0
|
||||
// Enable interoperability with unversioned Raft library, and don't
|
||||
// start using new ID-based features yet.
|
||||
conf.RaftConfig.ProtocolVersion = 1
|
||||
|
||||
// Disable shutdown on removal
|
||||
conf.RaftConfig.ShutdownOnRemove = false
|
||||
|
|
|
@ -355,6 +355,15 @@ func (s *Server) setupRaft() error {
|
|||
trans := raft.NewNetworkTransport(s.raftLayer, 3, 10*time.Second, s.config.LogOutput)
|
||||
s.raftTransport = trans
|
||||
|
||||
// Make sure we set the LogOutput.
|
||||
s.config.RaftConfig.LogOutput = s.config.LogOutput
|
||||
|
||||
// Our version of Raft protocol requires the LocalID to match the network
|
||||
// address of the transport.
|
||||
s.config.RaftConfig.LocalID = raft.ServerID(trans.LocalAddr())
|
||||
|
||||
// Build an all in-memory setup for dev mode, otherwise prepare a full
|
||||
// disk-based setup.
|
||||
var log raft.LogStore
|
||||
var stable raft.StableStore
|
||||
var snap raft.SnapshotStore
|
||||
|
@ -394,21 +403,22 @@ func (s *Server) setupRaft() error {
|
|||
snap = snapshots
|
||||
|
||||
// If we see a peers.json file, attempt recovery based on it.
|
||||
recovery, err := raft.NewPeersJSONRecovery(path)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("recovery failed to parse peers.json: %v", err)
|
||||
}
|
||||
if recovery != nil {
|
||||
peersFile := filepath.Join(path, "peers.json")
|
||||
if _, err := os.Stat(peersFile); err == nil {
|
||||
s.logger.Printf("[INFO] consul: found peers.json file, recovering Raft configuration...")
|
||||
configuration, err := raft.ReadPeersJSON(peersFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("recovery failed to parse peers.json: %v", err)
|
||||
}
|
||||
tmpFsm, err := NewFSM(s.tombstoneGC, s.config.LogOutput)
|
||||
if err != nil {
|
||||
return fmt.Errorf("recovery failed to make temp FSM: %v", err)
|
||||
}
|
||||
if err := raft.RecoverCluster(s.config.RaftConfig, tmpFsm,
|
||||
log, stable, snap, recovery.Configuration); err != nil {
|
||||
log, stable, snap, configuration); err != nil {
|
||||
return fmt.Errorf("recovery failed: %v", err)
|
||||
}
|
||||
if err := recovery.Disarm(); err != nil {
|
||||
if err := os.Remove(peersFile); err != nil {
|
||||
return fmt.Errorf("recovery failed to delete peers.json, please delete manually: %v", err)
|
||||
}
|
||||
s.logger.Printf("[INFO] consul: deleted peers.json file after successful recovery")
|
||||
|
@ -465,9 +475,6 @@ func (s *Server) setupRaft() error {
|
|||
}
|
||||
}
|
||||
|
||||
// Make sure we set the LogOutput.
|
||||
s.config.RaftConfig.LogOutput = s.config.LogOutput
|
||||
|
||||
// Setup the Raft store.
|
||||
s.raft, err = raft.NewRaft(s.config.RaftConfig, s.fsm, log, stable, snap, trans)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue