WIP: draft incomplete keep rule for keeping most recent common ancestor
This commit is contained in:
@@ -26,6 +26,7 @@ jobs:
|
|||||||
- type: last_n
|
- type: last_n
|
||||||
count: 10
|
count: 10
|
||||||
keep_receiver:
|
keep_receiver:
|
||||||
|
- type: most_recent_common_snapshot
|
||||||
- type: grid
|
- type: grid
|
||||||
grid: 1x1h(keep=all) | 24x1h | 35x1d | 6x30d
|
grid: 1x1h(keep=all) | 24x1h | 35x1d | 6x30d
|
||||||
regex: "zrepl_.*"
|
regex: "zrepl_.*"
|
||||||
@@ -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]}
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ type Snapshot interface {
|
|||||||
Name() string
|
Name() string
|
||||||
Replicated() bool
|
Replicated() bool
|
||||||
Date() time.Time
|
Date() time.Time
|
||||||
|
PresentOnBothSides() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// The returned snapshot list is guaranteed to only contains elements of input parameter snaps
|
// The returned snapshot list is guaranteed to only contains elements of input parameter snaps
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ type stubSnap struct {
|
|||||||
name string
|
name string
|
||||||
replicated bool
|
replicated bool
|
||||||
date time.Time
|
date time.Time
|
||||||
|
bothSides bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s stubSnap) Name() string { return s.name }
|
func (s stubSnap) Name() string { return s.name }
|
||||||
|
|||||||
Reference in New Issue
Block a user