router/registry: fix bug which impacts service registered in multiple domains (#1925)
* router/registry: fix bug which impacts service registered in multiple domains * router/registry: bugfix
This commit is contained in:
parent
ed5729a842
commit
b2ebc36dda
13
registry.go
13
registry.go
@ -204,8 +204,11 @@ func (r *rtr) loadRoutes(reg registry.Registry) error {
|
|||||||
// if the routes exist save them
|
// if the routes exist save them
|
||||||
if len(routes) > 0 {
|
if len(routes) > 0 {
|
||||||
logger.Tracef("Creating routes for service %v domain: %v", service, domain)
|
logger.Tracef("Creating routes for service %v domain: %v", service, domain)
|
||||||
// save the routes without pumping out events
|
for _, rt := range routes {
|
||||||
r.table.saveRoutes(service.Name, routes)
|
if err := r.table.Create(rt); err != nil {
|
||||||
|
logger.Errorf("Error creating route for service %v in domain %v: %v", service, domain, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +227,11 @@ func (r *rtr) loadRoutes(reg registry.Registry) error {
|
|||||||
|
|
||||||
if len(routes) > 0 {
|
if len(routes) > 0 {
|
||||||
logger.Tracef("Creating routes for service %v domain: %v", srv, domain)
|
logger.Tracef("Creating routes for service %v domain: %v", srv, domain)
|
||||||
r.table.saveRoutes(srv.Name, routes)
|
for _, rt := range routes {
|
||||||
|
if err := r.table.Create(rt); err != nil {
|
||||||
|
logger.Errorf("Error creating route for service %v in domain %v: %v", service, domain, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
table.go
21
table.go
@ -89,23 +89,6 @@ func (t *table) deleteService(service, network string) {
|
|||||||
t.routes[service] = routes
|
t.routes[service] = routes
|
||||||
}
|
}
|
||||||
|
|
||||||
// saveRoutes completely replaces the routes for a service
|
|
||||||
func (t *table) saveRoutes(service string, routes []router.Route) {
|
|
||||||
t.Lock()
|
|
||||||
defer t.Unlock()
|
|
||||||
|
|
||||||
// delete old routes
|
|
||||||
delete(t.routes, service)
|
|
||||||
// make new map
|
|
||||||
t.routes[service] = make(map[uint64]*route)
|
|
||||||
|
|
||||||
// iterate through new routes and save
|
|
||||||
for _, rt := range routes {
|
|
||||||
// save the new route
|
|
||||||
t.routes[service][rt.Hash()] = &route{rt, time.Now()}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// sendEvent sends events to all subscribed watchers
|
// sendEvent sends events to all subscribed watchers
|
||||||
func (t *table) sendEvent(e *router.Event) {
|
func (t *table) sendEvent(e *router.Event) {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
@ -369,7 +352,9 @@ func (t *table) Query(q ...router.QueryOption) ([]router.Route, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cache the routes
|
// cache the routes
|
||||||
t.saveRoutes(opts.Service, routes)
|
for _, rt := range routes {
|
||||||
|
t.Create(rt)
|
||||||
|
}
|
||||||
|
|
||||||
// try again
|
// try again
|
||||||
if routes, ok := readAndFilter(opts); ok {
|
if routes, ok := readAndFilter(opts); ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user