2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
meta "github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ExistsPrm groups the parameters of Exists operation.
|
|
|
|
type ExistsPrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// ExistsRes groups the resulting values of Exists operation.
|
2020-11-17 12:23:15 +00:00
|
|
|
type ExistsRes struct {
|
|
|
|
ex bool
|
|
|
|
}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetAddress is an Exists option to set object checked for existence.
|
|
|
|
func (p *ExistsPrm) SetAddress(addr oid.Address) {
|
|
|
|
p.addr = addr
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Exists returns the fact that the object is in the shard.
|
2022-05-20 18:08:59 +00:00
|
|
|
func (p ExistsRes) Exists() bool {
|
2020-11-17 12:23:15 +00:00
|
|
|
return p.ex
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exists checks if object is presented in shard.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that does not allow to
|
|
|
|
// unambiguously determine the presence of an object.
|
2022-03-17 08:03:58 +00:00
|
|
|
//
|
2022-03-17 13:26:17 +00:00
|
|
|
// Returns an error of type apistatus.ObjectAlreadyRemoved if object has been marked as removed.
|
2022-07-27 18:38:28 +00:00
|
|
|
// Returns the object.ErrObjectIsExpired if the object is presented but already expired.
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) Exists(prm ExistsPrm) (ExistsRes, error) {
|
2022-06-29 11:27:36 +00:00
|
|
|
var exists bool
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if s.GetMode().NoMetabase() {
|
2022-07-06 12:10:21 +00:00
|
|
|
var p common.ExistsPrm
|
|
|
|
p.Address = prm.addr
|
2022-06-29 11:27:36 +00:00
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
var res common.ExistsRes
|
2022-06-29 11:27:36 +00:00
|
|
|
res, err = s.blobStor.Exists(p)
|
2022-07-06 12:10:21 +00:00
|
|
|
exists = res.Exists
|
2022-06-29 11:27:36 +00:00
|
|
|
} else {
|
|
|
|
var existsPrm meta.ExistsPrm
|
|
|
|
existsPrm.SetAddress(prm.addr)
|
|
|
|
|
|
|
|
var res meta.ExistsRes
|
|
|
|
res, err = s.metaBase.Exists(existsPrm)
|
|
|
|
exists = res.Exists()
|
2022-03-03 15:09:24 +00:00
|
|
|
}
|
2020-11-18 14:38:49 +00:00
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return ExistsRes{
|
2020-11-18 14:38:49 +00:00
|
|
|
ex: exists,
|
2020-12-01 08:35:44 +00:00
|
|
|
}, err
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|