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"
|
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
2020-04-27 20:43:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type allocSelector struct {
|
2020-05-08 16:54:06 +00:00
|
|
|
index stores.SectorIndex
|
|
|
|
alloc stores.SectorFileType
|
2020-06-03 21:44:59 +00:00
|
|
|
ptype stores.PathType
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 12:36:49 +00:00
|
|
|
func newAllocSelector(index stores.SectorIndex, alloc stores.SectorFileType, ptype stores.PathType) *allocSelector {
|
2020-04-27 20:43:42 +00:00
|
|
|
return &allocSelector{
|
2020-05-08 16:54:06 +00:00
|
|
|
index: index,
|
|
|
|
alloc: alloc,
|
2020-06-03 21:44:59 +00:00
|
|
|
ptype: ptype,
|
2020-07-16 21:41:04 +00:00
|
|
|
}
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 12:32:17 +00:00
|
|
|
func (s *allocSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, whnd *workerHandle) (bool, error) {
|
2020-04-27 20:43:42 +00:00
|
|
|
tasks, err := whnd.w.TaskTypes(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("getting supported worker task types: %w", err)
|
|
|
|
}
|
|
|
|
if _, supported := tasks[task]; !supported {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
paths, err := whnd.w.Paths(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("getting worker paths: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
have := map[stores.ID]struct{}{}
|
|
|
|
for _, path := range paths {
|
|
|
|
have[path.ID] = struct{}{}
|
|
|
|
}
|
|
|
|
|
2020-06-03 21:44:59 +00:00
|
|
|
best, err := s.index.StorageBestAlloc(ctx, s.alloc, spt, s.ptype)
|
2020-05-08 16:54:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("finding best alloc storage: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, info := range best {
|
2020-04-27 20:43:42 +00:00
|
|
|
if _, ok := have[info.ID]; ok {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *allocSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b *workerHandle) (bool, error) {
|
2020-08-31 11:31:11 +00:00
|
|
|
return a.utilization() < b.utilization(), nil
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ WorkerSelector = &allocSelector{}
|