mirror of
https://github.com/minio/minio.git
synced 2025-01-25 21:53:16 -05:00
XL: ListDir should return each List from a random disk in the set. (#1613)
Fixes #1609
This commit is contained in:
parent
8099396ff0
commit
0e4e9c4bc1
@ -18,6 +18,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
slashpath "path"
|
slashpath "path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -479,24 +480,32 @@ func (xl XL) ListDir(volume, dirPath string) (entries []string, err error) {
|
|||||||
if !isValidVolname(volume) {
|
if !isValidVolname(volume) {
|
||||||
return nil, errInvalidArgument
|
return nil, errInvalidArgument
|
||||||
}
|
}
|
||||||
// FIXME: need someway to figure out which disk has the latest namespace
|
|
||||||
// so that Listing can be done there. One option is always do Listing from
|
|
||||||
// the "local" disk - if it is down user has to list using another XL server.
|
|
||||||
// This way user knows from which disk he is listing from.
|
|
||||||
|
|
||||||
for _, disk := range xl.storageDisks {
|
// Count for list errors encountered.
|
||||||
if entries, err = disk.ListDir(volume, dirPath); err != nil {
|
var listErrCount = 0
|
||||||
continue
|
|
||||||
}
|
// Loop through and return the first success entry based on the
|
||||||
|
// selected random disk.
|
||||||
|
for listErrCount < len(xl.storageDisks) {
|
||||||
|
// Choose a random disk on each attempt, do not hit the same disk all the time.
|
||||||
|
randIndex := rand.Intn(len(xl.storageDisks) - 1)
|
||||||
|
disk := xl.storageDisks[randIndex] // Pick a random disk.
|
||||||
|
// Initiate a list operation, if successful filter and return quickly.
|
||||||
|
if entries, err = disk.ListDir(volume, dirPath); err == nil {
|
||||||
for i, entry := range entries {
|
for i, entry := range entries {
|
||||||
if strings.HasSuffix(entry, slashSeparator) && isLeafDirectoryXL(disk, volume, path.Join(dirPath, entry)) {
|
isLeaf := isLeafDirectoryXL(disk, volume, path.Join(dirPath, entry))
|
||||||
|
isDir := strings.HasSuffix(entry, slashSeparator)
|
||||||
|
if isDir && isLeaf {
|
||||||
entries[i] = strings.TrimSuffix(entry, slashSeparator)
|
entries[i] = strings.TrimSuffix(entry, slashSeparator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// We have list from one of the disks hence break the loop.
|
// We got the entries successfully return.
|
||||||
break
|
return entries, nil
|
||||||
}
|
}
|
||||||
return
|
listErrCount++ // Update list error count.
|
||||||
|
}
|
||||||
|
// Return error at the end.
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object API.
|
// Object API.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user