clean up member contacting
All checks were successful
Gitea/etcdmtr/pipeline/head This commit looks good
All checks were successful
Gitea/etcdmtr/pipeline/head This commit looks good
This commit is contained in:
parent
fa89dae820
commit
ab85083700
@ -140,18 +140,30 @@ func main() {
|
||||
fmt.Printf("found member list of: %d\n", numMembers)
|
||||
|
||||
for _, member := range members.Members {
|
||||
c2, err := client.GetEtcdWithEndpoints([]string{member.ClientURLs[0]})
|
||||
endpoint := member.ClientURLs[0]
|
||||
log.Printf("trying to reach %s", endpoint)
|
||||
|
||||
contextCtx, _ := context.WithTimeout(context.TODO(), operationTimeout)
|
||||
|
||||
is_leader, err := contactMember(contextCtx, client, endpoint)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Printf("couldn't reach member %s: %s", endpoint, err)
|
||||
continue
|
||||
}
|
||||
defer c2.Close()
|
||||
|
||||
status, err := c2.Status(ctx, member.ClientURLs[0])
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
log.Printf("reached member %s - is leader? %v", member.ClientURLs[0], status.Leader == status.Header.MemberId)
|
||||
log.Printf("reached member %s - is leader? %v", endpoint, is_leader)
|
||||
}
|
||||
}
|
||||
|
||||
func contactMember(ctx context.Context, client *Client, endpoint string) (bool, error) {
|
||||
etcd, err := client.GetEtcdWithEndpoints([]string{endpoint})
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("couldn't get client: %s", err)
|
||||
}
|
||||
defer etcd.Close()
|
||||
|
||||
status, err := etcd.Status(ctx, endpoint)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("couldn't reach member: %s", err)
|
||||
}
|
||||
return status.Leader == status.Header.MemberId, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user