mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-28 19:34:58 +01:00
fixup 4e04f8d3d2
: snapper with separate stopped state for clean shutdown
would tight loop in ErrorWait
This commit is contained in:
parent
cf5d63ee88
commit
f3e8eda04d
@ -75,6 +75,7 @@ const (
|
|||||||
Snapshotting
|
Snapshotting
|
||||||
Waiting
|
Waiting
|
||||||
ErrorWait
|
ErrorWait
|
||||||
|
Stopped
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s State) sf() state {
|
func (s State) sf() state {
|
||||||
@ -84,6 +85,7 @@ func (s State) sf() state {
|
|||||||
Snapshotting: snapshot,
|
Snapshotting: snapshot,
|
||||||
Waiting: wait,
|
Waiting: wait,
|
||||||
ErrorWait: wait,
|
ErrorWait: wait,
|
||||||
|
Stopped: nil,
|
||||||
}
|
}
|
||||||
return m[s]
|
return m[s]
|
||||||
}
|
}
|
||||||
@ -167,6 +169,13 @@ func onErr(err error, u updater) state {
|
|||||||
}).sf()
|
}).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 {
|
func syncUp(a args, u updater) state {
|
||||||
fss, err := listFSes(a.fsf)
|
fss, err := listFSes(a.fsf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -187,7 +196,7 @@ func syncUp(a args, u updater) state {
|
|||||||
s.state = Planning
|
s.state = Planning
|
||||||
}).sf()
|
}).sf()
|
||||||
case <-a.ctx.Done():
|
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
|
snapper.state = Planning
|
||||||
}).sf()
|
}).sf()
|
||||||
case <-a.ctx.Done():
|
case <-a.ctx.Done():
|
||||||
return onErr(a.ctx.Err(), u)
|
return onMainCtxDone(a.ctx, u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ const (
|
|||||||
_State_name_1 = "Snapshotting"
|
_State_name_1 = "Snapshotting"
|
||||||
_State_name_2 = "Waiting"
|
_State_name_2 = "Waiting"
|
||||||
_State_name_3 = "ErrorWait"
|
_State_name_3 = "ErrorWait"
|
||||||
|
_State_name_4 = "Stopped"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -26,6 +27,8 @@ func (i State) String() string {
|
|||||||
return _State_name_2
|
return _State_name_2
|
||||||
case i == 16:
|
case i == 16:
|
||||||
return _State_name_3
|
return _State_name_3
|
||||||
|
case i == 32:
|
||||||
|
return _State_name_4
|
||||||
default:
|
default:
|
||||||
return "State(" + strconv.FormatInt(int64(i), 10) + ")"
|
return "State(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user