Skip to content

Commit

Permalink
Fixed an issue where blue green switches weren't being handled gracef…
Browse files Browse the repository at this point in the history
…ully.
  • Loading branch information
Marcus committed Jul 28, 2015
1 parent e4ebaca commit 2ec223f
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions zk_coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,19 +669,27 @@ func (this *ZookeeperCoordinator) tryRemoveOldApiRequests(group string, api Cons
}
for _, request := range requests {
childPath := fmt.Sprintf("%s/%s", apiPath, request)
if data, _, err = this.zkConn.Get(childPath); err != nil && err != zk.ErrNoNode {
// It's possible another consumer deleted the node before we could read it's data
break
if api == Rebalance {
if data, _, err = this.zkConn.Get(childPath); err != nil && err != zk.ErrNoNode {
// It's possible another consumer deleted the node before we could read it's data
break
}
if t, err = strconv.ParseInt(string(data), 10, 64); err != nil {
t = int64(0) // If the data isn't a timestamp ensure it will be deleted anyway.
}
} else if api == BlueGreenRequest {
if t, err = strconv.ParseInt(string(request), 10, 64); err != nil {
break
}
}

if t, err = strconv.ParseInt(string(data), 10, 64); err == nil && !time.Unix(t, 0).Before(time.Now()) {
// Don't delete if this zk node has a timestamp as the data and the timestamp is still valid
continue
}
// If the data is not a timestamp or is a timestamp but has reached expiration delete it
err = this.deleteNode(childPath)
if err != nil && err != zk.ErrNoNode {
break
// Don't delete if this zk node has a timestamp as the data and the timestamp is still valid
if !time.Unix(t, 0).Before(time.Now().Add(-10*time.Minute)) {
// If the data is not a timestamp or is a timestamp but has reached expiration delete it
err = this.deleteNode(childPath)
if err != nil && err != zk.ErrNoNode {
break
}
}
}
}
Expand Down

0 comments on commit 2ec223f

Please sign in to comment.