xl: Fix feeding NumVersions & SuccessorModTime to lifecycle (#11462)

After recent refactor where lifecycle started to rely on ObjectInfo to
make decisions, it turned out there are some issues calculating
Successor Modtime and NumVersions, hence the lifecycle is not working as
expected in a versioning bucket in some cases.

This commit fixes the behavior.
master
Anis Elleuch 4 years ago committed by GitHub
parent c9b0f595b9
commit 1887c25279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      cmd/xl-storage-format-v2.go

@ -611,12 +611,13 @@ func (z xlMetaV2) TotalSize() int64 {
// versions returns error for unexpected entries.
// showPendingDeletes is set to true if ListVersions needs to list objects marked deleted
// but waiting to be replicated
func (z xlMetaV2) ListVersions(volume, path string) (versions []FileInfo, modTime time.Time, err error) {
var latestModTime time.Time
var latestVersionID string
func (z xlMetaV2) ListVersions(volume, path string) ([]FileInfo, time.Time, error) {
var versions []FileInfo
var err error
for _, version := range z.Versions {
if !version.Valid() {
return nil, latestModTime, errFileCorrupt
return nil, time.Time{}, errFileCorrupt
}
var fi FileInfo
switch version.Type {
@ -628,27 +629,22 @@ func (z xlMetaV2) ListVersions(volume, path string) (versions []FileInfo, modTim
fi, err = version.ObjectV1.ToFileInfo(volume, path)
}
if err != nil {
return nil, latestModTime, err
}
if fi.ModTime.After(latestModTime) {
latestModTime = fi.ModTime
latestVersionID = fi.VersionID
return nil, time.Time{}, err
}
versions = append(versions, fi)
}
// We didn't find the version in delete markers so latest version
// is indeed one of the actual version of the object with data.
sort.Sort(versionsSorter(versions))
for i := range versions {
if versions[i].VersionID != latestVersionID {
continue
versions[i].NumVersions = len(versions)
if i > 0 {
versions[i].SuccessorModTime = versions[i-1].ModTime
}
versions[i].IsLatest = true
break
}
sort.Sort(versionsSorter(versions))
return versions, latestModTime, nil
versions[0].IsLatest = true
return versions, versions[0].ModTime, nil
}
func getModTimeFromVersion(v xlMetaV2Version) time.Time {
@ -744,8 +740,8 @@ findVersion:
// A version is found, fill dynamic fields
fi.IsLatest = i == 0
fi.NumVersions = len(z.Versions)
if i < len(orderedVersions)-1 {
fi.SuccessorModTime = getModTimeFromVersion(orderedVersions[i+1])
if i > 0 {
fi.SuccessorModTime = getModTimeFromVersion(orderedVersions[i-1])
}
return fi, nil
}

Loading…
Cancel
Save