lotus/extern/sector-storage/selector_task.go

50 lines
1.3 KiB
Go
Raw Normal View History

package sectorstorage
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/extern/sector-storage/sealtasks"
2022-01-18 10:57:04 +00:00
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
)
type taskSelector struct {
2022-01-18 10:57:04 +00:00
best []storiface.StorageInfo //nolint: unused, structcheck
}
func newTaskSelector() *taskSelector {
return &taskSelector{}
}
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)
if err != nil {
return false, xerrors.Errorf("getting supported worker task types: %w", err)
}
_, supported := tasks[task]
return supported, nil
}
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)
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{}