diff --git a/zk.go b/zk.go index a3f4b42..9d5b659 100644 --- a/zk.go +++ b/zk.go @@ -209,7 +209,6 @@ func MesosFromZKOpts(options ...ZKOpt) (string, error) { } // Create a closure that allows us to use the ExponentialBackoff function. - config.backoff.Steps = 1 retryErr := ExponentialBackoff(config.backoff, config.logger, func() (bool, error) { c, _, err := zk.Connect(config.endpoints, config.timeout, func(c *zk.Conn) { c.SetLogger(config.logger) }) @@ -234,15 +233,20 @@ func MesosFromZKOpts(options ...ZKOpt) (string, error) { // Search for the leader through all the children in the given path minScore := math.MaxInt64 - mesosInstance := new(MesosInstance) + var mesosInstance MesosInstance for _, child := range children { - // Only the leader will start with json.info_ if strings.HasPrefix(child, "json.info_") { - score, err := strconv.Atoi((strings.Split(child, "_"))[1]) - if err != nil { - NewTemporaryError(errors.Wrap(err, "unable to read the zk node for Mesos.")) + strs := strings.Split(child, "_") + if len(strs) < 2 { + config.logger.Printf("Zk node %v/%v's name is malformed.", config.path, child) + continue } + score, err := strconv.Atoi(strs[1]) + if err != nil { + return false, NewTemporaryError(errors.Wrap(err, "unable to read the zk node for Mesos.")) + } + // get the leader from the child with the smallest score. if score < minScore { minScore = score @@ -256,7 +260,7 @@ func MesosFromZKOpts(options ...ZKOpt) (string, error) { return false, NewTemporaryError(errors.Wrap(err, "error fetching contents of leader")) } - err = json.Unmarshal([]byte(data), mesosInstance) + err = json.Unmarshal([]byte(data), &mesosInstance) if err != nil { config.logger.Printf("%s", err) return false,