Skip to content

Commit

Permalink
Fix issue with update counter fail when max retry
Browse files Browse the repository at this point in the history
Signed-off-by: Swarvanu Sengupta <[email protected]>
  • Loading branch information
s8sg committed Nov 26, 2018
1 parent a712512 commit 0ba3273
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (consulStore *ConsulStateStore) Create(vertexs []string) error {

// IncrementCounter
func (consulStore *ConsulStateStore) IncrementCounter(vertex string) (int, error) {
var serr error
count := 0
key := fmt.Sprintf("%s/%s", consulStore.consulKeyPath, vertex)
for i := 0; i < consulStore.RetryCount; i++ {
Expand All @@ -78,20 +79,20 @@ func (consulStore *ConsulStateStore) IncrementCounter(vertex string) (int, error
modifyIndex := pair.ModifyIndex
counter, err := strconv.Atoi(string(pair.Value))
if err != nil {
return 0, fmt.Errorf("failed to convert counter for %s, error %v", vertex, err)
return 0, fmt.Errorf("failed to update counter for %s, error %v", vertex, err)
}

count = counter + 1
counterStr := fmt.Sprintf("%d", count)

p := &consul.KVPair{Key: key, Value: []byte(counterStr), ModifyIndex: modifyIndex}
_, err = consulStore.kv.Put(p, nil)
if err != nil {
continue
if err == nil {
return count, nil
}
break
serr = err
}
return count, nil
return 0, fmt.Errorf("failed to update counter after max retry for %s, error %v", vertex, serr)
}

// SetState set state of pipeline
Expand Down

0 comments on commit 0ba3273

Please sign in to comment.