2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2024-09-03 09:18:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2024-09-03 09:18:10 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2023-04-12 14:01:29 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ExistsPrm groups the parameters of Exists operation.
|
|
|
|
type ExistsPrm struct {
|
2024-05-30 06:26:06 +00:00
|
|
|
// Exists option to set object checked for existence.
|
|
|
|
Address oid.Address
|
|
|
|
// Exists option to set parent object checked for existence.
|
2024-12-10 09:52:26 +00:00
|
|
|
ECParentAddress 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
|
2024-05-27 19:07:43 +00:00
|
|
|
lc bool
|
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
|
|
|
|
}
|
|
|
|
|
2024-05-27 19:07:43 +00:00
|
|
|
// Locked returns the fact that the object is locked.
|
|
|
|
func (p ExistsRes) Locked() bool {
|
|
|
|
return p.lc
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:23:15 +00:00
|
|
|
// 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.
|
2023-06-20 08:59:18 +00:00
|
|
|
// Returns the ErrShardDisabled if the shard is disabled.
|
2023-03-13 11:37:35 +00:00
|
|
|
func (s *Shard) Exists(ctx context.Context, prm ExistsPrm) (ExistsRes, error) {
|
2023-04-12 14:01:29 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.Exists",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
2024-05-30 06:26:06 +00:00
|
|
|
attribute.String("address", prm.Address.EncodeToString()),
|
2023-04-12 14:01:29 +00:00
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2022-06-29 11:27:36 +00:00
|
|
|
var exists bool
|
2024-05-27 19:07:43 +00:00
|
|
|
var locked bool
|
2022-06-29 11:27:36 +00:00
|
|
|
var err error
|
|
|
|
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
2023-06-20 08:59:18 +00:00
|
|
|
if s.info.Mode.Disabled() {
|
|
|
|
return ExistsRes{}, ErrShardDisabled
|
2024-09-03 09:18:10 +00:00
|
|
|
} else if s.info.EvacuationInProgress {
|
|
|
|
return ExistsRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound))
|
2023-06-20 08:59:18 +00:00
|
|
|
} else if s.info.Mode.NoMetabase() {
|
2022-07-06 12:10:21 +00:00
|
|
|
var p common.ExistsPrm
|
2024-05-30 06:26:06 +00:00
|
|
|
p.Address = prm.Address
|
2022-06-29 11:27:36 +00:00
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
var res common.ExistsRes
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err = s.blobStor.Exists(ctx, 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
|
2024-05-30 06:26:06 +00:00
|
|
|
existsPrm.SetAddress(prm.Address)
|
2024-12-10 09:52:26 +00:00
|
|
|
existsPrm.SetECParent(prm.ECParentAddress)
|
2022-06-29 11:27:36 +00:00
|
|
|
|
|
|
|
var res meta.ExistsRes
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err = s.metaBase.Exists(ctx, existsPrm)
|
2022-06-29 11:27:36 +00:00
|
|
|
exists = res.Exists()
|
2024-05-27 19:07:43 +00:00
|
|
|
locked = res.Locked()
|
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,
|
2024-05-27 19:07:43 +00:00
|
|
|
lc: locked,
|
2020-12-01 08:35:44 +00:00
|
|
|
}, err
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|