Merge pull request #6233 from nonsense/fix-finalizesector-storage-req

consider storiface.PathStorage when calculating storage requirements
This commit is contained in:
Łukasz Magiera 2021-05-20 21:43:55 +02:00 committed by GitHub
commit 2d4eaf08c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package stores
import (
"context"
"errors"
"fmt"
"net/url"
gopath "path"
"sort"
@ -383,7 +384,16 @@ func (i *Index) StorageBestAlloc(ctx context.Context, allocate storiface.SectorF
var candidates []storageEntry
spaceReq, err := allocate.SealSpaceUse(ssize)
var err error
var spaceReq uint64
switch pathType {
case storiface.PathSealing:
spaceReq, err = allocate.SealSpaceUse(ssize)
case storiface.PathStorage:
spaceReq, err = allocate.StoreSpaceUse(ssize)
default:
panic(fmt.Sprintf("unexpected pathType: %s", pathType))
}
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