mirror of
https://github.com/minio/minio.git
synced 2025-11-20 18:06:10 -05:00
fix: In federated setup dial all hosts to figure out online host (#10074)
In federated NAS gateway setups, multiple hosts in srvRecords was picked at random which could mean that if one of the host was down the request can indeed fail and if client retries it would succeed. Instead allow server to figure out the current online host quickly such that we can exclude the host which is down. At the max the attempt to look for a downed node is to 300 millisecond, if the node is taking longer to respond than this value we simply ignore and move to the node, total attempts are equal to number of srvRecords if no server is online we simply fallback to last dialed host.
This commit is contained in:
@@ -346,18 +346,36 @@ func isMinioReservedBucket(bucketName string) bool {
|
||||
|
||||
// returns a slice of hosts by reading a slice of DNS records
|
||||
func getHostsSlice(records []dns.SrvRecord) []string {
|
||||
var hosts []string
|
||||
for _, r := range records {
|
||||
hosts = append(hosts, net.JoinHostPort(r.Host, string(r.Port)))
|
||||
hosts := make([]string, len(records))
|
||||
for i, r := range records {
|
||||
hosts[i] = net.JoinHostPort(r.Host, string(r.Port))
|
||||
}
|
||||
return hosts
|
||||
}
|
||||
|
||||
// returns a host (and corresponding port) from a slice of DNS records
|
||||
func getHostFromSrv(records []dns.SrvRecord) string {
|
||||
rand.Seed(time.Now().Unix())
|
||||
srvRecord := records[rand.Intn(len(records))]
|
||||
return net.JoinHostPort(srvRecord.Host, string(srvRecord.Port))
|
||||
var rng = rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
|
||||
|
||||
// returns an online host (and corresponding port) from a slice of DNS records
|
||||
func getHostFromSrv(records []dns.SrvRecord) (host string) {
|
||||
hosts := getHostsSlice(records)
|
||||
|
||||
var d net.Dialer
|
||||
var retry int
|
||||
for retry < len(hosts) {
|
||||
ctx, cancel := context.WithTimeout(GlobalContext, 300*time.Millisecond)
|
||||
|
||||
host = hosts[rng.Intn(len(hosts))]
|
||||
conn, err := d.DialContext(ctx, "tcp", host)
|
||||
cancel()
|
||||
if err != nil {
|
||||
retry++
|
||||
continue
|
||||
}
|
||||
conn.Close()
|
||||
break
|
||||
}
|
||||
|
||||
return host
|
||||
}
|
||||
|
||||
// IsCompressed returns true if the object is marked as compressed.
|
||||
|
||||
Reference in New Issue
Block a user