WIP: draft incomplete keep rule for keeping most recent common ancestor

This commit is contained in:
Christian Schwarz 2019-10-10 13:34:33 +02:00
parent 3edfe535c6
commit 3de3e2b688
5 changed files with 63 additions and 0 deletions

View File

@ -26,6 +26,7 @@ jobs:
- type: last_n
count: 10
keep_receiver:
- type: most_recent_common_snapshot
- type: grid
grid: 1x1h(keep=all) | 24x1h | 35x1d | 6x30d
regex: "zrepl_.*"

View File

@ -0,0 +1,29 @@
package pruning
import "sort"
type KeepMostRecentCommonAncestor struct {
_opaque struct{}
}
func NewKeepMostRecentCommonAncestor() *KeepMostRecentCommonAncestor {
return &KeepMostRecentCommonAncestor{}
}
func (k *KeepMostRecentCommonAncestor) KeepRule(snaps []Snapshot) (destroyList []Snapshot) {
var bothSides []Snapshot
for _, s := range snaps {
if s.PresentOnBothSides() {
bothSides = append(bothSides, s)
}
}
if len(bothSides) == 0 {
return []Snapshot{}
}
sort.Slice(bothSides, func(i, j int) bool {
return bothSides[i].Date().After(bothSides[j].Date())
})
return []Snapshot{bothSides[0]}
}

View File

@ -0,0 +1,31 @@
package pruning
import "testing"
func TestKeppMostRecentCommonAncestor(t *testing.T) {
o := func(minutes int) time.Time {
return time.Unix(123, 0).Add(time.Duration(minutes) * time.Minute)
}
tcs := map[string]testCase{
"empty": {
inputs: []Snapshot{},
rules: []KeepRule{NewKeepMostRecentCommonAncestor()},
expDestroy: map[string]bool{},
},
"nil": {
inputs: nil,
rules: []KeepRule{NewKeepMostRecentCommonAncestor()},
expDestroy: map[string]bool{},
},
"": {
inputs: []Snapshot{
stubSnap{name: "s1", date: o(5), bothSides: }
},
}
}
testTable(tcs, t)
}

View File

@ -17,6 +17,7 @@ type Snapshot interface {
Name() string
Replicated() bool
Date() time.Time
PresentOnBothSides() bool
}
// The returned snapshot list is guaranteed to only contains elements of input parameter snaps

View File

@ -9,6 +9,7 @@ type stubSnap struct {
name string
replicated bool
date time.Time
bothSides bool
}
func (s stubSnap) Name() string { return s.name }