forget: make oldest snapshot marker more strict

Now, a snapshot is only marked as oldest if it's the last in the list AND its values matches the last seen value for that bucket.

Also, updated the corresponding golden files for the tests.
This commit is contained in:
Srigovind Nayak 2024-09-07 15:00:21 +05:30
parent d656a50852
commit b69c6408a6
No known key found for this signature in database
GPG key ID: 3C4A72A34ABD4C43
5 changed files with 10 additions and 10 deletions

View file

@ -256,13 +256,13 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reason
if val != b.Last || nr == len(list)-1 { if val != b.Last || nr == len(list)-1 {
debug.Log("keep %v %v, bucker %v, val %v\n", cur.Time, cur.id.Str(), i, val) debug.Log("keep %v %v, bucker %v, val %v\n", cur.Time, cur.id.Str(), i, val)
keepSnap = true keepSnap = true
if val == b.Last && nr == len(list)-1 {
b.reason = fmt.Sprintf("oldest %v", b.reason)
}
buckets[i].Last = val buckets[i].Last = val
if buckets[i].Count > 0 { if buckets[i].Count > 0 {
buckets[i].Count-- buckets[i].Count--
} }
if nr == len(list)-1 {
b.reason = fmt.Sprintf("oldest %v", b.reason)
}
keepSnapReasons = append(keepSnapReasons, b.reason) keepSnapReasons = append(keepSnapReasons, b.reason)
} }
} }
@ -278,10 +278,10 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reason
if val != b.Last || nr == len(list)-1 { if val != b.Last || nr == len(list)-1 {
debug.Log("keep %v, time %v, ID %v, bucker %v, val %v %v\n", b.reason, cur.Time, cur.id.Str(), i, val, b.Last) debug.Log("keep %v, time %v, ID %v, bucker %v, val %v %v\n", b.reason, cur.Time, cur.id.Str(), i, val, b.Last)
keepSnap = true keepSnap = true
bucketsWithin[i].Last = val if val == b.Last && nr == len(list)-1 {
if nr == len(list)-1 {
b.reason = fmt.Sprintf("oldest %v", b.reason) b.reason = fmt.Sprintf("oldest %v", b.reason)
} }
bucketsWithin[i].Last = val
keepSnapReasons = append(keepSnapReasons, fmt.Sprintf("%v %v", b.reason, b.Within)) keepSnapReasons = append(keepSnapReasons, fmt.Sprintf("%v %v", b.reason, b.Within))
} }
} }

View file

@ -1978,7 +1978,7 @@
"paths": null "paths": null
}, },
"matches": [ "matches": [
"oldest last snapshot" "last snapshot"
], ],
"counters": { "counters": {
"last": -1 "last": -1

View file

@ -2169,8 +2169,8 @@
"paths": null "paths": null
}, },
"matches": [ "matches": [
"oldest last snapshot", "last snapshot",
"oldest hourly snapshot" "hourly snapshot"
], ],
"counters": { "counters": {
"last": -1, "last": -1,

View file

@ -1708,7 +1708,7 @@
"paths": null "paths": null
}, },
"matches": [ "matches": [
"oldest hourly snapshot" "hourly snapshot"
], ],
"counters": { "counters": {
"hourly": -1 "hourly": -1

View file

@ -1978,7 +1978,7 @@
"paths": null "paths": null
}, },
"matches": [ "matches": [
"oldest last snapshot" "last snapshot"
], ],
"counters": { "counters": {
"last": 97 "last": 97