lotus/storage/sealer/selector_alloc.go

81 lines
2.0 KiB
Go
Raw Permalink Normal View History

package sealer
import (
"context"
"golang.org/x/xerrors"
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/storage/paths"
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
"github.com/filecoin-project/lotus/storage/sealer/storiface"
)
type allocSelector struct {
index paths.SectorIndex
2020-09-06 16:54:00 +00:00
alloc storiface.SectorFileType
ptype storiface.PathType
2024-04-01 18:19:00 +00:00
miner abi.ActorID
}
2024-04-01 18:19:00 +00:00
func newAllocSelector(index paths.SectorIndex, alloc storiface.SectorFileType, ptype storiface.PathType, miner abi.ActorID) *allocSelector {
return &allocSelector{
index: index,
alloc: alloc,
2020-06-03 21:44:59 +00:00
ptype: ptype,
2024-04-01 18:19:00 +00:00
miner: miner,
2020-07-16 21:41:04 +00:00
}
}
2022-11-28 16:21:56 +00:00
func (s *allocSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, whnd SchedWorker) (bool, bool, error) {
2022-04-06 16:31:42 +00:00
tasks, err := whnd.TaskTypes(ctx)
if err != nil {
return false, false, xerrors.Errorf("getting supported worker task types: %w", err)
}
if _, supported := tasks[task]; !supported {
return false, false, nil
}
2022-11-28 16:21:56 +00:00
paths, err := whnd.Paths(ctx)
if err != nil {
return false, false, xerrors.Errorf("getting worker paths: %w", err)
}
2022-01-18 10:57:04 +00:00
have := map[storiface.ID]struct{}{}
for _, path := range paths {
have[path.ID] = struct{}{}
}
ssize, err := spt.SectorSize()
if err != nil {
return false, false, xerrors.Errorf("getting sector size: %w", err)
}
2024-04-01 18:19:00 +00:00
best, err := s.index.StorageBestAlloc(ctx, s.alloc, ssize, s.ptype, s.miner)
if err != nil {
return false, false, xerrors.Errorf("finding best alloc storage: %w", err)
}
2022-07-01 16:02:10 +00:00
requested := s.alloc
for _, info := range best {
if _, ok := have[info.ID]; ok {
requested = requested.SubAllowed(info.AllowTypes, info.DenyTypes)
2022-07-01 16:02:10 +00:00
// got all paths
if requested == storiface.FTNone {
break
}
}
}
2022-07-01 16:02:10 +00:00
return requested == storiface.FTNone, false, nil
}
2022-11-28 16:21:56 +00:00
func (s *allocSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b SchedWorker) (bool, error) {
return a.Utilization() < b.Utilization(), nil
}
var _ WorkerSelector = &allocSelector{}