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"
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2020-12-01 09:35:42 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
2022-02-15 22:24:43 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2021-11-10 07:08:33 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
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
|
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) {
|
2020-12-01 09:35:42 +00:00
|
|
|
if p != nil {
|
2021-02-19 14:01:01 +00:00
|
|
|
p.addrs = addrs
|
2022-05-31 17:00:41 +00:00
|
|
|
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) {
|
2021-02-19 14:08:41 +00:00
|
|
|
if p != nil {
|
|
|
|
p.addrs = addrs
|
|
|
|
p.tombstone = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
//
|
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
|
2020-12-01 09:35:42 +00:00
|
|
|
|
2021-02-19 14:01:01 +00:00
|
|
|
for i := range prm.addrs {
|
2021-02-19 14:08:41 +00:00
|
|
|
if prm.tombstone != nil {
|
2022-05-31 17:00:41 +00:00
|
|
|
shPrm.WithTarget(*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-02-15 22:24:43 +00:00
|
|
|
switch e.inhumeAddr(prm.addrs[i], shPrm, true) {
|
|
|
|
case 1:
|
2022-05-31 11:56:59 +00:00
|
|
|
return InhumeRes{}, apistatus.ObjectLocked{}
|
2022-02-15 22:24:43 +00:00
|
|
|
case 0:
|
|
|
|
switch e.inhumeAddr(prm.addrs[i], shPrm, false) {
|
|
|
|
case 1:
|
2022-05-31 11:56:59 +00:00
|
|
|
return InhumeRes{}, apistatus.ObjectLocked{}
|
2022-02-15 22:24:43 +00:00
|
|
|
case 0:
|
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-02-15 22:24:43 +00:00
|
|
|
// Returns:
|
|
|
|
// 0 - fail
|
|
|
|
// 1 - object locked
|
|
|
|
// 2 - ok
|
2022-05-20 18:08:59 +00:00
|
|
|
func (e *StorageEngine) inhumeAddr(addr oid.Address, prm shard.InhumePrm, checkExists bool) (status uint8) {
|
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
|
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-05-20 18:08:59 +00:00
|
|
|
existPrm.WithAddress(addr)
|
|
|
|
exRes, err := sh.Exists(existPrm)
|
2021-02-11 15:43:50 +00:00
|
|
|
if err != nil {
|
2022-03-17 08:03:58 +00:00
|
|
|
if shard.IsErrRemoved(err) {
|
2021-05-20 14:31:47 +00:00
|
|
|
// inhumed once - no need to be inhumed again
|
2022-02-15 22:24:43 +00:00
|
|
|
status = 2
|
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-01-31 14:58:32 +00:00
|
|
|
e.reportShardError(sh, "could not inhume object in shard", err)
|
2022-02-15 22:24:43 +00:00
|
|
|
|
|
|
|
if errors.As(err, &errLocked) {
|
|
|
|
status = 1
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-15 22:24:43 +00:00
|
|
|
status = 2
|
|
|
|
|
|
|
|
return true
|
2020-12-01 09:35:42 +00:00
|
|
|
})
|
|
|
|
|
2021-02-11 15:43:50 +00:00
|
|
|
return
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
2021-02-17 12:27:40 +00:00
|
|
|
|
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
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (e *StorageEngine) processExpiredLocks(ctx context.Context, lockers []oid.Address) {
|
2022-03-10 17:58:58 +00:00
|
|
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
|
|
|
sh.HandleExpiredLocks(lockers)
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
e.log.Info("interrupt processing the expired locks by context")
|
|
|
|
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():
|
|
|
|
e.log.Info("interrupt processing the deleted locks by context")
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|