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:
Łukasz Magiera 2021-04-11 22:30:56 +02:00 committed by GitHub
commit b54b1303f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View File

@ -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)

View File

@ -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)
}
}
}