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-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
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.
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) Inhume(prm InhumePrm) (InhumeRes, error) {
|
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 {
|
|
|
|
_ = s.writeCache.Delete(prm.target[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-05-26 17:38:32 +00:00
|
|
|
res, err := s.metaBase.Inhume(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
|
|
|
|
}
|
|
|
|
|
2020-12-01 07:40:58 +00:00
|
|
|
s.log.Debug("could not mark object to delete in metabase",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
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()
|
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
s.decObjectCounterBy(logical, res.AvailableInhumed())
|
|
|
|
|
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 {
|
|
|
|
s.deletedLockCallBack(context.Background(), deletedLockObjs)
|
|
|
|
}
|
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return InhumeRes{}, nil
|
2020-12-01 07:40:58 +00:00
|
|
|
}
|