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