2020-04-27 20:43:42 +00:00
|
|
|
package sectorstorage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/sector-storage/sealtasks"
|
|
|
|
"github.com/filecoin-project/sector-storage/stores"
|
|
|
|
)
|
|
|
|
|
|
|
|
type taskSelector struct {
|
2020-05-01 16:31:34 +00:00
|
|
|
best []stores.StorageInfo //nolint: unused, structcheck
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newTaskSelector() *taskSelector {
|
|
|
|
return &taskSelector{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *taskSelector) Ok(ctx context.Context, task sealtasks.TaskType, whnd *workerHandle) (bool, error) {
|
|
|
|
tasks, err := whnd.w.TaskTypes(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("getting supported worker task types: %w", err)
|
|
|
|
}
|
|
|
|
_, supported := tasks[task]
|
|
|
|
|
|
|
|
return supported, nil
|
|
|
|
}
|
|
|
|
|
2020-04-28 10:31:08 +00:00
|
|
|
func (s *taskSelector) Cmp(ctx context.Context, _ sealtasks.TaskType, a, b *workerHandle) (bool, error) {
|
2020-04-27 20:43:42 +00:00
|
|
|
atasks, err := a.w.TaskTypes(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("getting supported worker task types: %w", err)
|
|
|
|
}
|
|
|
|
btasks, err := b.w.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
|
|
|
|
}
|
|
|
|
|
2020-04-29 14:04:05 +00:00
|
|
|
return a.active.utilization(a.info.Resources) < b.active.utilization(b.info.Resources), nil
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ WorkerSelector = &allocSelector{}
|