Commit 3ed773dd authored by Łukasz Magiera's avatar Łukasz Magiera
Browse files

fs: better findBestPath errors

parent 6c13c17b
...@@ -145,8 +145,6 @@ func (f *FS) Init() error { ...@@ -145,8 +145,6 @@ func (f *FS) Init() error {
return nil return nil
} }
// TODO: fix the locking situation
func (f *FS) FindSector(typ DataType, miner address.Address, id uint64) (out SectorPath, err error) { func (f *FS) FindSector(typ DataType, miner address.Address, id uint64) (out SectorPath, err error) {
// TODO: consider keeping some sort of index at some point // TODO: consider keeping some sort of index at some point
...@@ -177,7 +175,7 @@ func (f *FS) FindSector(typ DataType, miner address.Address, id uint64) (out Sec ...@@ -177,7 +175,7 @@ func (f *FS) FindSector(typ DataType, miner address.Address, id uint64) (out Sec
return out, nil return out, nil
} }
func (f *FS) findBestPath(size uint64, cache bool, strict bool) StoragePath { func (f *FS) findBestPath(size uint64, cache bool, strict bool) (StoragePath, error) {
var best StoragePath var best StoragePath
bestw := big.NewInt(0) bestw := big.NewInt(0)
...@@ -211,7 +209,15 @@ func (f *FS) findBestPath(size uint64, cache bool, strict bool) StoragePath { ...@@ -211,7 +209,15 @@ func (f *FS) findBestPath(size uint64, cache bool, strict bool) StoragePath {
} }
} }
return best if best == "" {
if cache {
return best, xerrors.Errorf("no available cache: %w", ErrNoSuitablePath)
}
return best, xerrors.Errorf("no available storage: %w", ErrNoSuitablePath)
}
return best, nil
} }
func (f *FS) ForceAllocSector(typ DataType, miner address.Address, ssize uint64, cache bool, id uint64) (SectorPath, error) { func (f *FS) ForceAllocSector(typ DataType, miner address.Address, ssize uint64, cache bool, id uint64) (SectorPath, error) {
...@@ -247,9 +253,9 @@ func (f *FS) AllocSector(typ DataType, miner address.Address, ssize uint64, cach ...@@ -247,9 +253,9 @@ func (f *FS) AllocSector(typ DataType, miner address.Address, ssize uint64, cach
need := overheadMul[typ] * ssize need := overheadMul[typ] * ssize
p := f.findBestPath(need, cache, false) p, err := f.findBestPath(need, cache, false)
if p == "" { if err != nil {
return "", ErrNoSuitablePath return "", err
} }
sp := p.Sector(typ, miner, id) sp := p.Sector(typ, miner, id)
...@@ -258,10 +264,11 @@ func (f *FS) AllocSector(typ DataType, miner address.Address, ssize uint64, cach ...@@ -258,10 +264,11 @@ func (f *FS) AllocSector(typ DataType, miner address.Address, ssize uint64, cach
} }
func (f *FS) PrepareCacheMove(sector SectorPath, ssize uint64, tocache bool) (SectorPath, error) { func (f *FS) PrepareCacheMove(sector SectorPath, ssize uint64, tocache bool) (SectorPath, error) {
p := f.findBestPath(ssize, tocache, true) p, err := f.findBestPath(ssize, tocache, true)
if p == "" { if err != nil {
return "", ErrNoSuitablePath return "", err
} }
m, err := sector.miner() m, err := sector.miner()
if err != nil { if err != nil {
return "", err return "", err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment