xl: Fix counting offline disks in StorageInfo (#9082)

Recent modification in the code led to incorrect calculation
of offline disks.

This commit saves the endpoint list in a xlObjects then we know
the name of each disk.
master
kannappanr 5 years ago committed by GitHub
parent c7ca791c58
commit 07a7f329e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      cmd/xl-sets.go
  2. 28
      cmd/xl-v1.go

@ -302,10 +302,16 @@ func newXLSets(endpoints Endpoints, format *formatXLV3, setCount int, drivesPerS
s.xlDisks[i] = make([]StorageAPI, drivesPerSet) s.xlDisks[i] = make([]StorageAPI, drivesPerSet)
s.xlLockers[i] = make([]dsync.NetLocker, drivesPerSet) s.xlLockers[i] = make([]dsync.NetLocker, drivesPerSet)
var endpoints Endpoints
for j := 0; j < drivesPerSet; j++ {
endpoints = append(endpoints, s.endpoints[i*s.drivesPerSet+j])
}
// Initialize xl objects for a given set. // Initialize xl objects for a given set.
s.sets[i] = &xlObjects{ s.sets[i] = &xlObjects{
getDisks: s.GetDisks(i), getDisks: s.GetDisks(i),
getLockers: s.GetLockers(i), getLockers: s.GetLockers(i),
endpoints: endpoints,
nsMutex: mutex, nsMutex: mutex,
bp: bp, bp: bp,
mrfUploadCh: make(chan partialUpload, 10000), mrfUploadCh: make(chan partialUpload, 10000),

@ -53,6 +53,8 @@ type xlObjects struct {
// getLockers returns list of remote and local lockers. // getLockers returns list of remote and local lockers.
getLockers func() []dsync.NetLocker getLockers func() []dsync.NetLocker
endpoints Endpoints
// Locker mutex map. // Locker mutex map.
nsMutex *nsLockMap nsMutex *nsLockMap
@ -87,7 +89,7 @@ func (d byDiskTotal) Less(i, j int) bool {
} }
// getDisksInfo - fetch disks info across all other storage API. // getDisksInfo - fetch disks info across all other storage API.
func getDisksInfo(disks []StorageAPI) (disksInfo []DiskInfo, onlineDisks, offlineDisks madmin.BackendDisks) { func getDisksInfo(disks []StorageAPI, endpoints Endpoints) (disksInfo []DiskInfo, onlineDisks, offlineDisks madmin.BackendDisks) {
disksInfo = make([]DiskInfo, len(disks)) disksInfo = make([]DiskInfo, len(disks))
g := errgroup.WithNErrs(len(disks)) g := errgroup.WithNErrs(len(disks))
@ -115,24 +117,16 @@ func getDisksInfo(disks []StorageAPI) (disksInfo []DiskInfo, onlineDisks, offlin
onlineDisks = make(madmin.BackendDisks) onlineDisks = make(madmin.BackendDisks)
offlineDisks = make(madmin.BackendDisks) offlineDisks = make(madmin.BackendDisks)
localNodeAddr := GetLocalPeer(globalEndpoints)
// Wait for the routines. // Wait for the routines.
for i, diskInfoErr := range g.Wait() { for i, diskInfoErr := range g.Wait() {
if disks[i] == nil { peerAddr := endpoints[i].Host
continue
}
peerAddr := disks[i].Hostname()
if peerAddr == "" {
peerAddr = localNodeAddr
}
if _, ok := offlineDisks[peerAddr]; !ok { if _, ok := offlineDisks[peerAddr]; !ok {
offlineDisks[peerAddr] = 0 offlineDisks[peerAddr] = 0
} }
if _, ok := onlineDisks[peerAddr]; !ok { if _, ok := onlineDisks[peerAddr]; !ok {
onlineDisks[peerAddr] = 0 onlineDisks[peerAddr] = 0
} }
if diskInfoErr != nil { if disks[i] == nil || diskInfoErr != nil {
offlineDisks[peerAddr]++ offlineDisks[peerAddr]++
continue continue
} }
@ -144,8 +138,8 @@ func getDisksInfo(disks []StorageAPI) (disksInfo []DiskInfo, onlineDisks, offlin
} }
// Get an aggregated storage info across all disks. // Get an aggregated storage info across all disks.
func getStorageInfo(disks []StorageAPI) StorageInfo { func getStorageInfo(disks []StorageAPI, endpoints Endpoints) StorageInfo {
disksInfo, onlineDisks, offlineDisks := getDisksInfo(disks) disksInfo, onlineDisks, offlineDisks := getDisksInfo(disks, endpoints)
// Sort so that the first element is the smallest. // Sort so that the first element is the smallest.
sort.Sort(byDiskTotal(disksInfo)) sort.Sort(byDiskTotal(disksInfo))
@ -179,18 +173,20 @@ func getStorageInfo(disks []StorageAPI) StorageInfo {
// StorageInfo - returns underlying storage statistics. // StorageInfo - returns underlying storage statistics.
func (xl xlObjects) StorageInfo(ctx context.Context, local bool) StorageInfo { func (xl xlObjects) StorageInfo(ctx context.Context, local bool) StorageInfo {
var endpoints = xl.endpoints
var disks []StorageAPI var disks []StorageAPI
if !local { if !local {
disks = xl.getDisks() disks = xl.getDisks()
} else { } else {
for _, d := range xl.getDisks() { for i, d := range xl.getDisks() {
if d != nil && d.Hostname() == "" { if endpoints[i].IsLocal {
// Append this local disk since local flag is true // Append this local disk since local flag is true
disks = append(disks, d) disks = append(disks, d)
} }
} }
} }
return getStorageInfo(disks) return getStorageInfo(disks, endpoints)
} }
// GetMetrics - is not implemented and shouldn't be called. // GetMetrics - is not implemented and shouldn't be called.

Loading…
Cancel
Save