2020-11-25 09:40:41 +00:00
|
|
|
package blobstor
|
|
|
|
|
2020-11-25 11:18:54 +00:00
|
|
|
import (
|
2022-07-06 12:10:21 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
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) {
|
2022-11-15 12:33:48 +00:00
|
|
|
b.modeMtx.RLock()
|
|
|
|
defer b.modeMtx.RUnlock()
|
|
|
|
|
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-08 11:33:49 +00:00
|
|
|
var errors []error
|
|
|
|
for i := range b.storage {
|
|
|
|
res, err := b.storage[i].Storage.Exists(prm)
|
|
|
|
if err == nil && res.Exists {
|
|
|
|
return res, nil
|
|
|
|
} else if err != nil {
|
|
|
|
errors = append(errors, err)
|
2022-03-03 14:16:49 +00:00
|
|
|
}
|
2020-11-25 11:18:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 11:33:49 +00:00
|
|
|
if len(errors) == 0 {
|
|
|
|
return common.ExistsRes{}, nil
|
|
|
|
}
|
2020-11-25 11:18:54 +00:00
|
|
|
|
2022-07-08 11:33:49 +00:00
|
|
|
for _, err := range errors[:len(errors)-1] {
|
2022-10-17 12:33:41 +00:00
|
|
|
b.log.Warn("error occurred during object existence checking",
|
2022-07-08 11:33:49 +00:00
|
|
|
zap.Stringer("address", prm.Address),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
2020-11-25 11:18:54 +00:00
|
|
|
|
2022-07-08 11:33:49 +00:00
|
|
|
return common.ExistsRes{}, errors[len(errors)-1]
|
2020-11-25 11:18:54 +00:00
|
|
|
}
|