2020-12-01 07:40:58 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2022-05-26 17:38:32 +00:00
|
|
|
"context"
|
2022-02-15 22:19:50 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-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 17:00:41 +00:00
|
|
|
target []oid.Address
|
|
|
|
tombstone *oid.Address
|
2020-12-01 07:40:58 +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 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-05-20 18:08:59 +00:00
|
|
|
func (p *InhumePrm) WithTarget(tombstone oid.Address, addrs ...oid.Address) {
|
2020-12-01 07:40:58 +00:00
|
|
|
if p != nil {
|
2021-02-15 12:02:22 +00:00
|
|
|
p.target = addrs
|
2022-05-31 17:00:41 +00:00
|
|
|
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.
|
|
|
|
//
|
|
|
|
// Should not be called along with WithTarget.
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-03-17 11:55:25 +00:00
|
|
|
if s.GetMode() != ModeReadWrite {
|
2022-05-31 11:50:39 +00:00
|
|
|
return InhumeRes{}, ErrReadOnlyMode
|
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
|
|
|
|
metaPrm.WithAddresses(prm.target...)
|
2022-05-26 17:38:32 +00:00
|
|
|
metaPrm.WithLockObjectHandling()
|
2021-02-15 11:32:49 +00:00
|
|
|
|
|
|
|
if prm.tombstone != nil {
|
2022-05-31 17:00:41 +00:00
|
|
|
metaPrm.WithTombstoneAddress(*prm.tombstone)
|
2021-02-15 11:32:49 +00:00
|
|
|
} else {
|
|
|
|
metaPrm.WithGCMark()
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
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-05-31 11:50:39 +00:00
|
|
|
return InhumeRes{}, fmt.Errorf("metabase inhume: %w", err)
|
2020-12-01 07:40:58 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|