frostfs-node/pkg/local_object_storage/shard/exists.go
Anton Nikiforov 5717d86173
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 2m46s
DCO action / DCO (pull_request) Successful in 2m43s
Tests and linters / Tests (1.22) (pull_request) Successful in 2m59s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m6s
Vulncheck / Vulncheck (pull_request) Successful in 2m52s
Build / Build Components (1.22) (pull_request) Successful in 3m24s
Build / Build Components (1.23) (pull_request) Successful in 3m24s
Tests and linters / Lint (pull_request) Successful in 3m44s
Tests and linters / Staticcheck (pull_request) Successful in 3m48s
Tests and linters / Tests (1.23) (pull_request) Successful in 3m54s
Tests and linters / Tests with -race (pull_request) Successful in 4m33s
Tests and linters / gopls check (pull_request) Successful in 4m31s
[#1349] node: Evacuate objects without setting mode to MAINTENANCE
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2024-09-04 16:11:00 +03:00

89 lines
2.5 KiB
Go

package shard
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
// ExistsPrm groups the parameters of Exists operation.
type ExistsPrm struct {
// Exists option to set object checked for existence.
Address oid.Address
// Exists option to set parent object checked for existence.
ParentAddress oid.Address
}
// ExistsRes groups the resulting values of Exists operation.
type ExistsRes struct {
ex bool
lc bool
}
// Exists returns the fact that the object is in the shard.
func (p ExistsRes) Exists() bool {
return p.ex
}
// Locked returns the fact that the object is locked.
func (p ExistsRes) Locked() bool {
return p.lc
}
// Exists checks if object is presented in shard.
//
// Returns any error encountered that does not allow to
// unambiguously determine the presence of an object.
//
// Returns an error of type apistatus.ObjectAlreadyRemoved if object has been marked as removed.
// Returns the object.ErrObjectIsExpired if the object is presented but already expired.
// Returns the ErrShardDisabled if the shard is disabled.
func (s *Shard) Exists(ctx context.Context, prm ExistsPrm) (ExistsRes, error) {
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.Exists",
trace.WithAttributes(
attribute.String("shard_id", s.ID().String()),
attribute.String("address", prm.Address.EncodeToString()),
))
defer span.End()
var exists bool
var locked bool
var err error
s.m.RLock()
defer s.m.RUnlock()
if s.info.Mode.Disabled() {
return ExistsRes{}, ErrShardDisabled
} else if s.info.EvacuationInProgress {
return ExistsRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound))
} else if s.info.Mode.NoMetabase() {
var p common.ExistsPrm
p.Address = prm.Address
var res common.ExistsRes
res, err = s.blobStor.Exists(ctx, p)
exists = res.Exists
} else {
var existsPrm meta.ExistsPrm
existsPrm.SetAddress(prm.Address)
existsPrm.SetParent(prm.ParentAddress)
var res meta.ExistsRes
res, err = s.metaBase.Exists(ctx, existsPrm)
exists = res.Exists()
locked = res.Locked()
}
return ExistsRes{
ex: exists,
lc: locked,
}, err
}