lifecycle: Expiry should not delete versions (#9972)

Currently, lifecycle expiry is deleting all object versions which is not
correct, unless noncurrent versions field is specified.

Also, only delete the delete marker if it is the only version of the
given object.
This commit is contained in:
Anis Elleuch
2020-07-05 04:56:02 +01:00
committed by GitHub
parent c087a05b43
commit d4af132fc4
3 changed files with 25 additions and 11 deletions

View File

@@ -40,6 +40,8 @@ const (
NoneAction Action = iota
// DeleteAction means the object needs to be removed after evaluting lifecycle rules
DeleteAction
// DeleteVersionAction deletes a particular version
DeleteVersionAction
)
// Lifecycle - Configuration for bucket lifecycle.
@@ -176,6 +178,7 @@ type ObjectOpts struct {
VersionID string
IsLatest bool
DeleteMarker bool
NumVersions int
}
// ComputeAction returns the action to perform by evaluating all lifecycle rules
@@ -187,27 +190,28 @@ func (lc Lifecycle) ComputeAction(obj ObjectOpts) Action {
}
for _, rule := range lc.FilterActionableRules(obj) {
if obj.DeleteMarker && obj.IsLatest && bool(rule.Expiration.DeleteMarker) {
if obj.DeleteMarker && obj.NumVersions == 1 && bool(rule.Expiration.DeleteMarker) {
// Indicates whether MinIO will remove a delete marker with no noncurrent versions.
// Only latest marker is removed. If set to true, the delete marker will be expired;
// if set to false the policy takes no action. This cannot be specified with Days or
// Date in a Lifecycle Expiration Policy.
return DeleteAction
return DeleteVersionAction
}
if !rule.NoncurrentVersionExpiration.IsDaysNull() {
if obj.VersionID != "" && !obj.IsLatest {
// Non current versions should be deleted.
if time.Now().After(expectedExpiryTime(obj.ModTime, rule.NoncurrentVersionExpiration.NoncurrentDays)) {
return DeleteAction
return DeleteVersionAction
}
return NoneAction
}
return NoneAction
}
// All other expiration only applies to latest versions.
if obj.IsLatest {
// All other expiration only applies to latest versions
// (except if this is a delete marker)
if obj.IsLatest && !obj.DeleteMarker {
switch {
case !rule.Expiration.IsDateNull():
if time.Now().UTC().After(rule.Expiration.Date.Time) {