lotus/extern/sector-storage/roprov.go

46 lines
1.2 KiB
Go
Raw Normal View History

package sectorstorage
2020-03-23 11:40:02 +00:00
import (
"context"
"golang.org/x/xerrors"
2020-03-23 11:40:02 +00:00
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
2020-03-23 11:40:02 +00:00
)
type readonlyProvider struct {
2020-06-03 20:00:34 +00:00
index stores.SectorIndex
stor *stores.Local
2020-06-15 12:32:17 +00:00
spt abi.RegisteredSealProof
2020-03-23 11:40:02 +00:00
}
2020-06-04 21:30:20 +00:00
func (l *readonlyProvider) AcquireSector(ctx context.Context, id abi.SectorID, existing stores.SectorFileType, allocate stores.SectorFileType, sealing stores.PathType) (stores.SectorPaths, func(), error) {
2020-03-25 20:19:58 +00:00
if allocate != stores.FTNone {
2020-03-26 02:50:56 +00:00
return stores.SectorPaths{}, nil, xerrors.New("read-only storage")
2020-03-23 11:40:02 +00:00
}
ssize, err := l.spt.SectorSize()
if err != nil {
return stores.SectorPaths{}, nil, xerrors.Errorf("failed to determine sector size: %w", err)
}
2020-06-03 20:00:34 +00:00
ctx, cancel := context.WithCancel(ctx)
2020-06-08 16:57:56 +00:00
// use TryLock to avoid blocking
locked, err := l.index.StorageTryLock(ctx, id, existing, stores.FTNone)
if err != nil {
2020-06-09 09:14:25 +00:00
cancel()
2020-06-03 20:00:34 +00:00
return stores.SectorPaths{}, nil, xerrors.Errorf("acquiring sector lock: %w", err)
}
2020-06-08 16:57:56 +00:00
if !locked {
2020-06-09 09:14:25 +00:00
cancel()
2020-06-08 16:57:56 +00:00
return stores.SectorPaths{}, nil, xerrors.Errorf("failed to acquire sector lock")
}
2020-06-03 20:00:34 +00:00
p, _, err := l.stor.AcquireSector(ctx, id, ssize, existing, allocate, sealing, stores.AcquireMove)
2020-03-23 11:40:02 +00:00
2020-06-04 19:00:16 +00:00
return p, cancel, err
2020-03-23 11:40:02 +00:00
}