mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 00:13:52 +01:00
WIP: draft incomplete keep rule for keeping most recent common ancestor
This commit is contained in:
parent
3edfe535c6
commit
3de3e2b688
@ -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_.*"
|
29
pruning/keep_most_recent_common_ancestor.go
Normal file
29
pruning/keep_most_recent_common_ancestor.go
Normal 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]}
|
||||
}
|
31
pruning/keep_most_recent_common_ancestor_test.go
Normal file
31
pruning/keep_most_recent_common_ancestor_test.go
Normal 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)
|
||||
|
||||
}
|
@ -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
|
||||
|
@ -9,6 +9,7 @@ type stubSnap struct {
|
||||
name string
|
||||
replicated bool
|
||||
date time.Time
|
||||
bothSides bool
|
||||
}
|
||||
|
||||
func (s stubSnap) Name() string { return s.name }
|
||||
|
Loading…
Reference in New Issue
Block a user