lotus/storage/sealer/selector_task.go

49 lines
1.3 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/sealer/sealtasks"
"github.com/filecoin-project/lotus/storage/sealer/storiface"
)
type taskSelector struct {
2022-01-18 10:57:04 +00:00
best []storiface.StorageInfo //nolint: unused, structcheck
}
func newTaskSelector() *taskSelector {
return &taskSelector{}
}
2022-11-28 16:21:56 +00:00
func (s *taskSelector) 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 {
2022-05-23 21:27:28 +00:00
return false, false, xerrors.Errorf("getting supported worker task types: %w", err)
}
_, supported := tasks[task]
2022-05-23 21:27:28 +00:00
return supported, false, nil
}
2022-11-28 16:21:56 +00:00
func (s *taskSelector) Cmp(ctx context.Context, _ sealtasks.TaskType, a, b SchedWorker) (bool, error) {
2022-04-06 16:31:42 +00:00
atasks, err := a.TaskTypes(ctx)
if err != nil {
return false, xerrors.Errorf("getting supported worker task types: %w", err)
}
2022-04-06 16:31:42 +00:00
btasks, err := b.TaskTypes(ctx)
if err != nil {
return false, xerrors.Errorf("getting supported worker task types: %w", err)
}
if len(atasks) != len(btasks) {
return len(atasks) < len(btasks), nil // prefer workers which can do less
}
return a.Utilization() < b.Utilization(), nil
}
2020-11-03 01:20:48 +00:00
var _ WorkerSelector = &taskSelector{}