From 2ec223fe6de0bdf10a0351ae0f79b3e0b788a586 Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 28 Jul 2015 14:47:27 -0700 Subject: [PATCH] Fixed an issue where blue green switches weren't being handled gracefully. --- zk_coordinator.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/zk_coordinator.go b/zk_coordinator.go index 34f17ea..165f45c 100644 --- a/zk_coordinator.go +++ b/zk_coordinator.go @@ -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 + } } } }