소스 검색

Merge pull request #715 from aboch/st

Some functions' logic cleanup
Jana Radhakrishnan 9 년 전
부모
커밋
f75ced4ab9
3개의 변경된 파일14개의 추가작업 그리고 23개의 파일을 삭제
  1. 1 1
      libnetwork/endpoint.go
  2. 7 11
      libnetwork/endpoint_cnt.go
  3. 6 11
      libnetwork/sandbox.go

+ 1 - 1
libnetwork/endpoint.go

@@ -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
 }

+ 7 - 11
libnetwork/endpoint_cnt.go

@@ -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 {

+ 6 - 11
libnetwork/sandbox.go

@@ -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)
-			})
-	}
 
-	if err != nil {
-		for _, f := range undo {
-			f()
-		}
+		defer func() {
+			if err != nil {
+				lEp.rename(oldName)
+			}
+		}()
 	}
+
 	return err
 }