mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 17:15:56 +00:00
Simplify logic, fix potential nil pointer dereference
This commit is contained in:
parent
1574341dba
commit
9c9ba2a8a8
1 changed files with 5 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue