Skip to content

Commit

Permalink
endpoint_cnt store updates should not create an object
Browse files Browse the repository at this point in the history
endpoint_cnt object is created during network create and destroyed when
network is deleted. But the updateToStore function creates an object
when it is not present in the store. endpoint_cnt is a mutable object
and is updated during endpoint create and delete events. If endpoint
create or delete happens after the network is deleted, it can
incorrectly create an endpoint_cnt object in the store and that can
cause problems when the same network is created again later.

The fix is to not create the endpoint_cnt object when endpoint_cnt is
incremented or decremented

Signed-off-by: Madhu Venugopal <[email protected]>
  • Loading branch information
mavenugo committed Oct 27, 2017
1 parent dd20549 commit f13e15b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions endpoint_cnt.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ func (ec *endpointCnt) setCnt(cnt uint64) error {
}

func (ec *endpointCnt) atomicIncDecEpCnt(inc bool) error {
store := ec.n.getController().getStore(ec.DataScope())
if store == nil {
return fmt.Errorf("store not found for scope %s", ec.DataScope())
}

tmp := &endpointCnt{n: ec.n}
if err := store.GetObject(datastore.Key(ec.Key()...), tmp); err != nil {
return err
}
retry:
ec.Lock()
if inc {
Expand All @@ -149,11 +158,6 @@ retry:
}
ec.Unlock()

store := ec.n.getController().getStore(ec.DataScope())
if store == nil {
return fmt.Errorf("store not found for scope %s", ec.DataScope())
}

if err := ec.n.getController().updateToStore(ec); err != nil {
if err == datastore.ErrKeyModified {
if err := store.GetObject(datastore.Key(ec.Key()...), ec); err != nil {
Expand Down
1 change: 1 addition & 0 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ retry:
if err := cs.GetObject(datastore.Key(kvObject.Key()...), kvObject); err != nil {
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
}
logrus.Errorf("Error (%v) deleting object %v, retrying....", err, kvObject.Key())
goto retry
}
return err
Expand Down

0 comments on commit f13e15b

Please sign in to comment.