consider storiface.PathStorage when calculating storage requirements

This commit is contained in:
Anton Evangelatov 2021-05-11 13:19:26 +02:00
parent bf10b051ff
commit e07438417c
2 changed files with 27 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package stores
import (
"context"
"errors"
"math"
"net/url"
gopath "path"
"sort"
@ -383,7 +384,14 @@ func (i *Index) StorageBestAlloc(ctx context.Context, allocate storiface.SectorF
var candidates []storageEntry
spaceReq, err := allocate.SealSpaceUse(ssize)
var err error
spaceReq := uint64(math.MaxUint64)
switch pathType {
case storiface.PathSealing:
spaceReq, err = allocate.SealSpaceUse(ssize)
case storiface.PathStorage:
spaceReq, err = allocate.StoreSpaceUse(ssize)
}
if err != nil {
return nil, xerrors.Errorf("estimating required space: %w", err)
}

View File

@ -73,6 +73,24 @@ func (t SectorFileType) SealSpaceUse(ssize abi.SectorSize) (uint64, error) {
return need, nil
}
func (t SectorFileType) StoreSpaceUse(ssize abi.SectorSize) (uint64, error) {
var need uint64
for _, pathType := range PathTypes {
if !t.Has(pathType) {
continue
}
oh, ok := FsOverheadFinalized[pathType]
if !ok {
return 0, xerrors.Errorf("no finalized overhead info for %s", pathType)
}
need += uint64(oh) * uint64(ssize) / FSOverheadDen
}
return need, nil
}
func (t SectorFileType) All() [FileTypes]bool {
var out [FileTypes]bool