snapper: make error mode an error wait mode

Just because taking one snapshot fails does not mean snapper needs to
stop for all others.
Since users are advised to monitor error logs, snapshot-taking errors
can still be addressed.
The ErrorWait mode allows a potential future Report / Status command to
distinguish normal waits from error waits.
This commit is contained in:
Christian Schwarz 2018-09-24 12:29:34 +02:00
parent d04b9713c4
commit 4e04f8d3d2
2 changed files with 9 additions and 7 deletions

View File

@ -74,7 +74,7 @@ const (
Planning Planning
Snapshotting Snapshotting
Waiting Waiting
Error ErrorWait
) )
func (s State) sf() state { func (s State) sf() state {
@ -83,7 +83,7 @@ func (s State) sf() state {
Planning: plan, Planning: plan,
Snapshotting: snapshot, Snapshotting: snapshot,
Waiting: wait, Waiting: wait,
Error: nil, ErrorWait: wait,
} }
return m[s] return m[s]
} }
@ -163,7 +163,7 @@ func (s *Snapper) Run(ctx context.Context, snapshotsTaken chan<- struct{}) {
func onErr(err error, u updater) state { func onErr(err error, u updater) state {
return u(func(s *Snapper) { return u(func(s *Snapper) {
s.err = err s.err = err
s.state = Error s.state = ErrorWait
}).sf() }).sf()
} }
@ -254,13 +254,15 @@ func snapshot(a args, u updater) state {
select { select {
case a.snapshotsTaken <- struct{}{}: case a.snapshotsTaken <- struct{}{}:
default: default:
a.log.Warn("callback channel is full, discarding snapshot update event") if a.snapshotsTaken != nil {
a.log.Warn("callback channel is full, discarding snapshot update event")
}
} }
return u(func(snapper *Snapper) { return u(func(snapper *Snapper) {
if hadErr { if hadErr {
snapper.state = Error snapper.state = ErrorWait
snapper.err = errors.New("one or more snapshots could not be created") snapper.err = errors.New("one or more snapshots could not be created, check logs for details")
} else { } else {
snapper.state = Waiting snapper.state = Waiting
} }

View File

@ -8,7 +8,7 @@ const (
_State_name_0 = "SyncUpPlanning" _State_name_0 = "SyncUpPlanning"
_State_name_1 = "Snapshotting" _State_name_1 = "Snapshotting"
_State_name_2 = "Waiting" _State_name_2 = "Waiting"
_State_name_3 = "Error" _State_name_3 = "ErrorWait"
) )
var ( var (