Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

standby server: save Running info correctly #881

Merged
merged 1 commit into from
Jul 25, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions server/standby_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type StandbyServerConfig struct {
}

type standbyInfo struct {
// stay running in standby mode
Running bool
Cluster []*machineMessage
SyncInterval float64
Expand Down Expand Up @@ -78,12 +79,16 @@ func (s *StandbyServer) Start() {
s.removeNotify = 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)
go func() {
defer s.routineGroup.Done()
s.monitorCluster()
}()
s.Running = true
}

// Stop stops the server gracefully.
Expand All @@ -97,11 +102,6 @@ func (s *StandbyServer) Stop() {

close(s.closeChan)
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
Expand Down Expand Up @@ -204,6 +204,10 @@ func (s *StandbyServer) monitorCluster() {
}

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() {
s.Stop()
close(s.removeNotify)
Expand Down