pruning: cleanup retention grid impl + tests + correct docs
package is now at 95% code coverage and the additional tests codify
all behavior specified in the docs
There is a slight change in behavior:
Intervals are now [duration) instead of (duration].
If the leftmost interval is not keep=all, the most recently created
snapshot will be destroyed if there are other snapshots within
that first interval.
Since we recommend keep=all all over the docs, and zrepl 0.3
will put holds on that snapshot if it is being replicated,
I feel like this is an acceptable change in behavior.
refs #292
fixup of 0bbe2befce
This commit is contained in:
+7
-24
@@ -3,7 +3,6 @@ package pruning
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -88,14 +87,6 @@ func newKeepGrid(re *regexp.Regexp, configIntervals []config.RetentionInterval)
|
||||
}, nil
|
||||
}
|
||||
|
||||
type retentionGridAdaptor struct {
|
||||
Snapshot
|
||||
}
|
||||
|
||||
func (a retentionGridAdaptor) LessThan(b retentiongrid.Entry) bool {
|
||||
return a.Date().Before(b.Date())
|
||||
}
|
||||
|
||||
// Prune filters snapshots with the retention grid.
|
||||
func (p *KeepGrid) KeepRule(snaps []Snapshot) (destroyList []Snapshot) {
|
||||
|
||||
@@ -110,24 +101,16 @@ func (p *KeepGrid) KeepRule(snaps []Snapshot) (destroyList []Snapshot) {
|
||||
return destroyList
|
||||
}
|
||||
|
||||
// Build adaptors for retention grid
|
||||
adaptors := make([]retentiongrid.Entry, 0)
|
||||
for i := range matching {
|
||||
adaptors = append(adaptors, retentionGridAdaptor{matching[i]})
|
||||
}
|
||||
|
||||
// determine 'now' edge
|
||||
sort.SliceStable(adaptors, func(i, j int) bool {
|
||||
return adaptors[i].LessThan(adaptors[j])
|
||||
})
|
||||
now := adaptors[len(adaptors)-1].Date()
|
||||
|
||||
// Evaluate retention grid
|
||||
_, removea := p.retentionGrid.FitEntries(now, adaptors)
|
||||
entrySlice := make([]retentiongrid.Entry, 0)
|
||||
for i := range matching {
|
||||
entrySlice = append(entrySlice, matching[i])
|
||||
}
|
||||
_, gridDestroyList := p.retentionGrid.FitEntries(entrySlice)
|
||||
|
||||
// Revert adaptors
|
||||
for i := range removea {
|
||||
destroyList = append(destroyList, removea[i].(retentionGridAdaptor).Snapshot)
|
||||
for i := range gridDestroyList {
|
||||
destroyList = append(destroyList, gridDestroyList[i].(Snapshot))
|
||||
}
|
||||
return destroyList
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user