Skip to content

Commit

Permalink
router: Minimize reloads for removal and filtering
Browse files Browse the repository at this point in the history
This change ensures that stateChanged is only set to true for endpoint
and route removal and namespace filtering if state was changed.
  • Loading branch information
marun committed Dec 12, 2016
1 parent c4dfa3b commit c182913
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/router/template/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -475,6 +474,7 @@ func (r *templateRouter) FilterNamespaces(namespaces sets.String) {
continue
}
delete(r.serviceUnits, k)
r.stateChanged = true
}

for k := range r.state {
Expand All @@ -483,6 +483,7 @@ func (r *templateRouter) FilterNamespaces(namespaces sets.String) {
continue
}
delete(r.state, k)
r.stateChanged = true
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down

0 comments on commit c182913

Please sign in to comment.