mirror of
https://github.com/minio/minio.git
synced 2025-03-03 07:10:07 -05:00
ilm: More compliance to spec related to expired delete markers (#12887)
<Days> tag can remove expired delete markers according to AWS S3 spec. <NoncurrentVersionExpiration> cannot remove expired delete markers in anyway.
This commit is contained in:
parent
3863a96bdf
commit
37bef900fd
@ -287,12 +287,23 @@ func (lc Lifecycle) ComputeAction(obj ObjectOpts) Action {
|
|||||||
return action
|
return action
|
||||||
}
|
}
|
||||||
for _, rule := range lc.FilterActionableRules(obj) {
|
for _, rule := range lc.FilterActionableRules(obj) {
|
||||||
if obj.ExpiredObjectDeleteMarker() && rule.Expiration.DeleteMarker.val {
|
if obj.ExpiredObjectDeleteMarker() {
|
||||||
// Indicates whether MinIO will remove a delete marker with no noncurrent versions.
|
if rule.Expiration.DeleteMarker.val {
|
||||||
// Only latest marker is removed. If set to true, the delete marker will be expired;
|
// Indicates whether MinIO will remove a delete marker with no noncurrent versions.
|
||||||
// if set to false the policy takes no action. This cannot be specified with Days or
|
// Only latest marker is removed. If set to true, the delete marker will be expired;
|
||||||
// Date in a Lifecycle Expiration Policy.
|
// if set to false the policy takes no action. This cannot be specified with Days or
|
||||||
return DeleteVersionAction
|
// Date in a Lifecycle Expiration Policy.
|
||||||
|
return DeleteVersionAction
|
||||||
|
}
|
||||||
|
|
||||||
|
if !rule.Expiration.IsDaysNull() {
|
||||||
|
// Specifying the Days tag will automatically perform ExpiredObjectDeleteMarker cleanup
|
||||||
|
// once delete markers are old enough to satisfy the age criteria.
|
||||||
|
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-configuration-examples.html
|
||||||
|
if time.Now().After(ExpectedExpiryTime(obj.ModTime, int(rule.Expiration.Days))) {
|
||||||
|
return DeleteVersionAction
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !rule.NoncurrentVersionExpiration.IsDaysNull() {
|
if !rule.NoncurrentVersionExpiration.IsDaysNull() {
|
||||||
@ -303,17 +314,6 @@ func (lc Lifecycle) ComputeAction(obj ObjectOpts) Action {
|
|||||||
return DeleteVersionAction
|
return DeleteVersionAction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.VersionID != "" && obj.ExpiredObjectDeleteMarker() {
|
|
||||||
// From https: //docs.aws.amazon.com/AmazonS3/latest/dev/lifecycle-configuration-examples.html :
|
|
||||||
// The NoncurrentVersionExpiration action in the same Lifecycle configuration removes noncurrent objects X days
|
|
||||||
// after they become noncurrent. Thus, in this example, all object versions are permanently removed X days after
|
|
||||||
// object creation. You will have expired object delete markers, but Amazon S3 detects and removes the expired
|
|
||||||
// object delete markers for you.
|
|
||||||
if time.Now().After(ExpectedExpiryTime(obj.ModTime, int(rule.NoncurrentVersionExpiration.NoncurrentDays))) {
|
|
||||||
return DeleteVersionAction
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !rule.NoncurrentVersionTransition.IsDaysNull() {
|
if !rule.NoncurrentVersionTransition.IsDaysNull() {
|
||||||
|
@ -210,11 +210,12 @@ func TestExpectedExpiryTime(t *testing.T) {
|
|||||||
|
|
||||||
func TestComputeActions(t *testing.T) {
|
func TestComputeActions(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
inputConfig string
|
inputConfig string
|
||||||
objectName string
|
objectName string
|
||||||
objectTags string
|
objectTags string
|
||||||
objectModTime time.Time
|
objectModTime time.Time
|
||||||
expectedAction Action
|
isExpiredDelMarker bool
|
||||||
|
expectedAction Action
|
||||||
}{
|
}{
|
||||||
// Empty object name (unexpected case) should always return NoneAction
|
// Empty object name (unexpected case) should always return NoneAction
|
||||||
{
|
{
|
||||||
@ -355,6 +356,30 @@ func TestComputeActions(t *testing.T) {
|
|||||||
objectModTime: time.Now().UTC().Add(-24 * time.Hour), // Created 1 day ago
|
objectModTime: time.Now().UTC().Add(-24 * time.Hour), // Created 1 day ago
|
||||||
expectedAction: DeleteAction,
|
expectedAction: DeleteAction,
|
||||||
},
|
},
|
||||||
|
// Should delete expired delete marker right away
|
||||||
|
{
|
||||||
|
inputConfig: `<BucketLifecycleConfiguration><Rule><Expiration><ExpiredObjectDeleteMarker>true</ExpiredObjectDeleteMarker></Expiration><Filter></Filter><Status>Enabled</Status></Rule></BucketLifecycleConfiguration>`,
|
||||||
|
objectName: "foodir/fooobject",
|
||||||
|
objectModTime: time.Now().UTC().Add(-1 * time.Hour), // Created one hour ago
|
||||||
|
isExpiredDelMarker: true,
|
||||||
|
expectedAction: DeleteVersionAction,
|
||||||
|
},
|
||||||
|
// Should not delete expired marker if its time has not come yet
|
||||||
|
{
|
||||||
|
inputConfig: `<BucketLifecycleConfiguration><Rule><Filter></Filter><Status>Enabled</Status><Expiration><Days>1</Days></Expiration></Rule></BucketLifecycleConfiguration>`,
|
||||||
|
objectName: "foodir/fooobject",
|
||||||
|
objectModTime: time.Now().UTC().Add(-12 * time.Hour), // Created 12 hours ago
|
||||||
|
isExpiredDelMarker: true,
|
||||||
|
expectedAction: NoneAction,
|
||||||
|
},
|
||||||
|
// Should delete expired marker since its time has come
|
||||||
|
{
|
||||||
|
inputConfig: `<BucketLifecycleConfiguration><Rule><Filter></Filter><Status>Enabled</Status><Expiration><Days>1</Days></Expiration></Rule></BucketLifecycleConfiguration>`,
|
||||||
|
objectName: "foodir/fooobject",
|
||||||
|
objectModTime: time.Now().UTC().Add(-10 * 24 * time.Hour), // Created 10 days ago
|
||||||
|
isExpiredDelMarker: true,
|
||||||
|
expectedAction: DeleteVersionAction,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
@ -365,10 +390,12 @@ func TestComputeActions(t *testing.T) {
|
|||||||
t.Fatalf("Got unexpected error: %v", err)
|
t.Fatalf("Got unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if resultAction := lc.ComputeAction(ObjectOpts{
|
if resultAction := lc.ComputeAction(ObjectOpts{
|
||||||
Name: tc.objectName,
|
Name: tc.objectName,
|
||||||
UserTags: tc.objectTags,
|
UserTags: tc.objectTags,
|
||||||
ModTime: tc.objectModTime,
|
ModTime: tc.objectModTime,
|
||||||
IsLatest: true,
|
DeleteMarker: tc.isExpiredDelMarker,
|
||||||
|
NumVersions: 1,
|
||||||
|
IsLatest: true,
|
||||||
}); resultAction != tc.expectedAction {
|
}); resultAction != tc.expectedAction {
|
||||||
t.Fatalf("Expected action: `%v`, got: `%v`", tc.expectedAction, resultAction)
|
t.Fatalf("Expected action: `%v`, got: `%v`", tc.expectedAction, resultAction)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user