From 32632e32646018bbfb26832e35388521c2b70dd8 Mon Sep 17 00:00:00 2001 From: Denis Shaposhnikov <993498+dsh2dsh@users.noreply.github.com> Date: Sat, 4 May 2024 22:16:09 +0200 Subject: [PATCH] Implement fast skip of "keep all" pruning Instead of configuration like this: ``` yaml pruning: keep: - type: "regex" regex: ".*" ``` or like this: ``` yaml pruning: keep_sender: - type: "regex" regex: ".*" keep_receiver: ``` which keeps all snapshots, now it's possible to omit `pruning:` at all, or one of `keep_sender:` or `keep_receiver:`. In this case zrepl will early abort pruning and mark it as done. Originally zrepl requests all snapshots and does nothing after that, because pruning configured to keep all snapshots, but anyway it spends some time executing zfs commands. --- README.md | 29 +++++++++++++++++++++++++++++ config/config.go | 6 +++--- daemon/pruner/pruner.go | 6 ++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 566d65b3..c237ec7a 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,35 @@ This project is a fork of [zrepl](https://github.com/zrepl/zrepl). type: "cron" still works too, just for compatibility. Both of them is the same type. + * Fast skip "keep all" pruning. + + Instead of configuration like this: + + ``` yaml + pruning: + keep: + - type: "regex" + regex: ".*" + ``` + + or like this: + + ``` yaml + pruning: + keep_sender: + - type: "regex" + regex: ".*" + keep_receiver: + ``` + + which keeps all snapshots, now it's possible to omit `pruning:` at all, or + one of `keep_sender:` or `keep_receiver:`. In this case zrepl will early + abort pruning and mark it as done. + + Originally zrepl requests all snapshots and does nothing after that, because + pruning configured to keep all snapshots, but anyway it spends some time + executing zfs commands. + * Small cosmetic changes ## User Documentation diff --git a/config/config.go b/config/config.go index 15d6c271..037d10e4 100644 --- a/config/config.go +++ b/config/config.go @@ -103,7 +103,7 @@ type PassiveJob struct { type SnapJob struct { Type string `yaml:"type"` Name string `yaml:"name"` - Pruning PruningLocal `yaml:"pruning"` + Pruning PruningLocal `yaml:"pruning,optional"` Snapshotting SnapshottingEnum `yaml:"snapshotting"` Filesystems FilesystemsFilter `yaml:"filesystems"` MonitorSnapshots MonitorSnapshots `yaml:"monitor,optional"` @@ -266,8 +266,8 @@ type SnapshottingManual struct { } type PruningSenderReceiver struct { - KeepSender []PruningEnum `yaml:"keep_sender"` - KeepReceiver []PruningEnum `yaml:"keep_receiver"` + KeepSender []PruningEnum `yaml:"keep_sender,optional"` + KeepReceiver []PruningEnum `yaml:"keep_receiver,optional"` } type PruningLocal struct { diff --git a/daemon/pruner/pruner.go b/daemon/pruner/pruner.go index 9c2e7d0f..45b184c5 100644 --- a/daemon/pruner/pruner.go +++ b/daemon/pruner/pruner.go @@ -212,6 +212,12 @@ func (s State) IsTerminal() bool { type updater func(func(*Pruner)) func (p *Pruner) Prune() { + if len(p.args.rules) == 0 { + l := GetLogger(p.args.ctx) + l.Info("skip pruning, because no keep rules configured") + p.state = Done + return + } p.prune(p.args) }