2022-06-14 18:03:38 +00:00
|
|
|
package sealer
|
2020-04-27 20:43:42 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-05-08 16:54:06 +00:00
|
|
|
|
2022-06-14 18:03:38 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
2020-04-27 20:43:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type taskSelector struct {
|
2022-01-18 10:57:04 +00:00
|
|
|
best []storiface.StorageInfo //nolint: unused, structcheck
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2020-04-27 20:43:42 +00:00
|
|
|
if err != nil {
|
2022-05-23 21:27:28 +00:00
|
|
|
return false, false, xerrors.Errorf("getting supported worker task types: %w", err)
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
_, supported := tasks[task]
|
|
|
|
|
2022-05-23 21:27:28 +00:00
|
|
|
return supported, false, nil
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
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)
|
2020-04-27 20:43:42 +00:00
|
|
|
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)
|
2020-04-27 20:43:42 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-05-18 13:47:08 +00:00
|
|
|
return a.Utilization() < b.Utilization(), nil
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 01:20:48 +00:00
|
|
|
var _ WorkerSelector = &taskSelector{}
|