randomize same-dc servers and other-dc servers
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/chrislusf/seaweedfs/weed/wdclient"
|
"github.com/chrislusf/seaweedfs/weed/wdclient"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -143,9 +142,6 @@ func retriedStreamFetchChunkData(writer io.Writer, urlStrings []string, cipherKe
|
|||||||
var shouldRetry bool
|
var shouldRetry bool
|
||||||
var totalWritten int
|
var totalWritten int
|
||||||
|
|
||||||
rand.Shuffle(len(urlStrings), func(i, j int) {
|
|
||||||
urlStrings[i], urlStrings[j] = urlStrings[j], urlStrings[i]
|
|
||||||
})
|
|
||||||
for waitTime := time.Second; waitTime < util.RetryWaitTime; waitTime += waitTime / 2 {
|
for waitTime := time.Second; waitTime < util.RetryWaitTime; waitTime += waitTime / 2 {
|
||||||
for _, urlString := range urlStrings {
|
for _, urlString := range urlStrings {
|
||||||
var localProcesed int
|
var localProcesed int
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||||
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -69,13 +70,21 @@ func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrls []string, err er
|
|||||||
if !found {
|
if !found {
|
||||||
return nil, fmt.Errorf("volume %d not found", id)
|
return nil, fmt.Errorf("volume %d not found", id)
|
||||||
}
|
}
|
||||||
|
var sameDcServers, otherDcServers []string
|
||||||
for _, loc := range locations {
|
for _, loc := range locations {
|
||||||
if vc.DataCenter == "" || loc.DataCenter == "" || vc.DataCenter != loc.DataCenter {
|
if vc.DataCenter == "" || loc.DataCenter == "" || vc.DataCenter != loc.DataCenter {
|
||||||
serverUrls = append(serverUrls, loc.Url)
|
sameDcServers = append(sameDcServers, loc.Url)
|
||||||
} else {
|
} else {
|
||||||
serverUrls = append([]string{loc.Url}, serverUrls...)
|
otherDcServers = append(otherDcServers, loc.Url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rand.Shuffle(len(sameDcServers), func(i, j int) {
|
||||||
|
sameDcServers[i], sameDcServers[j] = sameDcServers[j], sameDcServers[i]
|
||||||
|
})
|
||||||
|
rand.Shuffle(len(otherDcServers), func(i, j int) {
|
||||||
|
otherDcServers[i], otherDcServers[j] = otherDcServers[j], otherDcServers[i]
|
||||||
|
})
|
||||||
|
serverUrls = append(sameDcServers, otherDcServers...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user