data-usage: Avoid crawling duplicated call (#8843)

This fix will also picks 3 and not 4 disks from a single erasure set.
master
Anis Elleuch 5 years ago committed by kannappanr
parent 2bb69033e5
commit 017067e11f
  1. 3
      cmd/data-usage.go
  2. 8
      cmd/storage-rest-server.go
  3. 6
      cmd/xl-v1.go

@ -88,7 +88,8 @@ func runDataUsageInfoForXLZones(ctx context.Context, z *xlZones, endCh <-chan st
time.Sleep(5 * time.Minute) time.Sleep(5 * time.Minute)
continue continue
} }
// Break without locking // Break without unlocking, this node will acquire
// data usage calculator role for its lifetime.
break break
} }

@ -119,15 +119,9 @@ func (s *storageRESTServer) CrawlAndGetDataUsageHandler(w http.ResponseWriter, r
return return
} }
usageInfo, err := s.storage.CrawlAndGetDataUsage(GlobalServiceDoneCh)
if err != nil {
s.writeErrorResponse(w, err)
return
}
w.Header().Set(xhttp.ContentType, "text/event-stream") w.Header().Set(xhttp.ContentType, "text/event-stream")
doneCh := sendWhiteSpaceToHTTPResponse(w) doneCh := sendWhiteSpaceToHTTPResponse(w)
usageInfo, err = s.storage.CrawlAndGetDataUsage(GlobalServiceDoneCh) usageInfo, err := s.storage.CrawlAndGetDataUsage(GlobalServiceDoneCh)
<-doneCh <-doneCh
if err != nil { if err != nil {

@ -198,16 +198,18 @@ func (xl xlObjects) GetMetrics(ctx context.Context) (*Metrics, error) {
return &Metrics{}, NotImplemented{} return &Metrics{}, NotImplemented{}
} }
// crawlAndGetDataUsage picks three random disks to crawl and get data usage
func (xl xlObjects) crawlAndGetDataUsage(ctx context.Context, endCh <-chan struct{}) DataUsageInfo { func (xl xlObjects) crawlAndGetDataUsage(ctx context.Context, endCh <-chan struct{}) DataUsageInfo {
var randomDisks []StorageAPI var randomDisks []StorageAPI
for _, d := range xl.getLoadBalancedDisks() { for _, d := range xl.getLoadBalancedDisks() {
if d == nil || !d.IsOnline() { if d == nil || !d.IsOnline() {
continue continue
} }
if len(randomDisks) > 3 { randomDisks = append(randomDisks, d)
if len(randomDisks) >= 3 {
break break
} }
randomDisks = append(randomDisks, d)
} }
var dataUsageResults = make([]DataUsageInfo, len(randomDisks)) var dataUsageResults = make([]DataUsageInfo, len(randomDisks))

Loading…
Cancel
Save