lotus/extern/sector-storage/selector_existing.go

69 lines
1.7 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"
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
2020-09-30 17:32:19 +00:00
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
)
type existingSelector struct {
2020-08-05 20:11:53 +00:00
index stores.SectorIndex
sector abi.SectorID
2020-09-06 16:54:00 +00:00
alloc storiface.SectorFileType
2020-08-05 12:36:49 +00:00
allowFetch bool
}
2020-09-06 16:54:00 +00:00
func newExistingSelector(index stores.SectorIndex, sector abi.SectorID, alloc storiface.SectorFileType, allowFetch bool) *existingSelector {
return &existingSelector{
2020-08-05 20:11:53 +00:00
index: index,
sector: sector,
alloc: alloc,
2020-08-05 12:36:49 +00:00
allowFetch: allowFetch,
}
}
2020-06-15 12:32:17 +00:00
func (s *existingSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, whnd *workerHandle) (bool, error) {
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-08-11 07:27:03 +00:00
best, err := s.index.StorageFindSector(ctx, s.sector, s.alloc, spt, s.allowFetch)
2020-08-05 12:36:49 +00:00
if err != nil {
return false, xerrors.Errorf("finding best storage: %w", err)
}
for _, info := range best {
if _, ok := have[info.ID]; ok {
return true, nil
}
}
return false, nil
}
func (s *existingSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b *workerHandle) (bool, error) {
return a.utilization() < b.utilization(), nil
}
var _ WorkerSelector = &existingSelector{}