This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

client: Don't query unconnected machines for leader information

Before this commit, we queried all machines for leader information,
regardless of whether they had connected. If a machine is not connected,
it probably won't respond, so querying it only increases the amount of
time required for the function to return. This resulted in `kelda ps`
being extremely slow when a machine had not yet connected (which can
happen when the cluster is first booting, or if a machine crashes).

Sometimes, the error "context deadline exceeded" would be printed
because the Query call to the daemon would timeout since obtaining the
leader client took so long.
  • Loading branch information...
kklin committed Nov 21, 2017
1 parent d459f57 commit 9e667f9e9aceca27d3a608a729eb81a948b3080d
Showing with 36 additions and 1 deletion.
  1. +1 −1 api/client/leader.go
  2. +35 −0 api/client/leader_test.go
View
@@ -21,7 +21,7 @@ func Leader(machines []db.Machine, creds connection.Credentials) (Client, error)
// Try to figure out the lead minion's IP by asking each of the machines.
for _, m := range machines {
if m.PublicIP == "" || m.Status == db.Stopping {
if m.PublicIP == "" || m.Status != db.Connected {
continue
}
View
@@ -35,13 +35,20 @@ func TestLeader(t *testing.T) {
}
res, err := Leader([]db.Machine{
{
PublicIP: "7.7.7.7",
Status: db.Connecting,
},
{
PublicIP: "8.8.8.8",
Status: db.Connected,
},
{
PublicIP: "9.9.9.9",
Status: db.Connected,
},
{
Status: db.Connected,
PublicIP: "leader",
PrivateIP: "leader-priv",
},
@@ -62,9 +69,11 @@ func TestNoLeader(t *testing.T) {
_, err := Leader([]db.Machine{
{
Status: db.Connected,
PublicIP: "8.8.8.8",
},
{
Status: db.Connected,
PublicIP: "9.9.9.9",
},
}, nil)
@@ -77,3 +86,29 @@ func TestLeaderNoMachines(t *testing.T) {
_, err := Leader(nil, nil)
assert.EqualError(t, err, "no machines to query")
}
func TestNoConnectedMachines(t *testing.T) {
newClient = func(host string, _ connection.Credentials) (Client, error) {
t.Fatalf("Unexpected call to newClient with host %s. newClient should "+
"not be called since no machines have been connected to.", host)
return nil, nil
}
Leader([]db.Machine{
{
PublicIP: "7.7.7.7",
},
{
Status: db.Connecting,
PublicIP: "8.8.8.8",
},
{
PublicIP: "9.9.9.9",
Status: db.Reconnecting,
},
{
Status: db.Stopping,
PublicIP: "10.10.10.10",
},
}, nil)
}

0 comments on commit 9e667f9

Please sign in to comment.