Browse Source

Moves disable checks down into the sort routine.

pull/1331/head
James Phillips 9 years ago
parent
commit
78b2c2d7ac
  1. 14
      consul/catalog_endpoint.go
  2. 20
      consul/rtt.go

14
consul/catalog_endpoint.go

@ -105,12 +105,10 @@ func (c *Catalog) ListDatacenters(args *struct{}, reply *[]string) error {
dcs = append(dcs, dc)
}
// Sort the DCs
// Sort the DCs by name first, then apply a stable sort by distance.
sort.Strings(dcs)
if !c.srv.config.DisableCoordinates {
if err := c.srv.sortDatacentersByDistance(dcs); err != nil {
return err
}
if err := c.srv.sortDatacentersByDistance(dcs); err != nil {
return err
}
// Return
@ -137,9 +135,6 @@ func (c *Catalog) ListNodes(args *structs.DCSpecificRequest, reply *structs.Inde
}
reply.Index, reply.Nodes = index, nodes
if c.srv.config.DisableCoordinates {
return nil
}
return c.srv.sortNodesByDistanceFrom(args.Source, reply.Nodes)
})
}
@ -200,9 +195,6 @@ func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *stru
if err := c.srv.filterACL(args.Token, reply); err != nil {
return err
}
if c.srv.config.DisableCoordinates {
return nil
}
return c.srv.sortNodesByDistanceFrom(args.Source, reply.ServiceNodes)
})

20
consul/rtt.go

@ -113,8 +113,15 @@ func (s *Server) newSorterByDistanceFrom(c *coordinate.Coordinate, subj interfac
// sortNodesByDistanceFrom is used to sort results from our service catalog based
// on the round trip time from the given source node. Nodes with missing coordinates
// will get stable sorted at the end of the list.
//
// If coordinates are disabled this will be a no-op.
func (s *Server) sortNodesByDistanceFrom(source structs.QuerySource, subj interface{}) error {
// Make it safe to call this without having to check if coordinates are
// disabled first.
if s.config.DisableCoordinates {
return nil
}
// We can't compare coordinates across DCs.
if source.Datacenter != s.config.Datacenter {
return nil
@ -131,7 +138,7 @@ func (s *Server) sortNodesByDistanceFrom(source structs.QuerySource, subj interf
return nil
}
// Do the Dew!
// Do the sort!
sorter, err := s.newSorterByDistanceFrom(coord, subj)
if err != nil {
return err
@ -182,7 +189,16 @@ func (s *serverSerfer) GetNodesForDatacenter(dc string) []string {
// sortDatacentersByDistance will sort the given list of DCs based on the
// median RTT to all nodes we know about from the WAN gossip pool). DCs with
// missing coordinates will be stable sorted to the end of the list.
//
// If coordinates are disabled this will be a no-op.
func (s *Server) sortDatacentersByDistance(dcs []string) error {
// Make it safe to call this without having to check if coordinates are
// disabled first.
if s.config.DisableCoordinates {
return nil
}
// Do the sort!
serfer := serverSerfer{s}
return sortDatacentersByDistance(&serfer, dcs)
}

Loading…
Cancel
Save