2020-08-17 13:26:18 +00:00
|
|
|
package sectorstorage
|
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
|
|
|
|
2020-08-17 13:26:18 +00:00
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/sealtasks"
|
2022-01-18 10:57:04 +00:00
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/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-05-18 13:47:08 +00:00
|
|
|
func (s *taskSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, whnd *WorkerHandle) (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 {
|
|
|
|
return false, xerrors.Errorf("getting supported worker task types: %w", err)
|
|
|
|
}
|
|
|
|
_, supported := tasks[task]
|
|
|
|
|
|
|
|
return supported, nil
|
|
|
|
}
|
|
|
|
|
2022-05-18 13:47:08 +00:00
|
|
|
func (s *taskSelector) Cmp(ctx context.Context, _ sealtasks.TaskType, a, b *WorkerHandle) (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{}
|