merge object lifecycle checks into usage crawler (#9579)

This commit is contained in:
Klaus Post
2020-06-12 10:28:21 -07:00
committed by GitHub
parent 225b812b5e
commit 43d6e3ae06
18 changed files with 1400 additions and 852 deletions
+21 -12
View File
@@ -18,6 +18,7 @@ package cmd
import (
"bufio"
"bytes"
"context"
"crypto/rand"
"encoding/hex"
@@ -35,8 +36,6 @@ import (
"syscall"
"time"
"bytes"
humanize "github.com/dustin/go-humanize"
jsoniter "github.com/json-iterator/go"
"github.com/klauspost/readahead"
@@ -366,7 +365,18 @@ func (s *posix) waitForLowActiveIO() {
}
func (s *posix) CrawlAndGetDataUsage(ctx context.Context, cache dataUsageCache) (dataUsageCache, error) {
dataUsageInfo, err := updateUsage(ctx, s.diskPath, cache, s.waitForLowActiveIO, func(item Item) (int64, error) {
// Check if the current bucket has a configured lifecycle policy
lc, err := globalLifecycleSys.Get(cache.Info.Name)
if err == nil && lc.HasActiveRules("", true) {
cache.Info.lifeCycle = lc
}
// Get object api
objAPI := newObjectLayerWithoutSafeModeFn()
if objAPI == nil {
return cache, errors.New("object layer not initialized")
}
dataUsageInfo, err := crawlDataFolder(ctx, s.diskPath, cache, s.waitForLowActiveIO, func(item crawlItem) (int64, error) {
// Look for `xl.json' at the leaf.
if !strings.HasSuffix(item.Path, SlashSeparator+xlMetaJSONFile) {
// if no xl.json found, skip the file.
@@ -379,23 +389,22 @@ func (s *posix) CrawlAndGetDataUsage(ctx context.Context, cache dataUsageCache)
}
meta, err := xlMetaV1UnmarshalJSON(ctx, xlMetaBuf)
if err != nil {
return 0, nil
}
// we don't necessarily care about the names
// of bucket and object, only interested in size.
// so use some dummy names.
size, err := meta.ToObjectInfo("dummy", "dummy").GetActualSize()
if err != nil {
return 0, errSkipFile
}
return size, nil
// Remove filename which is the meta file.
item.transformMetaDir()
return item.applyActions(ctx, objAPI,
actionMeta{oi: meta.ToObjectInfo(item.bucket, item.objectPath()),
meta: meta.Meta,
}), nil
})
if err != nil {
return dataUsageInfo, err
}
dataUsageInfo.Info.LastUpdate = time.Now()
total := dataUsageInfo.sizeRecursive(dataUsageInfo.Info.Name)
if total == nil {