2022-07-05 13:47:39 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
2022-07-05 13:47:39 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2022-07-08 07:09:48 +00:00
|
|
|
// Exists implements common.Storage.
|
2022-07-06 12:10:21 +00:00
|
|
|
func (b *Blobovniczas) Exists(prm common.ExistsPrm) (common.ExistsRes, error) {
|
2022-11-17 06:29:35 +00:00
|
|
|
if prm.StorageID != nil {
|
|
|
|
id := blobovnicza.NewIDFromBytes(prm.StorageID)
|
|
|
|
blz, err := b.openBlobovnicza(id.String())
|
|
|
|
if err != nil {
|
|
|
|
return common.ExistsRes{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
exists, err := blz.Exists(prm.Address)
|
|
|
|
return common.ExistsRes{Exists: exists}, err
|
|
|
|
}
|
|
|
|
|
2022-07-05 13:47:39 +00:00
|
|
|
activeCache := make(map[string]struct{})
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
var gPrm blobovnicza.GetPrm
|
|
|
|
gPrm.SetAddress(prm.Address)
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
var found bool
|
2022-07-06 12:10:21 +00:00
|
|
|
err := b.iterateSortedLeaves(&prm.Address, func(p string) (bool, error) {
|
2022-07-05 13:47:39 +00:00
|
|
|
dirPath := filepath.Dir(p)
|
|
|
|
|
|
|
|
_, ok := activeCache[dirPath]
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
_, err := b.getObjectFromLevel(gPrm, p, !ok)
|
2022-07-05 13:47:39 +00:00
|
|
|
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
|
|
|
|
})
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
return common.ExistsRes{Exists: found}, err
|
2022-07-05 13:47:39 +00:00
|
|
|
}
|