sealmgr: Working local addpiece
This commit is contained in:
parent
c91d970c41
commit
4beed065b6
89
storage/sealmgr/advmgr/local.go
Normal file
89
storage/sealmgr/advmgr/local.go
Normal file
@ -0,0 +1,89 @@
|
||||
package advmgr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-sectorbuilder"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
|
||||
"github.com/filecoin-project/lotus/storage/sealmgr"
|
||||
)
|
||||
|
||||
type localWorker struct {
|
||||
scfg *sectorbuilder.Config
|
||||
storage *storage
|
||||
}
|
||||
|
||||
type localWorkerPathProvider struct {
|
||||
w *localWorker
|
||||
}
|
||||
|
||||
func (l *localWorkerPathProvider) AcquireSectorNumber() (abi.SectorNumber, error) {
|
||||
return 0, xerrors.Errorf("unsupported")
|
||||
}
|
||||
|
||||
func (l *localWorkerPathProvider) FinalizeSector(abi.SectorNumber) error {
|
||||
return xerrors.Errorf("unsupported")
|
||||
}
|
||||
|
||||
func (l *localWorkerPathProvider) AcquireSector(id abi.SectorNumber, existing sectorbuilder.SectorFileType, allocate sectorbuilder.SectorFileType, sealing bool) (sectorbuilder.SectorPaths, func(), error) {
|
||||
mid, err := address.IDFromAddress(l.w.scfg.Miner)
|
||||
if err != nil {
|
||||
return sectorbuilder.SectorPaths{}, nil, xerrors.Errorf("get miner ID: %w", err)
|
||||
}
|
||||
|
||||
return l.w.storage.acquireSector(abi.ActorID(mid), id, existing, allocate, sealing)
|
||||
}
|
||||
|
||||
func (l *localWorker) sb() (sectorbuilder.Basic, error) {
|
||||
return sectorbuilder.New(&localWorkerPathProvider{w:l}, l.scfg)
|
||||
}
|
||||
|
||||
func (l *localWorker) AddPiece(ctx context.Context, sz abi.UnpaddedPieceSize, sn abi.SectorNumber, r io.Reader, epcs []abi.UnpaddedPieceSize) (abi.PieceInfo, error) {
|
||||
sb, err := l.sb()
|
||||
if err != nil {
|
||||
return abi.PieceInfo{}, err
|
||||
}
|
||||
|
||||
return sb.AddPiece(ctx, sz, sn, r, epcs)
|
||||
}
|
||||
|
||||
func (l *localWorker) SealPreCommit1(ctx context.Context, sectorNum abi.SectorNumber, ticket abi.SealRandomness, pieces []abi.PieceInfo) (out []byte, err error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *localWorker) SealPreCommit2(ctx context.Context, sectorNum abi.SectorNumber, phase1Out []byte) (sealedCID cid.Cid, unsealedCID cid.Cid, err error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *localWorker) SealCommit1(ctx context.Context, sectorNum abi.SectorNumber, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, sealedCID cid.Cid, unsealedCID cid.Cid) (output []byte, err error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *localWorker) SealCommit2(ctx context.Context, sectorNum abi.SectorNumber, phase1Out []byte) (proof []byte, err error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *localWorker) FinalizeSector(context.Context, abi.SectorNumber) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (l *localWorker) TaskTypes() map[sealmgr.TaskType]struct{} {
|
||||
return map[sealmgr.TaskType]struct{}{
|
||||
sealmgr.TTAddPiece: {},
|
||||
sealmgr.TTPreCommit1: {},
|
||||
sealmgr.TTPreCommit2: {},
|
||||
sealmgr.TTCommit2: {},
|
||||
}
|
||||
}
|
||||
|
||||
func (l *localWorker) Paths() []Path {
|
||||
return l.storage.local()
|
||||
}
|
||||
|
||||
var _ Worker = &localWorker{}
|
@ -70,7 +70,9 @@ func New(ls LocalStorage, cfg *sectorbuilder.Config, sc SectorIDCounter) (*Manag
|
||||
}
|
||||
|
||||
m := &Manager{
|
||||
workers: nil,
|
||||
workers: []Worker{
|
||||
&localWorker{scfg: cfg, storage: stor},
|
||||
},
|
||||
scfg: cfg,
|
||||
sc: sc,
|
||||
|
||||
|
@ -157,17 +157,6 @@ func (st *storage) acquireSector(mid abi.ActorID, id abi.SectorNumber, existing
|
||||
continue
|
||||
}
|
||||
|
||||
s, ok := p.sectors[abi.SectorID{
|
||||
Miner: mid,
|
||||
Number: id,
|
||||
}]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if s & fileType == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// TODO: Check free space
|
||||
// TODO: Calc weights
|
||||
|
||||
@ -238,6 +227,25 @@ func (st *storage) findSector(mid abi.ActorID, sn abi.SectorNumber, typ sectorbu
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (st *storage) local() []Path {
|
||||
var out []Path
|
||||
for _, p := range st.paths {
|
||||
if p.local == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
out = append(out, Path{
|
||||
ID: p.meta.ID,
|
||||
Weight: p.meta.Weight,
|
||||
LocalPath: p.local,
|
||||
CanSeal: p.meta.CanSeal,
|
||||
CanStore: p.meta.CanStore,
|
||||
})
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func parseSectorID(baseName string) (abi.SectorID, error) {
|
||||
var n abi.SectorNumber
|
||||
var mid abi.ActorID
|
||||
|
@ -16,6 +16,13 @@ import (
|
||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||
)
|
||||
|
||||
|
||||
type LocalWorker struct {
|
||||
sectorbuilder.Basic
|
||||
}
|
||||
|
||||
var _ Worker = &LocalWorker{}
|
||||
|
||||
// Simple implements a very basic storage manager which has one local worker,
|
||||
// running one thing locally
|
||||
type Simple struct {
|
||||
|
@ -1,11 +0,0 @@
|
||||
package sealmgr
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-sectorbuilder"
|
||||
)
|
||||
|
||||
type LocalWorker struct {
|
||||
sectorbuilder.Basic
|
||||
}
|
||||
|
||||
var _ Worker = &LocalWorker{}
|
Loading…
Reference in New Issue
Block a user