mirror of https://github.com/status-im/consul.git
Adds a hook for the route lookup function.
This commit is contained in:
parent
fcbb615aa0
commit
f1acda4238
|
@ -33,6 +33,9 @@ type Router struct {
|
||||||
// managers for that datacenter. This is used to quickly lookup routes.
|
// managers for that datacenter. This is used to quickly lookup routes.
|
||||||
managers map[string][]*Manager
|
managers map[string][]*Manager
|
||||||
|
|
||||||
|
// routeFn is a hook to actually do the routing.
|
||||||
|
routeFn func(datacenter string) (*Manager, *agent.Server, bool)
|
||||||
|
|
||||||
// This top-level lock covers all the internal state.
|
// This top-level lock covers all the internal state.
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
@ -81,6 +84,9 @@ func NewRouter(logger *log.Logger, shutdownCh chan struct{}, localDatacenter str
|
||||||
managers: make(map[string][]*Manager),
|
managers: make(map[string][]*Manager),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hook the direct route lookup by default.
|
||||||
|
router.routeFn = router.findDirectRoute
|
||||||
|
|
||||||
// This will propagate a top-level shutdown to all the managers.
|
// This will propagate a top-level shutdown to all the managers.
|
||||||
go func() {
|
go func() {
|
||||||
<-shutdownCh
|
<-shutdownCh
|
||||||
|
@ -272,6 +278,12 @@ func (r *Router) FailServer(areaID types.AreaID, s *agent.Server) error {
|
||||||
// should feed that back to the manager associated with the server, which is
|
// should feed that back to the manager associated with the server, which is
|
||||||
// also returned, by calling NofifyFailedServer().
|
// also returned, by calling NofifyFailedServer().
|
||||||
func (r *Router) FindRoute(datacenter string) (*Manager, *agent.Server, bool) {
|
func (r *Router) FindRoute(datacenter string) (*Manager, *agent.Server, bool) {
|
||||||
|
return r.routeFn(datacenter)
|
||||||
|
}
|
||||||
|
|
||||||
|
// findDirectRoute looks for a route to the given datacenter if it's directly
|
||||||
|
// adjacent to the server.
|
||||||
|
func (r *Router) findDirectRoute(datacenter string) (*Manager, *agent.Server, bool) {
|
||||||
r.RLock()
|
r.RLock()
|
||||||
defer r.RUnlock()
|
defer r.RUnlock()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue