瀏覽代碼

libnetwork: Network.updateSvcRecord: remove unused localEps arg

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 年之前
父節點
當前提交
8ae5dc4aae
共有 3 個文件被更改,包括 12 次插入24 次删除
  1. 8 8
      libnetwork/endpoint.go
  2. 1 1
      libnetwork/network.go
  3. 3 15
      libnetwork/store.go

+ 8 - 8
libnetwork/endpoint.go

@@ -567,9 +567,8 @@ func (ep *Endpoint) sbJoin(sb *Sandbox, options ...EndpointOption) (err error) {
 
 
 func (ep *Endpoint) rename(name string) error {
 func (ep *Endpoint) rename(name string) error {
 	var (
 	var (
-		err      error
-		netWatch *netWatch
-		ok       bool
+		err error
+		ok  bool
 	)
 	)
 
 
 	n := ep.getNetwork()
 	n := ep.getNetwork()
@@ -591,12 +590,13 @@ func (ep *Endpoint) rename(name string) error {
 		}
 		}
 	} else {
 	} else {
 		c.mu.Lock()
 		c.mu.Lock()
-		netWatch, ok = c.nmap[n.ID()]
+		_, ok = c.nmap[n.ID()]
 		c.mu.Unlock()
 		c.mu.Unlock()
 		if !ok {
 		if !ok {
+			// FIXME(thaJeztah): what is this check for, or is this to prevent a race condition (network removed)?
 			return fmt.Errorf("watch null for network %q", n.Name())
 			return fmt.Errorf("watch null for network %q", n.Name())
 		}
 		}
-		n.updateSvcRecord(ep, c.getLocalEps(netWatch), false)
+		n.updateSvcRecord(ep, false)
 	}
 	}
 
 
 	oldName := ep.name
 	oldName := ep.name
@@ -621,13 +621,13 @@ func (ep *Endpoint) rename(name string) error {
 			}
 			}
 		}()
 		}()
 	} else {
 	} else {
-		n.updateSvcRecord(ep, c.getLocalEps(netWatch), true)
+		n.updateSvcRecord(ep, true)
 		defer func() {
 		defer func() {
 			if err != nil {
 			if err != nil {
-				n.updateSvcRecord(ep, c.getLocalEps(netWatch), false)
+				n.updateSvcRecord(ep, false)
 				ep.name = oldName
 				ep.name = oldName
 				ep.anonymous = oldAnonymous
 				ep.anonymous = oldAnonymous
-				n.updateSvcRecord(ep, c.getLocalEps(netWatch), true)
+				n.updateSvcRecord(ep, true)
 			}
 			}
 		}()
 		}()
 	}
 	}

+ 1 - 1
libnetwork/network.go

@@ -1272,7 +1272,7 @@ func (n *Network) EndpointByID(id string) (*Endpoint, error) {
 	return ep, nil
 	return ep, nil
 }
 }
 
 
-func (n *Network) updateSvcRecord(ep *Endpoint, localEps []*Endpoint, isAdd bool) {
+func (n *Network) updateSvcRecord(ep *Endpoint, isAdd bool) {
 	var ipv6 net.IP
 	var ipv6 net.IP
 	epName := ep.Name()
 	epName := ep.Name()
 	if iface := ep.Iface(); iface != nil && iface.Address() != nil {
 	if iface := ep.Iface(); iface != nil && iface.Address() != nil {

+ 3 - 15
libnetwork/store.go

@@ -196,18 +196,6 @@ type netWatch struct {
 	remoteEps map[string]*Endpoint
 	remoteEps map[string]*Endpoint
 }
 }
 
 
-func (c *Controller) getLocalEps(nw *netWatch) []*Endpoint {
-	c.mu.Lock()
-	defer c.mu.Unlock()
-
-	var epl []*Endpoint
-	for _, ep := range nw.localEps {
-		epl = append(epl, ep)
-	}
-
-	return epl
-}
-
 func (c *Controller) watchSvcRecord(ep *Endpoint) {
 func (c *Controller) watchSvcRecord(ep *Endpoint) {
 	c.watchCh <- ep
 	c.watchCh <- ep
 }
 }
@@ -231,7 +219,7 @@ func (c *Controller) processEndpointCreate(ep *Endpoint) {
 
 
 	if ok {
 	if ok {
 		// Update the svc db for the local endpoint join right away
 		// Update the svc db for the local endpoint join right away
-		n.updateSvcRecord(ep, c.getLocalEps(nw), true)
+		n.updateSvcRecord(ep, true)
 
 
 		c.mu.Lock()
 		c.mu.Lock()
 		nw.localEps[endpointID] = ep
 		nw.localEps[endpointID] = ep
@@ -252,7 +240,7 @@ func (c *Controller) processEndpointCreate(ep *Endpoint) {
 	// Update the svc db for the local endpoint join right away
 	// Update the svc db for the local endpoint join right away
 	// Do this before adding this ep to localEps so that we don't
 	// Do this before adding this ep to localEps so that we don't
 	// try to update this ep's container's svc records
 	// try to update this ep's container's svc records
-	n.updateSvcRecord(ep, c.getLocalEps(nw), true)
+	n.updateSvcRecord(ep, true)
 
 
 	c.mu.Lock()
 	c.mu.Lock()
 	nw.localEps[endpointID] = ep
 	nw.localEps[endpointID] = ep
@@ -277,7 +265,7 @@ func (c *Controller) processEndpointDelete(ep *Endpoint) {
 		// Update the svc db about local endpoint leave right away
 		// Update the svc db about local endpoint leave right away
 		// Do this after we remove this ep from localEps so that we
 		// Do this after we remove this ep from localEps so that we
 		// don't try to remove this svc record from this ep's container.
 		// don't try to remove this svc record from this ep's container.
-		n.updateSvcRecord(ep, c.getLocalEps(nw), false)
+		n.updateSvcRecord(ep, false)
 
 
 		c.mu.Lock()
 		c.mu.Lock()
 		if len(nw.localEps) == 0 {
 		if len(nw.localEps) == 0 {