Skip to content

Commit

Permalink
Walk the DCs from nearest to most remote.
Browse files Browse the repository at this point in the history
  • Loading branch information
sean- committed Jun 11, 2016
1 parent 8d0b798 commit 006d1a3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 006d1a3

Please sign in to comment.