Skip to content

Commit

Permalink
Try to fix proper route group cloing routing on routing rule removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Mar 2, 2020
1 parent 6242fac commit e3b54ff
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,22 @@ func (r *router) SaveRule(rule routing.Rule) error {

// DelRules removes rules associated with `ids` from the routing table.
func (r *router) DelRules(ids []routing.RouteID) {
rules := make([]routing.Rule, 0, len(ids))
for _, id := range ids {
rule, err := r.rt.Rule(id)
if err != nil {
r.logger.WithError(err).Errorf("Failed to get rule with ID %d on rule removal", id)
continue
}

rules = append(rules, rule)
}

r.rt.DelRules(ids)

for _, rule := range rules {
r.removeRule(rule)
}
}

func (r *router) rulesGCLoop() {
Expand All @@ -746,35 +761,39 @@ func (r *router) rulesGCLoop() {
func (r *router) rulesGC() {
removedRules := r.rt.CollectGarbage()

r.logger.Infof("Removed %d rules", len(removedRules))
r.logger.Infof("Removing %d rules", len(removedRules))

for _, rule := range removedRules {
r.logger.Infof("Removed rule of type %s", rule.Type())
// we need to process only consume rules, cause we don't
// really care about the other ones, other rules removal
// doesn't affect our work here
if rule.Type() == routing.RuleConsume {
cnsmRuleDesc := rule.RouteDescriptor()
r.logger.Infof("Removed consume rule with desc %s", &cnsmRuleDesc)

rg, ok := r.popRouteGroup(cnsmRuleDesc)
if !ok {
r.logger.Infoln("Couldn't remove route group after consume rule expired: route group not found")
continue
}
r.removeRule(rule)
}
}

func (r *router) removeRule(rule routing.Rule) {
r.logger.Infof("Removing rule of type %s with ID %d", rule.Type(), rule.KeyRouteID())
// we need to process only consume rules, cause we don't
// really care about the other ones, other rules removal
// doesn't affect our work here
if rule.Type() == routing.RuleConsume {
cnsmRuleDesc := rule.RouteDescriptor()
r.logger.Infof("Removed consume rule with desc %s", &cnsmRuleDesc)

rg, ok := r.popRouteGroup(cnsmRuleDesc)
if !ok {
r.logger.Infoln("Couldn't remove route group after consume rule expired: route group not found")
return
}

r.logger.Infoln("Removed route group for removed consume rule with desc %s", &cnsmRuleDesc)
r.logger.Infoln("Removed route group for removed consume rule with desc %s", &cnsmRuleDesc)

if !rg.isClosed() {
r.logger.Infoln("Closing route group")
if err := rg.Close(); err != nil {
r.logger.Errorf("Error closing route group during rule GC: %v", err)
} else {
r.logger.Infoln("Successfully closed route group")
}
if !rg.isClosed() {
r.logger.Infoln("Closing route group")
if err := rg.Close(); err != nil {
r.logger.Errorf("Error closing route group during rule GC: %v", err)
} else {
r.logger.Infoln("Route group is ALREADY closed")
r.logger.Infoln("Successfully closed route group")
}
} else {
r.logger.Infoln("Route group is ALREADY closed")
}
}
}

0 comments on commit e3b54ff

Please sign in to comment.