frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree/exists.go
Evgenii Stratonikov ca15083a50 [#1523] local_object_storage: Unify parameters for the Exists operation
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-08-22 13:14:19 +03:00

38 lines
922 B
Go

package blobovniczatree
import (
"path/filepath"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"go.uber.org/zap"
)
func (b *Blobovniczas) Exists(prm common.ExistsPrm) (common.ExistsRes, error) {
activeCache := make(map[string]struct{})
var gPrm blobovnicza.GetPrm
gPrm.SetAddress(prm.Address)
var found bool
err := b.iterateSortedLeaves(&prm.Address, func(p string) (bool, error) {
dirPath := filepath.Dir(p)
_, ok := activeCache[dirPath]
_, err := b.getObjectFromLevel(gPrm, p, !ok)
if err != nil {
if !blobovnicza.IsErrNotFound(err) {
b.log.Debug("could not get object from level",
zap.String("level", p),
zap.String("error", err.Error()))
}
}
activeCache[dirPath] = struct{}{}
found = err == nil
return found, nil
})
return common.ExistsRes{Exists: found}, err
}