Merge pull request #881 from unihorn/111

standby server: save Running info correctly
This commit is contained in:
Yicheng Qin 2014-07-24 17:29:25 -07:00
commit a884f2a18a

View File

@ -30,6 +30,7 @@ type StandbyServerConfig struct {
} }
type standbyInfo struct { type standbyInfo struct {
// stay running in standby mode
Running bool Running bool
Cluster []*machineMessage Cluster []*machineMessage
SyncInterval float64 SyncInterval float64
@ -78,12 +79,16 @@ func (s *StandbyServer) Start() {
s.removeNotify = make(chan bool) s.removeNotify = make(chan bool)
s.closeChan = make(chan bool) s.closeChan = make(chan bool)
s.Running = true
if err := s.saveInfo(); err != nil {
log.Warnf("error saving cluster info for standby")
}
s.routineGroup.Add(1) s.routineGroup.Add(1)
go func() { go func() {
defer s.routineGroup.Done() defer s.routineGroup.Done()
s.monitorCluster() s.monitorCluster()
}() }()
s.Running = true
} }
// Stop stops the server gracefully. // Stop stops the server gracefully.
@ -97,11 +102,6 @@ func (s *StandbyServer) Stop() {
close(s.closeChan) close(s.closeChan)
s.routineGroup.Wait() s.routineGroup.Wait()
if err := s.saveInfo(); err != nil {
log.Warnf("error saving cluster info for standby")
}
s.Running = false
} }
// RemoveNotify notifies the server is removed from standby mode and ready // RemoveNotify notifies the server is removed from standby mode and ready
@ -204,6 +204,10 @@ func (s *StandbyServer) monitorCluster() {
} }
log.Infof("join through leader %v", leader.PeerURL) log.Infof("join through leader %v", leader.PeerURL)
s.Running = false
if err := s.saveInfo(); err != nil {
log.Warnf("error saving cluster info for standby")
}
go func() { go func() {
s.Stop() s.Stop()
close(s.removeNotify) close(s.removeNotify)