From 006d1a32905a32a4c1935f6371bd7b4226e9f71a Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Sat, 11 Jun 2016 18:52:21 -0400 Subject: [PATCH] Walk the DCs from nearest to most remote. --- client/client.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client/client.go b/client/client.go index bee92fda1..d0c477ad1 100644 --- a/client/client.go +++ b/client/client.go @@ -1291,6 +1291,21 @@ func (c *Client) setupConsulSyncer() error { if err != nil { return fmt.Errorf("client.consul: unable to query Consul datacenters: %v", err) } + if len(dcs) > 2 { + // Query the local DC first, then shuffle the + // remaining DCs. Future heartbeats will cause Nomad + // Clients to fixate on their local datacenter so + // it's okay to talk with remote DCs. If the no + // Nomad servers are available within + // datacenterQueryLimit, the next heartbeat will pick + // a new set of servers so it's okay. + nearestDC := dcs[0] + otherDCs := make([]string, 0, len(dcs)) + otherDCs = dcs[1:lib.MinInt(len(dcs), datacenterQueryLimit)] + shuffleStrings(otherDCs) + + dcs = append([]string{nearestDC}, otherDCs...) + } nomadServerServiceName := c.config.ConsulConfig.ServerServiceName var mErr multierror.Error