2020-12-01 09:35:42 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2021-02-11 15:43:50 +00:00
|
|
|
"errors"
|
|
|
|
|
2020-12-01 09:35:42 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// InhumePrm encapsulates parameters for inhume operation.
|
|
|
|
type InhumePrm struct {
|
|
|
|
addr, tombstone *objectSDK.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
// InhumeRes encapsulates results of inhume operation.
|
|
|
|
type InhumeRes struct{}
|
|
|
|
|
|
|
|
// WithTarget sets object address that should be inhumed and tombstone address
|
|
|
|
// as the reason for inhume operation.
|
|
|
|
func (p *InhumePrm) WithTarget(addr, tombstone *objectSDK.Address) *InhumePrm {
|
|
|
|
if p != nil {
|
|
|
|
p.addr = addr
|
|
|
|
p.tombstone = tombstone
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2021-02-11 15:43:50 +00:00
|
|
|
var errInhumeFailure = errors.New("inhume operation failed")
|
|
|
|
|
2020-12-01 09:35:42 +00:00
|
|
|
// Inhume calls metabase. Inhume method to mark object as removed. It won't be
|
|
|
|
// removed physically from shard until `Delete` operation.
|
|
|
|
func (e *StorageEngine) Inhume(prm *InhumePrm) (*InhumeRes, error) {
|
|
|
|
shPrm := new(shard.InhumePrm).WithTarget(prm.addr, prm.tombstone)
|
|
|
|
|
2021-02-11 15:43:50 +00:00
|
|
|
res := e.inhume(prm.addr, shPrm, true)
|
|
|
|
if res == nil {
|
|
|
|
res = e.inhume(prm.addr, shPrm, false)
|
|
|
|
if res == nil {
|
|
|
|
return nil, errInhumeFailure
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *StorageEngine) inhume(addr *objectSDK.Address, prm *shard.InhumePrm, checkExists bool) (res *InhumeRes) {
|
|
|
|
e.iterateOverSortedShards(addr, func(_ int, sh *shard.Shard) (stop bool) {
|
|
|
|
if checkExists {
|
|
|
|
exRes, err := sh.Exists(new(shard.ExistsPrm).
|
|
|
|
WithAddress(addr),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
// TODO: smth wrong with shard, need to be processed
|
|
|
|
e.log.Warn("could not check for presents in shard",
|
|
|
|
zap.Stringer("shard", sh.ID()),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
} else if !exRes.Exists() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := sh.Inhume(prm)
|
2020-12-01 09:35:42 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: smth wrong with shard, need to be processed
|
|
|
|
e.log.Warn("could not inhume object in shard",
|
|
|
|
zap.Stringer("shard", sh.ID()),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
2021-02-11 15:43:50 +00:00
|
|
|
} else {
|
|
|
|
res = new(InhumeRes)
|
2020-12-01 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 15:43:50 +00:00
|
|
|
return err == nil
|
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
|
|
|
}
|