Compare commits

..

1 Commits

Author SHA1 Message Date
Christian Schwarz 3de3e2b688 WIP: draft incomplete keep rule for keeping most recent common ancestor 2020-02-17 17:46:31 +01:00
8 changed files with 68 additions and 8 deletions
+1
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_.*"
+2 -4
View File
@@ -21,10 +21,8 @@ RestrictRealtime=yes
SystemCallArchitectures=native
# BEGIN ProtectHome
# DEBIAN STRETCH
ProtectHome=read-only
# FEDORA 28 / 29
# ProtectHome=tmpfs
ProtectHome=read-only # DEBIAN STRETCH
# ProtectHome=tmpfs # FEDORA 28 / 29
# END ProtectHome
# BEGIN SystemCallFilter
-3
View File
@@ -37,9 +37,6 @@ The following list may be incomplete, feel free to submit a PR with an update:
* - MacOS
- ``brew install zrepl``
- Available on `homebrew <https://brew.sh>`_
* - Arch Linux
- ``yay install zrepl-bin``
- Available on `AUR <https://aur.archlinux.org/packages/zrepl-bin>`_
* - Others
-
- Use `binary releases`_ or build from source.
@@ -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)
}
+1
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
+1
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 }
@@ -36,7 +36,9 @@ func ClientConn(cn transport.Connecter, log Logger) *grpc.ClientConn {
})
dialerOption := grpc.WithDialer(grpcclientidentity.NewDialer(log, cn))
cred := grpc.WithTransportCredentials(grpcclientidentity.NewTransportCredentials(log))
cc, err := grpc.DialContext(context.Background(), "doesn't matter done by dialer", dialerOption, cred, ka)
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) // FIXME constant
defer cancel()
cc, err := grpc.DialContext(ctx, "doesn't matter done by dialer", dialerOption, cred, ka)
if err != nil {
log.WithError(err).Error("cannot create gRPC client conn (non-blocking)")
// It's ok to panic here: the we call grpc.DialContext without the