Merge pull request #5962 from filecoin-project/fix/storagefsm-allow-broken-global
storagefsm: Apply global events even in broken states
This commit is contained in:
commit
b54b1303f9
10
extern/storage-sealing/fsm.go
vendored
10
extern/storage-sealing/fsm.go
vendored
@ -242,7 +242,15 @@ func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(sta
|
||||
|
||||
p := fsmPlanners[state.State]
|
||||
if p == nil {
|
||||
return nil, 0, xerrors.Errorf("planner for state %s not found", state.State)
|
||||
if len(events) == 1 {
|
||||
if _, ok := events[0].User.(globalMutator); ok {
|
||||
p = planOne() // in case we're in a really weird state, allow restart / update state / remove
|
||||
}
|
||||
}
|
||||
|
||||
if p == nil {
|
||||
return nil, 0, xerrors.Errorf("planner for state %s not found", state.State)
|
||||
}
|
||||
}
|
||||
|
||||
processed, err := p(events, state)
|
||||
|
35
extern/storage-sealing/fsm_test.go
vendored
35
extern/storage-sealing/fsm_test.go
vendored
@ -175,3 +175,38 @@ func TestPlannerList(t *testing.T) {
|
||||
require.True(t, ok, "state %s", state)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrokenState(t *testing.T) {
|
||||
var notif []struct{ before, after SectorInfo }
|
||||
ma, _ := address.NewIDAddress(55151)
|
||||
m := test{
|
||||
s: &Sealing{
|
||||
maddr: ma,
|
||||
stats: SectorStats{
|
||||
bySector: map[abi.SectorID]statSectorState{},
|
||||
},
|
||||
notifee: func(before, after SectorInfo) {
|
||||
notif = append(notif, struct{ before, after SectorInfo }{before, after})
|
||||
},
|
||||
},
|
||||
t: t,
|
||||
state: &SectorInfo{State: "not a state"},
|
||||
}
|
||||
|
||||
_, _, err := m.s.plan([]statemachine.Event{{User: SectorPacked{}}}, m.state)
|
||||
require.Error(t, err)
|
||||
require.Equal(m.t, m.state.State, SectorState("not a state"))
|
||||
|
||||
m.planSingle(SectorRemove{})
|
||||
require.Equal(m.t, m.state.State, Removing)
|
||||
|
||||
expected := []SectorState{"not a state", "not a state", Removing}
|
||||
for i, n := range notif {
|
||||
if n.before.State != expected[i] {
|
||||
t.Fatalf("expected before state: %s, got: %s", expected[i], n.before.State)
|
||||
}
|
||||
if n.after.State != expected[i+1] {
|
||||
t.Fatalf("expected after state: %s, got: %s", expected[i+1], n.after.State)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user