1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #715 from aboch/st

Some functions' logic cleanup
This commit is contained in:
Jana Radhakrishnan 2015-10-27 11:23:40 -07:00
commit f75ced4ab9
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
}