2020-11-25 09:40:41 +00:00
|
|
|
package blobstor
|
|
|
|
|
2020-11-25 11:18:54 +00:00
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
2021-04-08 13:53:25 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
2022-03-03 14:16:49 +00:00
|
|
|
"go.uber.org/zap"
|
2020-11-25 11:18:54 +00:00
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Exists checks if the object is presented in BLOB storage.
|
2020-11-25 09:40:41 +00:00
|
|
|
//
|
|
|
|
// Returns any error encountered that did not allow
|
|
|
|
// to completely check object existence.
|
2022-07-06 12:10:21 +00:00
|
|
|
func (b *BlobStor) Exists(prm common.ExistsPrm) (common.ExistsRes, error) {
|
2020-11-25 11:18:54 +00:00
|
|
|
// check presence in shallow dir first (cheaper)
|
2022-07-06 12:10:21 +00:00
|
|
|
res, err := b.existsBig(prm)
|
2022-03-03 14:16:49 +00:00
|
|
|
|
|
|
|
// If there was an error during existence check below,
|
|
|
|
// it will be returned unless object was found in blobovnicza.
|
|
|
|
// Otherwise, it is logged and the latest error is returned.
|
|
|
|
// FSTree | Blobovnicza | Behaviour
|
|
|
|
// found | (not tried) | return true, nil
|
|
|
|
// not found | any result | return the result
|
|
|
|
// error | found | log the error, return true, nil
|
|
|
|
// error | not found | return the error
|
|
|
|
// error | error | log the first error, return the second
|
2022-07-06 12:10:21 +00:00
|
|
|
if !res.Exists {
|
2022-03-03 14:16:49 +00:00
|
|
|
var smallErr error
|
2020-11-25 11:18:54 +00:00
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
res, smallErr = b.existsSmall(prm)
|
|
|
|
if err != nil && (smallErr != nil || res.Exists) {
|
2022-03-03 14:16:49 +00:00
|
|
|
b.log.Warn("error occured during object existence checking",
|
2022-07-06 12:10:21 +00:00
|
|
|
zap.Stringer("address", prm.Address),
|
2022-03-03 14:16:49 +00:00
|
|
|
zap.String("error", err.Error()))
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
err = smallErr
|
|
|
|
}
|
2020-11-25 11:18:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
return res, err
|
2020-11-25 11:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// checks if object is presented in shallow dir.
|
2022-07-06 12:10:21 +00:00
|
|
|
func (b *BlobStor) existsBig(prm common.ExistsPrm) (common.ExistsRes, error) {
|
|
|
|
_, err := b.fsTree.Exists(prm.Address)
|
2021-04-08 13:53:25 +00:00
|
|
|
if errors.Is(err, fstree.ErrFileNotFound) {
|
2022-07-06 12:10:21 +00:00
|
|
|
return common.ExistsRes{}, nil
|
2020-11-25 11:18:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
return common.ExistsRes{Exists: err == nil}, err
|
2020-11-25 11:18:54 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 14:16:49 +00:00
|
|
|
// existsSmall checks if object is presented in blobovnicza.
|
2022-07-06 12:10:21 +00:00
|
|
|
func (b *BlobStor) existsSmall(prm common.ExistsPrm) (common.ExistsRes, error) {
|
|
|
|
return b.blobovniczas.Exists(prm)
|
2020-11-25 11:18:54 +00:00
|
|
|
}
|