From 9c9ba2a8a8d709bc51f90780ef7b294f8e3ec3a6 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Fri, 14 Feb 2014 11:29:09 -0600 Subject: [PATCH] Simplify logic, fix potential nil pointer dereference --- commands/pilosa-nexter/nexter.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/commands/pilosa-nexter/nexter.go b/commands/pilosa-nexter/nexter.go index a7a6d3d77..22e360756 100644 --- a/commands/pilosa-nexter/nexter.go +++ b/commands/pilosa-nexter/nexter.go @@ -82,19 +82,11 @@ func (self *Nexter) countloop(ch chan uint64, id int, client *etcd.Client) { } end = start + blocksize } - for { - newval, err := client.CompareAndSwap(path, strconv.FormatUint(end, 10), 0, strconv.FormatUint(start, 10), 0) - if err == nil { - break - } else { - log.Println("Error with CompareAndSet! Trying again in 1 second...") - time.Sleep(time.Second) - start, err = strconv.ParseUint(newval.Node.Value, 10, 0) - if err != nil { - log.Fatal(err) - } - end = start + blocksize - } + _, err = client.CompareAndSwap(path, strconv.FormatUint(end, 10), 0, strconv.FormatUint(start, 10), 0) + if err != nil { + log.Println("Error with CompareAndSet! Trying again in 1 second...") + time.Sleep(time.Second) + continue } for c := start; c < end; c += 1 { ch <- c