From 9cb468be3ee4106bf4a2b5ed5e1dcabf4a04e338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 28 Apr 2021 20:08:50 +0200 Subject: [PATCH] Fix unsealed sector acquire logic --- extern/sector-storage/ffiwrapper/sealer_cgo.go | 6 +++--- extern/sector-storage/manager.go | 2 +- extern/sector-storage/piece_provider.go | 6 ++++-- extern/sector-storage/stores/index.go | 3 +++ extern/sector-storage/stores/local.go | 4 ++++ extern/sector-storage/stores/remote.go | 2 +- extern/sector-storage/storiface/storage.go | 2 ++ 7 files changed, 18 insertions(+), 7 deletions(-) diff --git a/extern/sector-storage/ffiwrapper/sealer_cgo.go b/extern/sector-storage/ffiwrapper/sealer_cgo.go index 21d14a4d9e6..a17a82eefd5 100644 --- a/extern/sector-storage/ffiwrapper/sealer_cgo.go +++ b/extern/sector-storage/ffiwrapper/sealer_cgo.go @@ -244,12 +244,12 @@ func (sb *Sealer) UnsealPiece(ctx context.Context, sector storage.SectorRef, off maxPieceSize := abi.PaddedPieceSize(ssize) // try finding existing - unsealedPath, done, err := sb.sectors.AcquireSector(ctx, sector, storiface.FTUnsealed, storiface.FTNone, storiface.PathStorage) + unsealedPath, done, err := sb.sectors.AcquireSector(ctx, sector, storiface.FTUnsealed, storiface.FTNone, storiface.PathStoragePrefer) var pf *partialfile.PartialFile switch { case xerrors.Is(err, storiface.ErrSectorNotFound): - unsealedPath, done, err = sb.sectors.AcquireSector(ctx, sector, storiface.FTNone, storiface.FTUnsealed, storiface.PathStorage) + unsealedPath, done, err = sb.sectors.AcquireSector(ctx, sector, storiface.FTNone, storiface.FTUnsealed, storiface.PathStoragePrefer) if err != nil { return xerrors.Errorf("acquire unsealed sector path (allocate): %w", err) } @@ -286,7 +286,7 @@ func (sb *Sealer) UnsealPiece(ctx context.Context, sector storage.SectorRef, off return nil } - srcPaths, srcDone, err := sb.sectors.AcquireSector(ctx, sector, storiface.FTCache|storiface.FTSealed, storiface.FTNone, storiface.PathStorage) + srcPaths, srcDone, err := sb.sectors.AcquireSector(ctx, sector, storiface.FTCache|storiface.FTSealed, storiface.FTNone, storiface.PathStoragePrefer) if err != nil { return xerrors.Errorf("acquire sealed sector paths: %w", err) } diff --git a/extern/sector-storage/manager.go b/extern/sector-storage/manager.go index 3bf0ac19e63..ef9c4b867da 100644 --- a/extern/sector-storage/manager.go +++ b/extern/sector-storage/manager.go @@ -237,7 +237,7 @@ func (m *Manager) SectorsUnsealPiece(ctx context.Context, sector storage.SectorR return xerrors.Errorf("getting sector size: %w", err) } - selector := newExistingSelector(m.index, sector.ID, storiface.FTSealed|storiface.FTCache, false) + selector := newExistingSelector(m.index, sector.ID, storiface.FTSealed|storiface.FTCache, true) log.Debugf("schedule unseal for sector %d", sector.ID) err = m.sched.Schedule(ctx, sector, sealtasks.TTUnseal, selector, unsealFetch, func(ctx context.Context, w Worker) error { diff --git a/extern/sector-storage/piece_provider.go b/extern/sector-storage/piece_provider.go index 008c06e63a0..ae4a0859d8d 100644 --- a/extern/sector-storage/piece_provider.go +++ b/extern/sector-storage/piece_provider.go @@ -3,10 +3,9 @@ package sectorstorage import ( "bufio" "context" - "io" - "github.com/ipfs/go-cid" "golang.org/x/xerrors" + "io" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/specs-storage/storage" @@ -67,6 +66,9 @@ func (p *pieceProvider) ReadPiece(ctx context.Context, sector storage.SectorRef, } r, unlock, err := p.tryReadUnsealedPiece(ctx, sector, offset, size) + if xerrors.Is(err, storiface.ErrSectorNotFound) { + err = nil + } if err != nil { return nil, false, err } diff --git a/extern/sector-storage/stores/index.go b/extern/sector-storage/stores/index.go index 4acc2ecdb6c..a9f7ef7f6ce 100644 --- a/extern/sector-storage/stores/index.go +++ b/extern/sector-storage/stores/index.go @@ -395,6 +395,9 @@ func (i *Index) StorageBestAlloc(ctx context.Context, allocate storiface.SectorF if (pathType == storiface.PathStorage) && !p.info.CanStore { continue } + if (pathType == storiface.PathStoragePrefer) && !p.info.CanStore && !p.info.CanSeal { + continue + } if spaceReq > uint64(p.fsi.Available) { log.Debugf("not allocating on %s, out of space (available: %d, need: %d)", p.info.ID, p.fsi.Available, spaceReq) diff --git a/extern/sector-storage/stores/local.go b/extern/sector-storage/stores/local.go index ab0a8eaebc8..bd03d34ed4f 100644 --- a/extern/sector-storage/stores/local.go +++ b/extern/sector-storage/stores/local.go @@ -493,6 +493,10 @@ func (st *Local) AcquireSector(ctx context.Context, sid storage.SectorRef, exist continue } + if (pathType == storiface.PathStoragePrefer) && !si.CanStore && !si.CanSeal { + continue + } + // TODO: Check free space best = p.sectorPath(sid.ID, fileType) diff --git a/extern/sector-storage/stores/remote.go b/extern/sector-storage/stores/remote.go index 4142dac091b..5c89fd24193 100644 --- a/extern/sector-storage/stores/remote.go +++ b/extern/sector-storage/stores/remote.go @@ -117,7 +117,7 @@ func (r *Remote) AcquireSector(ctx context.Context, s storage.SectorRef, existin } odt := storiface.FSOverheadSeal - if pathType == storiface.PathStorage { + if pathType == storiface.PathStorage || pathType == storiface.PathStoragePrefer { odt = storiface.FsOverheadFinalized } diff --git a/extern/sector-storage/storiface/storage.go b/extern/sector-storage/storiface/storage.go index e836002d5de..98d128b1cf3 100644 --- a/extern/sector-storage/storiface/storage.go +++ b/extern/sector-storage/storiface/storage.go @@ -5,6 +5,8 @@ type PathType string const ( PathStorage PathType = "storage" PathSealing PathType = "sealing" + + PathStoragePrefer PathType = "storage-prefer" ) type AcquireMode string