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:25:52 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/paths"
|
2022-06-14 18:03:38 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
2022-06-15 10:06:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
2020-04-27 20:43:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type existingSelector struct {
|
2022-06-14 18:25:52 +00:00
|
|
|
index paths.SectorIndex
|
2020-08-05 20:11:53 +00:00
|
|
|
sector abi.SectorID
|
2022-07-01 16:02:10 +00:00
|
|
|
fileType storiface.SectorFileType
|
2024-04-01 18:19:00 +00:00
|
|
|
miner abi.ActorID
|
2020-08-05 12:36:49 +00:00
|
|
|
allowFetch bool
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2024-04-01 18:19:00 +00:00
|
|
|
func newExistingSelector(index paths.SectorIndex, sector abi.SectorID, alloc storiface.SectorFileType, miner abi.ActorID, allowFetch bool) *existingSelector {
|
2020-04-27 20:43:42 +00:00
|
|
|
return &existingSelector{
|
2020-08-05 20:11:53 +00:00
|
|
|
index: index,
|
|
|
|
sector: sector,
|
2022-07-01 16:02:10 +00:00
|
|
|
fileType: alloc,
|
2024-04-01 18:19:00 +00:00
|
|
|
miner: miner,
|
2020-08-05 12:36:49 +00:00
|
|
|
allowFetch: allowFetch,
|
|
|
|
}
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:21:56 +00:00
|
|
|
func (s *existingSelector) 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 20:56:11 +00:00
|
|
|
return false, false, xerrors.Errorf("getting supported worker task types: %w", err)
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
if _, supported := tasks[task]; !supported {
|
2022-05-23 20:56:11 +00:00
|
|
|
return false, false, nil
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:21:56 +00:00
|
|
|
paths, err := whnd.Paths(ctx)
|
2020-04-27 20:43:42 +00:00
|
|
|
if err != nil {
|
2022-05-23 20:56:11 +00:00
|
|
|
return false, false, xerrors.Errorf("getting worker paths: %w", err)
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 10:57:04 +00:00
|
|
|
have := map[storiface.ID]struct{}{}
|
2020-04-27 20:43:42 +00:00
|
|
|
for _, path := range paths {
|
|
|
|
have[path.ID] = struct{}{}
|
|
|
|
}
|
|
|
|
|
2020-10-21 01:30:56 +00:00
|
|
|
ssize, err := spt.SectorSize()
|
|
|
|
if err != nil {
|
2022-05-23 20:56:11 +00:00
|
|
|
return false, false, xerrors.Errorf("getting sector size: %w", err)
|
2020-10-21 01:30:56 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 16:02:10 +00:00
|
|
|
best, err := s.index.StorageFindSector(ctx, s.sector, s.fileType, ssize, s.allowFetch)
|
2020-08-05 12:36:49 +00:00
|
|
|
if err != nil {
|
2022-05-23 20:56:11 +00:00
|
|
|
return false, false, xerrors.Errorf("finding best storage: %w", err)
|
2020-08-05 12:36:49 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 16:02:10 +00:00
|
|
|
requested := s.fileType
|
|
|
|
|
2020-08-05 12:36:49 +00:00
|
|
|
for _, info := range best {
|
2020-04-27 20:43:42 +00:00
|
|
|
if _, ok := have[info.ID]; ok {
|
2022-07-01 16:02:10 +00:00
|
|
|
// we're not putting new sector files anywhere
|
|
|
|
if !s.allowFetch {
|
|
|
|
return true, false, nil
|
|
|
|
}
|
|
|
|
|
2022-07-12 11:09:20 +00:00
|
|
|
requested = requested.SubAllowed(info.AllowTypes, info.DenyTypes)
|
2022-07-01 16:02:10 +00:00
|
|
|
|
|
|
|
// got all paths
|
|
|
|
if requested == storiface.FTNone {
|
|
|
|
break
|
|
|
|
}
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 16:02:10 +00:00
|
|
|
return requested == storiface.FTNone, false, nil
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:21:56 +00:00
|
|
|
func (s *existingSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b SchedWorker) (bool, error) {
|
2022-05-18 13:47:08 +00:00
|
|
|
return a.Utilization() < b.Utilization(), nil
|
2020-04-27 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ WorkerSelector = &existingSelector{}
|