pruning: implement 'grid' keep rule

This commit is contained in:
Christian Schwarz
2018-09-24 17:30:03 +02:00
parent 328ac687f6
commit 9e941d5be5
11 changed files with 138 additions and 190 deletions
+11 -11
View File
@@ -22,10 +22,10 @@ func (i *retentionIntervalStub) KeepCount() int {
return i.keepCount
}
func retentionGridFromString(gs string) (g *retentionGrid) {
func gridFromString(gs string) (g *Grid) {
intervals := strings.Split(gs, "|")
g = &retentionGrid{
intervals: make([]RetentionInterval, len(intervals)),
g = &Grid{
intervals: make([]Interval, len(intervals)),
}
for idx, i := range intervals {
comps := strings.SplitN(i, ",", 2)
@@ -62,11 +62,11 @@ func (ds dummySnap) Date() time.Time {
return ds.date
}
func (ds dummySnap) LessThan(b RetentionGridEntry) bool {
func (ds dummySnap) LessThan(b Entry) bool {
return ds.date.Before(b.(dummySnap).date) // don't have a txg here
}
func validateRetentionGridFitEntries(t *testing.T, now time.Time, input, keep, remove []RetentionGridEntry) {
func validateRetentionGridFitEntries(t *testing.T, now time.Time, input, keep, remove []Entry) {
snapDescr := func(d dummySnap) string {
return fmt.Sprintf("%s@%s", d.Name, d.date.Sub(now))
@@ -101,8 +101,8 @@ func validateRetentionGridFitEntries(t *testing.T, now time.Time, input, keep, r
}
func TestRetentionGridFitEntriesEmptyInput(t *testing.T) {
g := retentionGridFromString("10m|10m|10m|1h")
keep, remove := g.FitEntries(time.Now(), []RetentionGridEntry{})
g := gridFromString("10m|10m|10m|1h")
keep, remove := g.FitEntries(time.Now(), []Entry{})
assert.Empty(t, keep)
assert.Empty(t, remove)
}
@@ -111,13 +111,13 @@ func TestRetentionGridFitEntriesIntervalBoundariesAndAlignment(t *testing.T) {
// Intervals are (duration], i.e. 10min is in the first interval, not in the second
g := retentionGridFromString("10m|10m|10m")
g := gridFromString("10m|10m|10m")
t.Logf("%#v\n", g)
now := time.Unix(0, 0)
snaps := []RetentionGridEntry{
snaps := []Entry{
dummySnap{"0", true, now.Add(1 * time.Minute)}, // before now
dummySnap{"1", true, now}, // before now
dummySnap{"2", true, now.Add(-10 * time.Minute)}, // 1st interval
@@ -133,13 +133,13 @@ func TestRetentionGridFitEntriesIntervalBoundariesAndAlignment(t *testing.T) {
func TestRetentionGridFitEntries(t *testing.T) {
g := retentionGridFromString("10m,-1|10m|10m,2|1h")
g := gridFromString("10m,-1|10m|10m,2|1h")
t.Logf("%#v\n", g)
now := time.Unix(0, 0)
snaps := []RetentionGridEntry{
snaps := []Entry{
dummySnap{"1", true, now.Add(3 * time.Minute)}, // pre-now must always be kept
dummySnap{"b1", true, now.Add(-6 * time.Minute)}, // 1st interval allows unlimited entries
dummySnap{"b3", true, now.Add(-8 * time.Minute)}, // 1st interval allows unlimited entries