From 0fb70328dc7f2452ba3fd1f49a1b951a19bd3b3b Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Mon, 12 Dec 2016 15:34:26 -0800 Subject: [PATCH] router: Minimize reloads for removal and filtering This change ensures that stateChanged is only set to true for endpoint and route removal and namespace filtering if state was changed. --- pkg/router/template/router.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/router/template/router.go b/pkg/router/template/router.go index 5c6beaa45cad..2c0baee1acb1 100644 --- a/pkg/router/template/router.go +++ b/pkg/router/template/router.go @@ -461,11 +461,10 @@ func (r *templateRouter) FilterNamespaces(namespaces sets.String) { r.lock.Lock() defer r.lock.Unlock() - r.stateChanged = true - if len(namespaces) == 0 { r.state = make(map[string]ServiceAliasConfig) r.serviceUnits = make(map[string]ServiceUnit) + r.stateChanged = true } for k := range r.serviceUnits { // TODO: the id of a service unit should be defined inside this class, not passed in from the outside @@ -475,6 +474,7 @@ func (r *templateRouter) FilterNamespaces(namespaces sets.String) { continue } delete(r.serviceUnits, k) + r.stateChanged = true } for k := range r.state { @@ -483,6 +483,7 @@ func (r *templateRouter) FilterNamespaces(namespaces sets.String) { continue } delete(r.state, k) + r.stateChanged = true } } @@ -534,8 +535,6 @@ func (r *templateRouter) DeleteEndpoints(id string) { r.lock.Lock() defer r.lock.Unlock() - r.stateChanged = true - service, ok := r.findMatchingServiceUnit(id) if !ok { return @@ -551,6 +550,8 @@ func (r *templateRouter) DeleteEndpoints(id string) { r.peerEndpoints = []Endpoint{} glog.V(4).Infof("Peer endpoint table has been cleared") } + + r.stateChanged = true } // routeKey generates route key in form of Namespace_Name. This is NOT the normal key structure of ns/name because @@ -658,8 +659,6 @@ func (r *templateRouter) RemoveRoute(route *routeapi.Route) { r.lock.Lock() defer r.lock.Unlock() - r.stateChanged = true - routeKey := r.routeKey(route) serviceAliasConfig, ok := r.state[routeKey] if !ok { @@ -668,6 +667,7 @@ func (r *templateRouter) RemoveRoute(route *routeapi.Route) { r.cleanUpServiceAliasConfig(&serviceAliasConfig) delete(r.state, routeKey) + r.stateChanged = true } // AddEndpoints adds new Endpoints for the given id.