2020-12-01 09:35:42 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2021-02-17 12:27:40 +00:00
|
|
|
"context"
|
2021-02-11 15:43:50 +00:00
|
|
|
"errors"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2022-11-12 12:27:54 +00:00
|
|
|
"go.uber.org/zap"
|
2020-12-01 09:35:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// InhumePrm encapsulates parameters for inhume operation.
|
|
|
|
type InhumePrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
tombstone *oid.Address
|
|
|
|
addrs []oid.Address
|
2022-06-14 17:48:33 +00:00
|
|
|
|
|
|
|
forceRemoval bool
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InhumeRes encapsulates results of inhume operation.
|
|
|
|
type InhumeRes struct{}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WithTarget sets a list of objects that should be inhumed and tombstone address
|
2020-12-01 09:35:42 +00:00
|
|
|
// as the reason for inhume operation.
|
2021-02-19 14:01:01 +00:00
|
|
|
//
|
|
|
|
// tombstone should not be nil, addr should not be empty.
|
2021-02-19 14:08:41 +00:00
|
|
|
// Should not be called along with MarkAsGarbage.
|
2022-05-23 13:12:32 +00:00
|
|
|
func (p *InhumePrm) WithTarget(tombstone oid.Address, addrs ...oid.Address) {
|
2022-09-14 14:36:37 +00:00
|
|
|
p.addrs = addrs
|
|
|
|
p.tombstone = &tombstone
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// MarkAsGarbage marks an object to be physically removed from local storage.
|
2021-02-19 14:08:41 +00:00
|
|
|
//
|
|
|
|
// Should not be called along with WithTarget.
|
2022-05-23 13:12:32 +00:00
|
|
|
func (p *InhumePrm) MarkAsGarbage(addrs ...oid.Address) {
|
2022-09-14 14:36:37 +00:00
|
|
|
p.addrs = addrs
|
|
|
|
p.tombstone = nil
|
2021-02-19 14:08:41 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 17:48:33 +00:00
|
|
|
// WithForceRemoval inhumes objects specified via MarkAsGarbage with GC mark
|
|
|
|
// without any object restrictions checks.
|
|
|
|
func (p *InhumePrm) WithForceRemoval() {
|
2022-09-14 14:36:37 +00:00
|
|
|
p.forceRemoval = true
|
|
|
|
p.tombstone = nil
|
2022-06-14 17:48:33 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 15:43:50 +00:00
|
|
|
var errInhumeFailure = errors.New("inhume operation failed")
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Inhume calls metabase. Inhume method to mark an object as removed. It won't be
|
|
|
|
// removed physically from the shard until `Delete` operation.
|
2021-11-09 15:46:12 +00:00
|
|
|
//
|
2022-02-15 22:24:43 +00:00
|
|
|
// Allows inhuming non-locked objects only. Returns apistatus.ObjectLocked
|
|
|
|
// if at least one object is locked.
|
|
|
|
//
|
2022-07-07 12:33:27 +00:00
|
|
|
// NOTE: Marks any object as removed (despite any prohibitions on operations
|
|
|
|
// with that object) if WithForceRemoval option has been provided.
|
|
|
|
//
|
2021-11-09 15:46:12 +00:00
|
|
|
// Returns an error if executions are blocked (see BlockExecution).
|
2022-05-31 11:56:59 +00:00
|
|
|
func (e *StorageEngine) Inhume(prm InhumePrm) (res InhumeRes, err error) {
|
2021-11-10 15:00:30 +00:00
|
|
|
err = e.execIfNotBlocked(func() error {
|
2021-11-09 15:46:12 +00:00
|
|
|
res, err = e.inhume(prm)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-31 11:56:59 +00:00
|
|
|
func (e *StorageEngine) inhume(prm InhumePrm) (InhumeRes, error) {
|
2021-03-16 08:14:56 +00:00
|
|
|
if e.metrics != nil {
|
|
|
|
defer elapsed(e.metrics.AddInhumeDuration)()
|
2021-03-15 13:09:27 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var shPrm shard.InhumePrm
|
2022-06-14 17:48:33 +00:00
|
|
|
if prm.forceRemoval {
|
|
|
|
shPrm.ForceRemoval()
|
|
|
|
}
|
2020-12-01 09:35:42 +00:00
|
|
|
|
2021-02-19 14:01:01 +00:00
|
|
|
for i := range prm.addrs {
|
2022-11-12 12:27:54 +00:00
|
|
|
if !prm.forceRemoval {
|
2023-03-15 00:42:49 +00:00
|
|
|
locked, err := e.IsLocked(prm.addrs[i])
|
2022-11-12 12:27:54 +00:00
|
|
|
if err != nil {
|
|
|
|
e.log.Warn("removing an object without full locking check",
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Stringer("addr", prm.addrs[i]))
|
|
|
|
} else if locked {
|
|
|
|
var lockedErr apistatus.ObjectLocked
|
|
|
|
return InhumeRes{}, lockedErr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-19 14:08:41 +00:00
|
|
|
if prm.tombstone != nil {
|
2022-07-13 12:43:04 +00:00
|
|
|
shPrm.SetTarget(*prm.tombstone, prm.addrs[i])
|
2021-02-19 14:08:41 +00:00
|
|
|
} else {
|
|
|
|
shPrm.MarkAsGarbage(prm.addrs[i])
|
|
|
|
}
|
2021-02-19 14:01:01 +00:00
|
|
|
|
2022-10-05 10:48:09 +00:00
|
|
|
ok, err := e.inhumeAddr(prm.addrs[i], shPrm, true)
|
|
|
|
if err != nil {
|
|
|
|
return InhumeRes{}, err
|
|
|
|
}
|
|
|
|
if !ok {
|
|
|
|
ok, err := e.inhumeAddr(prm.addrs[i], shPrm, false)
|
|
|
|
if err != nil {
|
|
|
|
return InhumeRes{}, err
|
|
|
|
} else if !ok {
|
2022-05-31 11:56:59 +00:00
|
|
|
return InhumeRes{}, errInhumeFailure
|
2021-02-19 14:01:01 +00:00
|
|
|
}
|
2021-02-11 15:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 11:56:59 +00:00
|
|
|
return InhumeRes{}, nil
|
2021-02-11 15:43:50 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 10:48:09 +00:00
|
|
|
// Returns ok if object was inhumed during this invocation or before.
|
|
|
|
func (e *StorageEngine) inhumeAddr(addr oid.Address, prm shard.InhumePrm, checkExists bool) (bool, error) {
|
2021-05-20 14:31:47 +00:00
|
|
|
root := false
|
2022-02-15 22:24:43 +00:00
|
|
|
var errLocked apistatus.ObjectLocked
|
2022-05-20 18:08:59 +00:00
|
|
|
var existPrm shard.ExistsPrm
|
2022-10-05 10:48:09 +00:00
|
|
|
var retErr error
|
|
|
|
var ok bool
|
2021-05-20 14:31:47 +00:00
|
|
|
|
2022-01-31 14:58:32 +00:00
|
|
|
e.iterateOverSortedShards(addr, func(_ int, sh hashedShard) (stop bool) {
|
2021-05-20 14:31:47 +00:00
|
|
|
defer func() {
|
|
|
|
// if object is root we continue since information about it
|
|
|
|
// can be presented in other shards
|
|
|
|
if checkExists && root {
|
|
|
|
stop = false
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-02-11 15:43:50 +00:00
|
|
|
if checkExists {
|
2022-07-13 12:43:04 +00:00
|
|
|
existPrm.SetAddress(addr)
|
2022-05-20 18:08:59 +00:00
|
|
|
exRes, err := sh.Exists(existPrm)
|
2021-02-11 15:43:50 +00:00
|
|
|
if err != nil {
|
2022-07-27 18:38:28 +00:00
|
|
|
if shard.IsErrRemoved(err) || shard.IsErrObjectExpired(err) {
|
2021-05-20 14:31:47 +00:00
|
|
|
// inhumed once - no need to be inhumed again
|
2022-10-05 10:48:09 +00:00
|
|
|
ok = true
|
2021-05-20 14:31:47 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
var siErr *objectSDK.SplitInfoError
|
|
|
|
if !errors.As(err, &siErr) {
|
2022-01-31 14:58:32 +00:00
|
|
|
e.reportShardError(sh, "could not check for presents in shard", err)
|
2021-05-20 14:31:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
root = true
|
2021-02-11 15:43:50 +00:00
|
|
|
} else if !exRes.Exists() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := sh.Inhume(prm)
|
2020-12-01 09:35:42 +00:00
|
|
|
if err != nil {
|
2022-06-06 14:44:37 +00:00
|
|
|
switch {
|
|
|
|
case errors.As(err, &errLocked):
|
2022-10-05 10:48:09 +00:00
|
|
|
retErr = apistatus.ObjectLocked{}
|
2022-02-15 22:24:43 +00:00
|
|
|
return true
|
2022-07-07 12:46:17 +00:00
|
|
|
case errors.Is(err, shard.ErrLockObjectRemoval):
|
2022-10-05 10:48:09 +00:00
|
|
|
retErr = meta.ErrLockObjectRemoval
|
|
|
|
return true
|
|
|
|
case errors.Is(err, shard.ErrReadOnlyMode) || errors.Is(err, shard.ErrDegradedMode):
|
|
|
|
retErr = err
|
2022-06-06 14:44:37 +00:00
|
|
|
return true
|
2022-02-15 22:24:43 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 07:34:20 +00:00
|
|
|
e.reportShardError(sh, "could not inhume object in shard", err)
|
2022-02-15 22:24:43 +00:00
|
|
|
return false
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 10:48:09 +00:00
|
|
|
ok = true
|
2022-02-15 22:24:43 +00:00
|
|
|
return true
|
2020-12-01 09:35:42 +00:00
|
|
|
})
|
|
|
|
|
2022-10-05 10:48:09 +00:00
|
|
|
return ok, retErr
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
2021-02-17 12:27:40 +00:00
|
|
|
|
2023-03-15 00:42:49 +00:00
|
|
|
// IsLocked checks whether an object is locked according to StorageEngine's state.
|
|
|
|
func (e *StorageEngine) IsLocked(addr oid.Address) (bool, error) {
|
2022-11-12 12:27:54 +00:00
|
|
|
var locked bool
|
|
|
|
var err error
|
|
|
|
var outErr error
|
|
|
|
|
|
|
|
e.iterateOverUnsortedShards(func(h hashedShard) (stop bool) {
|
|
|
|
locked, err = h.Shard.IsLocked(addr)
|
|
|
|
if err != nil {
|
|
|
|
e.reportShardError(h, "can't check object's lockers", err, zap.Stringer("addr", addr))
|
|
|
|
outErr = err
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return locked
|
|
|
|
})
|
|
|
|
|
|
|
|
if locked {
|
|
|
|
return locked, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return locked, outErr
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
func (e *StorageEngine) processExpiredTombstones(ctx context.Context, addrs []meta.TombstonedObject) {
|
2022-01-31 14:58:32 +00:00
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
2022-04-19 18:00:22 +00:00
|
|
|
sh.HandleExpiredTombstones(addrs)
|
2021-02-17 12:27:40 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-03-10 17:58:58 +00:00
|
|
|
|
2023-03-28 08:17:15 +00:00
|
|
|
func (e *StorageEngine) processExpiredLocks(ctx context.Context, epoch uint64, lockers []oid.Address) {
|
2022-03-10 17:58:58 +00:00
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
2023-03-28 08:17:15 +00:00
|
|
|
sh.HandleExpiredLocks(ctx, epoch, lockers)
|
2022-03-10 17:58:58 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2023-03-28 14:58:28 +00:00
|
|
|
e.log.Info("interrupt processing the expired locks", zap.Error(ctx.Err()))
|
2022-03-10 17:58:58 +00:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-05-26 17:38:32 +00:00
|
|
|
|
|
|
|
func (e *StorageEngine) processDeletedLocks(ctx context.Context, lockers []oid.Address) {
|
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
|
|
|
sh.HandleDeletedLocks(lockers)
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2023-03-28 14:58:28 +00:00
|
|
|
e.log.Info("interrupt processing the deleted locks", zap.Error(ctx.Err()))
|
2022-05-26 17:38:32 +00:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|