Some functions' logic cleanup

Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
Alessandro Boch 2015-10-27 10:14:54 -07:00
parent bd77346032
commit 7b4b56169b
3 changed files with 14 additions and 23 deletions

View File

@ -471,7 +471,7 @@ func (ep *endpoint) rename(name string) error {
// benign error. Besides there is no meaningful recovery that
// we can do. When the cluster recovers subsequent EpCnt update
// will force the peers to get the correct EP name.
_ = n.getEpCnt().updateStore()
n.getEpCnt().updateStore()
return err
}

View File

@ -109,22 +109,18 @@ func (ec *endpointCnt) EndpointCnt() uint64 {
}
func (ec *endpointCnt) updateStore() error {
retry:
store := ec.n.getController().getStore(ec.DataScope())
if store == nil {
return fmt.Errorf("store not found for scope %s", ec.DataScope())
return fmt.Errorf("store not found for scope %s on endpoint count update", 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 {
return fmt.Errorf("could not update the kvobject to latest on rename: %v", err)
}
goto retry
for {
if err := ec.n.getController().updateToStore(ec); err == nil || err != datastore.ErrKeyModified {
return err
}
if err := store.GetObject(datastore.Key(ec.Key()...), ec); err != nil {
return fmt.Errorf("could not update the kvobject to latest on endpoint count update: %v", err)
}
return err
}
return nil
}
func (ec *endpointCnt) atomicIncDecEpCnt(inc bool) error {

View File

@ -205,7 +205,6 @@ func (sb *sandbox) Delete() error {
func (sb *sandbox) Rename(name string) error {
var err error
undo := []func(){}
for _, ep := range sb.getConnectedEndpoints() {
if ep.endpointInGWNetwork() {
@ -217,18 +216,14 @@ func (sb *sandbox) Rename(name string) error {
if err = ep.rename(name); err != nil {
break
}
undo = append(undo,
func() {
// Ignore the error while undoing
_ = lEp.rename(oldName)
})
defer func() {
if err != nil {
lEp.rename(oldName)
}
}()
}
if err != nil {
for _, f := range undo {
f()
}
}
return err
}