-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ilm: Handle DeleteAllVersions action differently for DEL markers (#19481
) i.e., this rule element doesn't apply to DEL markers. This is a breaking change to how ExpiredObejctDeleteAllVersions functions today. This is necessary to avoid the following highly probable footgun scenario in the future. Scenario: The user uses tags-based filtering to select an object's time to live(TTL). The application sometimes deletes objects, too, making its latest version a DEL marker. The previous implementation skipped tag-based filters if the newest version was DEL marker, voiding the tag-based TTL. The user is surprised to find objects that have expired sooner than expected. * Add DelMarkerExpiration action This ILM action removes all versions of an object if its the latest version is a DEL marker. ```xml <DelMarkerObjectExpiration> <Days> 10 </Days> </DelMarkerObjectExpiration> ``` 1. Applies only to objects whose, • The latest version is a DEL marker. • satisfies the number of days criteria 2. Deletes all versions of this object 3. Associated rule can't have tag-based filtering Includes, - New bucket event type for deletion due to DelMarkerExpiration
- Loading branch information
Showing
11 changed files
with
471 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) 2024 MinIO, Inc. | ||
// | ||
// This file is part of MinIO Object Storage stack | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package lifecycle | ||
|
||
import ( | ||
"encoding/xml" | ||
"time" | ||
) | ||
|
||
var errInvalidDaysDelMarkerExpiration = Errorf("Days must be a positive integer with DelMarkerExpiration") | ||
|
||
// DelMarkerExpiration used to xml encode/decode ILM action by the same name | ||
type DelMarkerExpiration struct { | ||
XMLName xml.Name `xml:"DelMarkerExpiration"` | ||
Days int `xml:"Days,omitempty"` | ||
} | ||
|
||
// Empty returns if a DelMarkerExpiration XML element is empty. | ||
// Used to detect if lifecycle.Rule contained a DelMarkerExpiration element. | ||
func (de DelMarkerExpiration) Empty() bool { | ||
return de.Days == 0 | ||
} | ||
|
||
// UnmarshalXML decodes a single XML element into a DelMarkerExpiration value | ||
func (de *DelMarkerExpiration) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error { | ||
type delMarkerExpiration DelMarkerExpiration | ||
var dexp delMarkerExpiration | ||
err := dec.DecodeElement(&dexp, &start) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if dexp.Days <= 0 { | ||
return errInvalidDaysDelMarkerExpiration | ||
} | ||
|
||
*de = DelMarkerExpiration(dexp) | ||
return nil | ||
} | ||
|
||
// MarshalXML encodes a DelMarkerExpiration value into an XML element | ||
func (de DelMarkerExpiration) MarshalXML(enc *xml.Encoder, start xml.StartElement) error { | ||
if de.Empty() { | ||
return nil | ||
} | ||
|
||
type delMarkerExpiration DelMarkerExpiration | ||
return enc.EncodeElement(delMarkerExpiration(de), start) | ||
} | ||
|
||
// NextDue returns upcoming DelMarkerExpiration date for obj if | ||
// applicable, returns false otherwise. | ||
func (de DelMarkerExpiration) NextDue(obj ObjectOpts) (time.Time, bool) { | ||
if !obj.IsLatest || !obj.DeleteMarker { | ||
return time.Time{}, false | ||
} | ||
|
||
return ExpectedExpiryTime(obj.ModTime, de.Days), true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2024 MinIO, Inc. | ||
// | ||
// This file is part of MinIO Object Storage stack | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package lifecycle | ||
|
||
import ( | ||
"encoding/xml" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestDelMarkerExpParseAndValidate(t *testing.T) { | ||
tests := []struct { | ||
xml string | ||
err error | ||
}{ | ||
{ | ||
xml: `<DelMarkerExpiration> <Days> 1 </Days> </DelMarkerExpiration>`, | ||
err: nil, | ||
}, | ||
{ | ||
xml: `<DelMarkerExpiration> <Days> -1 </Days> </DelMarkerExpiration>`, | ||
err: errInvalidDaysDelMarkerExpiration, | ||
}, | ||
} | ||
|
||
for i, test := range tests { | ||
t.Run(fmt.Sprintf("TestDelMarker-%d", i), func(t *testing.T) { | ||
var dexp DelMarkerExpiration | ||
var fail bool | ||
err := xml.Unmarshal([]byte(test.xml), &dexp) | ||
if test.err == nil { | ||
if err != nil { | ||
fail = true | ||
} | ||
} else { | ||
if err == nil { | ||
fail = true | ||
} | ||
if test.err.Error() != err.Error() { | ||
fail = true | ||
} | ||
} | ||
if fail { | ||
t.Fatalf("Expected %v but got %v", test.err, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.