lotus/storage/sealer/selector_existing.go

74 lines
1.9 KiB
Go
Raw 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 existingSelector struct {
index paths.SectorIndex
2020-08-05 20:11:53 +00:00
sector abi.SectorID
2020-09-06 16:54:00 +00:00
alloc storiface.SectorFileType
2020-08-05 12:36:49 +00:00
allowFetch bool
}
func newExistingSelector(index paths.SectorIndex, sector abi.SectorID, alloc storiface.SectorFileType, allowFetch bool) *existingSelector {
return &existingSelector{
2020-08-05 20:11:53 +00:00
index: index,
sector: sector,
alloc: alloc,
2020-08-05 12:36:49 +00:00
allowFetch: allowFetch,
}
}
func (s *existingSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, whnd *WorkerHandle) (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
}
2020-10-28 13:23:38 +00:00
paths, err := whnd.workerRpc.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)
}
best, err := s.index.StorageFindSector(ctx, s.sector, s.alloc, ssize, s.allowFetch)
2020-08-05 12:36:49 +00:00
if err != nil {
return false, false, xerrors.Errorf("finding best storage: %w", err)
2020-08-05 12:36:49 +00:00
}
for _, info := range best {
if _, ok := have[info.ID]; ok {
return true, false, nil
}
}
return false, false, nil
}
func (s *existingSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b *WorkerHandle) (bool, error) {
return a.Utilization() < b.Utilization(), nil
}
var _ WorkerSelector = &existingSelector{}