Skip to content

Commit

Permalink
Implement fast skip of "keep all" pruning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dsh2dsh committed May 4, 2024
1 parent 1cd99a5 commit 32632e3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions daemon/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 32632e3

Please sign in to comment.