Skip to content

Commit

Permalink
cluster: double-check on stop server before hash
Browse files Browse the repository at this point in the history
Hash method calls force-commit, and underline meta, pgid can be nil

Fix #30.
  • Loading branch information
gyuho committed Oct 9, 2016
1 parent 7ed2bdc commit 71bc8b5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ func (c *Cluster) updateNodeStatus() {
}()

if c.IsStopped(i) {
c.nodes[i].statusLock.Lock()
c.nodes[i].status.StateTxt = fmt.Sprintf("%s has been stopped (since %s)", c.nodes[i].status.Name, humanize.Time(c.nodes[i].stoppedStartedAt))
c.nodes[i].statusLock.Unlock()
plog.Printf("%s has been stopped (skipping updateNodeStatus)", c.nodes[i].cfg.Name)
return
}
Expand All @@ -452,7 +454,7 @@ func (c *Cluster) updateNodeStatus() {
defer cli.Close()

now = time.Now()
ctx, cancel := context.WithTimeout(c.rootCtx, 3*time.Second)
ctx, cancel := context.WithTimeout(c.rootCtx, time.Second)
resp, err := cli.Status(ctx, c.nodes[i].cfg.LCUrls[0].Host)
cancel()
if err != nil {
Expand Down Expand Up @@ -483,7 +485,7 @@ func (c *Cluster) updateNodeStatus() {
}

now = time.Now()
conn, err := grpc.Dial(c.nodes[i].cfg.LCUrls[0].Host, grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)), grpc.WithTimeout(3*time.Second))
conn, err := grpc.Dial(c.nodes[i].cfg.LCUrls[0].Host, grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)), grpc.WithTimeout(time.Second))
if err != nil {
c.nodes[i].statusLock.Lock()
c.nodes[i].status.State = StoppedNodeStatus
Expand All @@ -499,7 +501,17 @@ func (c *Cluster) updateNodeStatus() {

now = time.Now()
mc := pb.NewMaintenanceClient(conn)
ctx, cancel = context.WithTimeout(c.rootCtx, 3*time.Second)

// TODO: https://github.com/coreos/etcdlabs/issues/30
if c.IsStopped(i) { // double-check
c.nodes[i].statusLock.Lock()
c.nodes[i].status.StateTxt = fmt.Sprintf("%s has been stopped (since %s)", c.nodes[i].status.Name, humanize.Time(c.nodes[i].stoppedStartedAt))
c.nodes[i].statusLock.Unlock()
plog.Printf("%s has been stopped (skipping updateNodeStatus)", c.nodes[i].cfg.Name)
return
}

ctx, cancel = context.WithTimeout(c.rootCtx, time.Second)
var hresp *pb.HashResponse
hresp, err = mc.Hash(ctx, &pb.HashRequest{})
cancel()
Expand Down

0 comments on commit 71bc8b5

Please sign in to comment.