fixup 4e04f8d3d2: snapper with separate stopped state for clean shutdown

would tight loop in ErrorWait
This commit is contained in:
Christian Schwarz 2018-09-24 14:40:47 +02:00
parent cf5d63ee88
commit f3e8eda04d
2 changed files with 14 additions and 2 deletions

View File

@ -75,6 +75,7 @@ const (
Snapshotting
Waiting
ErrorWait
Stopped
)
func (s State) sf() state {
@ -84,6 +85,7 @@ func (s State) sf() state {
Snapshotting: snapshot,
Waiting: wait,
ErrorWait: wait,
Stopped: nil,
}
return m[s]
}
@ -167,6 +169,13 @@ func onErr(err error, u updater) state {
}).sf()
}
func onMainCtxDone(ctx context.Context, u updater) state {
return u(func(s *Snapper) {
s.err = ctx.Err()
s.state = Stopped
}).sf()
}
func syncUp(a args, u updater) state {
fss, err := listFSes(a.fsf)
if err != nil {
@ -187,7 +196,7 @@ func syncUp(a args, u updater) state {
s.state = Planning
}).sf()
case <-a.ctx.Done():
return onErr(err, u)
return onMainCtxDone(a.ctx, u)
}
}
@ -286,7 +295,7 @@ func wait(a args, u updater) state {
snapper.state = Planning
}).sf()
case <-a.ctx.Done():
return onErr(a.ctx.Err(), u)
return onMainCtxDone(a.ctx, u)
}
}

View File

@ -9,6 +9,7 @@ const (
_State_name_1 = "Snapshotting"
_State_name_2 = "Waiting"
_State_name_3 = "ErrorWait"
_State_name_4 = "Stopped"
)
var (
@ -26,6 +27,8 @@ func (i State) String() string {
return _State_name_2
case i == 16:
return _State_name_3
case i == 32:
return _State_name_4
default:
return "State(" + strconv.FormatInt(int64(i), 10) + ")"
}