Skip to content

Commit

Permalink
Fix unsealed sector acquire logic
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Apr 28, 2021
1 parent ac39417 commit 9cb468b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions extern/sector-storage/ffiwrapper/sealer_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion extern/sector-storage/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions extern/sector-storage/piece_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions extern/sector-storage/stores/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions extern/sector-storage/stores/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion extern/sector-storage/stores/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions extern/sector-storage/storiface/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ type PathType string
const (
PathStorage PathType = "storage"
PathSealing PathType = "sealing"

PathStoragePrefer PathType = "storage-prefer"
)

type AcquireMode string
Expand Down

0 comments on commit 9cb468b

Please sign in to comment.