sectors: Handle sector state reload errors more gracefully

This commit is contained in:
Łukasz Magiera 2019-12-11 15:17:38 +01:00
parent e6dd471103
commit 613bb25297
4 changed files with 63 additions and 3 deletions

View File

@ -22,7 +22,7 @@ const (
MajorOnlyMask = 0xff0000 MajorOnlyMask = 0xff0000
MinorOnlyMask = 0x00ff00 MinorOnlyMask = 0x00ff00
PatchOnlyMask = 0x0000ff PatchOnlyMask = 0x0000ff
c) )
// VersionInts returns (major, minor, patch) versions // VersionInts returns (major, minor, patch) versions
func VersionInts(version uint32) (uint32, uint32, uint32) { func VersionInts(version uint32) (uint32, uint32, uint32) {

View File

@ -8,6 +8,7 @@ import (
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/query" "github.com/ipfs/go-datastore/query"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
"go.uber.org/multierr"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/lotus/lib/cborutil" "github.com/filecoin-project/lotus/lib/cborutil"
@ -139,6 +140,8 @@ func (st *StateStore) List(out interface{}) error {
outT := reflect.TypeOf(out).Elem().Elem() outT := reflect.TypeOf(out).Elem().Elem()
rout := reflect.ValueOf(out) rout := reflect.ValueOf(out)
var errs error
for { for {
res, ok := res.NextSync() res, ok := res.NextSync()
if !ok { if !ok {
@ -151,7 +154,8 @@ func (st *StateStore) List(out interface{}) error {
elem := reflect.New(outT) elem := reflect.New(outT)
err := cborutil.ReadCborRPC(bytes.NewReader(res.Value), elem.Interface()) err := cborutil.ReadCborRPC(bytes.NewReader(res.Value), elem.Interface())
if err != nil { if err != nil {
return err errs = multierr.Append(errs, xerrors.Errorf("decoding state for key '%s': %w", res.Key, err))
continue
} }
rout.Elem().Set(reflect.Append(rout.Elem(), elem.Elem())) rout.Elem().Set(reflect.Append(rout.Elem(), elem.Elem()))

View File

@ -65,7 +65,7 @@ func (m *Miner) UpdateSectorState(ctx context.Context, sector uint64, snonce uin
func (m *Miner) sectorStateLoop(ctx context.Context) error { func (m *Miner) sectorStateLoop(ctx context.Context) error {
trackedSectors, err := m.ListSectors() trackedSectors, err := m.ListSectors()
if err != nil { if err != nil {
return xerrors.Errorf("loading sector list: %w", err) log.Errorf("loading sector list: %+v", err)
} }
go func() { go func() {

56
storage/sectors_test.go Normal file
View File

@ -0,0 +1,56 @@
package storage
import (
"bytes"
"testing"
"gotest.tools/assert"
"github.com/filecoin-project/lotus/lib/cborutil"
)
func TestSectorInfoSelialization(t *testing.T) {
si := &SectorInfo{
State: 123,
SectorID: 234,
Nonce: 345,
Pieces: []Piece{{
DealID: 1234,
Size: 5,
CommP: []byte{3},
}},
CommD: []byte{32, 4},
CommR: nil,
Proof: nil,
Ticket: SealTicket{
BlockHeight: 345,
TicketBytes: []byte{87, 78, 7, 87},
},
PreCommitMessage: nil,
Seed: SealSeed{},
CommitMessage: nil,
FaultReportMsg: nil,
LastErr: "hi",
}
b, err := cborutil.Dump(si)
if err != nil {
t.Fatal(err)
}
var si2 SectorInfo
if err := cborutil.ReadCborRPC(bytes.NewReader(b), &si); err != nil {
return
}
assert.Equal(t, si.State, si2.State)
assert.Equal(t, si.Nonce, si2.Nonce)
assert.Equal(t, si.SectorID, si2.SectorID)
assert.Equal(t, si.Pieces, si2.Pieces)
assert.Equal(t, si.CommD, si2.CommD)
assert.Equal(t, si.Ticket, si2.Ticket)
assert.Equal(t, si, si2)
}