WIP: generic activation through + new interval-based replication trigger

This commit is contained in:
Christian Schwarz
2023-12-22 14:00:20 +00:00
parent ebc46cf1c0
commit b0caa2d151
11 changed files with 197 additions and 43 deletions
+3 -8
View File
@@ -10,6 +10,7 @@ import (
"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/daemon/hooks"
"github.com/zrepl/zrepl/daemon/job/trigger"
"github.com/zrepl/zrepl/util/suspendresumesafetimer"
"github.com/zrepl/zrepl/zfs"
)
@@ -42,7 +43,7 @@ type Cron struct {
wakeupWhileRunningCount int
}
func (s *Cron) Run(ctx context.Context, snapshotsTaken chan<- struct{}) {
func (s *Cron) Run(ctx context.Context, snapshotsTaken *trigger.Trigger) {
for {
now := time.Now()
@@ -75,13 +76,7 @@ func (s *Cron) Run(ctx context.Context, snapshotsTaken chan<- struct{}) {
s.running = false
s.mtx.Unlock()
select {
case snapshotsTaken <- struct{}{}:
default:
if snapshotsTaken != nil {
getLogger(ctx).Warn("callback channel is full, discarding snapshot update event")
}
}
snapshotsTaken.Fire()
}()
}
+3 -1
View File
@@ -2,11 +2,13 @@ package snapper
import (
"context"
"github.com/zrepl/zrepl/daemon/job/trigger"
)
type manual struct{}
func (s *manual) Run(ctx context.Context, wakeUpCommon chan<- struct{}) {
func (s *manual) Run(ctx context.Context, snapshotsTaken *trigger.Trigger) {
// nothing to do
}
+4 -9
View File
@@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
"github.com/zrepl/zrepl/daemon/job/trigger"
"github.com/zrepl/zrepl/daemon/logging/trace"
"github.com/zrepl/zrepl/config"
@@ -51,7 +52,7 @@ type periodicArgs struct {
interval time.Duration
fsf zfs.DatasetFilter
planArgs planArgs
snapshotsTaken chan<- struct{}
snapshotsTaken *trigger.Trigger
dryRun bool
}
@@ -103,7 +104,7 @@ func (s State) sf() state {
type updater func(u func(*Periodic)) State
type state func(a periodicArgs, u updater) state
func (s *Periodic) Run(ctx context.Context, snapshotsTaken chan<- struct{}) {
func (s *Periodic) Run(ctx context.Context, snapshotsTaken *trigger.Trigger) {
defer trace.WithSpanFromStackUpdateCtx(&ctx)()
getLogger(ctx).Debug("start")
defer getLogger(ctx).Debug("stop")
@@ -207,13 +208,7 @@ func periodicStateSnapshot(a periodicArgs, u updater) state {
ok := plan.execute(a.ctx, false)
select {
case a.snapshotsTaken <- struct{}{}:
default:
if a.snapshotsTaken != nil {
getLogger(a.ctx).Warn("callback channel is full, discarding snapshot update event")
}
}
a.snapshotsTaken.Fire()
return u(func(snapper *Periodic) {
if !ok {
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/daemon/job/trigger"
"github.com/zrepl/zrepl/zfs"
)
@@ -17,7 +18,7 @@ const (
)
type Snapper interface {
Run(ctx context.Context, snapshotsTaken chan<- struct{})
Run(ctx context.Context, snapshotsTaken *trigger.Trigger)
Report() Report
}