2020-12-01 07:40:58 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2022-05-26 17:38:32 +00:00
|
|
|
"context"
|
2022-07-07 12:46:17 +00:00
|
|
|
"errors"
|
2022-02-15 22:19:50 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2023-09-27 08:02:06 +00:00
|
|
|
tracingPkg "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
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-12-01 07:40:58 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// InhumePrm encapsulates parameters for inhume operation.
|
|
|
|
type InhumePrm struct {
|
2022-05-31 20:11:42 +00:00
|
|
|
target []oid.Address
|
|
|
|
tombstone *oid.Address
|
|
|
|
forceRemoval bool
|
2020-12-01 07:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InhumeRes encapsulates results of inhume operation.
|
|
|
|
type InhumeRes struct{}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetTarget sets a list of objects that should be inhumed and tombstone address
|
2020-12-01 07:40:58 +00:00
|
|
|
// as the reason for inhume operation.
|
2021-02-15 11:32:49 +00:00
|
|
|
//
|
2021-02-15 12:02:22 +00:00
|
|
|
// tombstone should not be nil, addr should not be empty.
|
2021-02-15 11:32:49 +00:00
|
|
|
// Should not be called along with MarkAsGarbage.
|
2022-07-13 12:43:04 +00:00
|
|
|
func (p *InhumePrm) SetTarget(tombstone oid.Address, addrs ...oid.Address) {
|
|
|
|
p.target = addrs
|
|
|
|
p.tombstone = &tombstone
|
2020-12-01 07:40:58 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 11:32:49 +00:00
|
|
|
// MarkAsGarbage marks object to be physically removed from shard.
|
|
|
|
//
|
2022-07-13 12:43:04 +00:00
|
|
|
// Should not be called along with SetTarget.
|
2022-05-20 18:08:59 +00:00
|
|
|
func (p *InhumePrm) MarkAsGarbage(addr ...oid.Address) {
|
2021-02-15 11:32:49 +00:00
|
|
|
if p != nil {
|
|
|
|
p.target = addr
|
|
|
|
p.tombstone = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 20:11:42 +00:00
|
|
|
// ForceRemoval forces object removing despite any restrictions imposed
|
|
|
|
// on deleting that object. Expected to be used only in control service.
|
|
|
|
func (p *InhumePrm) ForceRemoval() {
|
|
|
|
if p != nil {
|
|
|
|
p.tombstone = nil
|
|
|
|
p.forceRemoval = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-07 12:46:17 +00:00
|
|
|
// ErrLockObjectRemoval is returned when inhume operation is being
|
|
|
|
// performed on lock object, and it is not a forced object removal.
|
|
|
|
var ErrLockObjectRemoval = meta.ErrLockObjectRemoval
|
|
|
|
|
2020-12-01 07:40:58 +00:00
|
|
|
// Inhume calls metabase. Inhume method to mark object as removed. It won't be
|
|
|
|
// removed physically from blobStor and metabase until `Delete` operation.
|
2021-12-27 11:04:07 +00:00
|
|
|
//
|
2022-02-15 22:19:50 +00:00
|
|
|
// Allows inhuming non-locked objects only. Returns apistatus.ObjectLocked
|
|
|
|
// if at least one object is locked.
|
|
|
|
//
|
2021-12-27 11:04:07 +00:00
|
|
|
// Returns ErrReadOnlyMode error if shard is in "read-only" mode.
|
2023-04-04 11:40:01 +00:00
|
|
|
func (s *Shard) Inhume(ctx context.Context, prm InhumePrm) (InhumeRes, error) {
|
2023-04-12 14:01:29 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.Inhume",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
|
|
|
|
if s.info.Mode.ReadOnly() {
|
|
|
|
s.m.RUnlock()
|
2022-05-31 11:50:39 +00:00
|
|
|
return InhumeRes{}, ErrReadOnlyMode
|
2022-12-07 17:42:35 +00:00
|
|
|
} else if s.info.Mode.NoMetabase() {
|
|
|
|
s.m.RUnlock()
|
2022-06-29 11:27:36 +00:00
|
|
|
return InhumeRes{}, ErrDegradedMode
|
2021-12-27 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 10:56:06 +00:00
|
|
|
if s.hasWriteCache() {
|
|
|
|
for i := range prm.target {
|
2023-04-12 14:01:29 +00:00
|
|
|
_ = s.writeCache.Delete(ctx, prm.target[i])
|
2021-04-06 10:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var metaPrm meta.InhumePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
metaPrm.SetAddresses(prm.target...)
|
|
|
|
metaPrm.SetLockObjectHandling()
|
2021-02-15 11:32:49 +00:00
|
|
|
|
|
|
|
if prm.tombstone != nil {
|
2022-07-12 14:59:37 +00:00
|
|
|
metaPrm.SetTombstoneAddress(*prm.tombstone)
|
2021-02-15 11:32:49 +00:00
|
|
|
} else {
|
2022-07-12 14:59:37 +00:00
|
|
|
metaPrm.SetGCMark()
|
2021-02-15 11:32:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 20:11:42 +00:00
|
|
|
if prm.forceRemoval {
|
2022-07-12 14:59:37 +00:00
|
|
|
metaPrm.SetForceGCMark()
|
2022-05-31 20:11:42 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err := s.metaBase.Inhume(ctx, metaPrm)
|
2020-12-01 07:40:58 +00:00
|
|
|
if err != nil {
|
2022-07-07 12:46:17 +00:00
|
|
|
if errors.Is(err, meta.ErrLockObjectRemoval) {
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RUnlock()
|
2022-07-07 12:46:17 +00:00
|
|
|
return InhumeRes{}, ErrLockObjectRemoval
|
|
|
|
}
|
|
|
|
|
2024-10-21 07:22:54 +00:00
|
|
|
s.log.Debug(ctx, logs.ShardCouldNotMarkObjectToDeleteInMetabase,
|
2020-12-01 07:40:58 +00:00
|
|
|
zap.String("error", err.Error()),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)),
|
2020-12-01 07:40:58 +00:00
|
|
|
)
|
2022-02-15 22:19:50 +00:00
|
|
|
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RUnlock()
|
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return InhumeRes{}, fmt.Errorf("metabase inhume: %w", err)
|
2020-12-01 07:40:58 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RUnlock()
|
|
|
|
|
2023-12-25 07:15:26 +00:00
|
|
|
s.decObjectCounterBy(logical, res.LogicInhumed())
|
2023-12-05 14:00:16 +00:00
|
|
|
s.decObjectCounterBy(user, res.UserInhumed())
|
2023-11-02 10:50:52 +00:00
|
|
|
s.decContainerObjectCounter(res.InhumedByCnrID())
|
2022-09-09 11:36:34 +00:00
|
|
|
|
2023-02-02 20:28:42 +00:00
|
|
|
i := 0
|
|
|
|
for i < res.GetDeletionInfoLength() {
|
|
|
|
delInfo := res.GetDeletionInfoByIndex(i)
|
|
|
|
s.addToContainerSize(delInfo.CID.EncodeToString(), -int64(delInfo.Size))
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
2022-05-26 17:38:32 +00:00
|
|
|
if deletedLockObjs := res.DeletedLockObjects(); len(deletedLockObjs) != 0 {
|
2023-04-04 11:40:01 +00:00
|
|
|
s.deletedLockCallBack(ctx, deletedLockObjs)
|
2022-05-26 17:38:32 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return InhumeRes{}, nil
|
2020-12-01 07:40:58 +00:00
|
|
|
}
|