[#842] object/delete: Set tombstone local node as tombstone owner

All objects in NeoFS must have owner ID. In previous implementation Object
Delete service handler set owner ID from request session token. If removal
was executed w/o a session, object with tombstone was prepared incorrectly.
In order to fix this node should set its own ID and become an owner of the
tombstone object.

Extend `NetworkInfo` interface required by Object.Delete handler with
`LocalNodeID` method which returns `owner.ID` of the local node. Implement
the method on `networkState` component of storage node application which is
updated on each node state change in NeoFS network map. Set owner returned
by `LocalNodeID` call as tombstone object's owner in Delete handler.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-11-08 15:10:49 +03:00 committed by Alex Vanin
parent d421022547
commit 0ec8f529ab
4 changed files with 35 additions and 3 deletions

View file

@ -13,6 +13,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
apiclient "github.com/nspcc-dev/neofs-api-go/pkg/client" apiclient "github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap" netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
apiclientconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/apiclient" apiclientconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/apiclient"
@ -77,6 +78,8 @@ type cfg struct {
key *keys.PrivateKey key *keys.PrivateKey
ownerIDFromKey *owner.ID // owner ID calculated from key
apiVersion *pkg.Version apiVersion *pkg.Version
cfgGRPC cfgGRPC cfgGRPC cfgGRPC
@ -221,9 +224,15 @@ func initCfg(path string) *cfg {
key := nodeconfig.Key(appCfg) key := nodeconfig.Key(appCfg)
neo3Wallet, err := owner.NEO3WalletFromPublicKey(&key.PrivateKey.PublicKey)
fatalOnErr(err)
ownerIDFromKey := owner.NewID()
ownerIDFromKey.SetNeo3Wallet(neo3Wallet)
var logPrm logger.Prm var logPrm logger.Prm
err := logPrm.SetLevelString( err = logPrm.SetLevelString(
loggerconfig.Level(appCfg), loggerconfig.Level(appCfg),
) )
fatalOnErr(err) fatalOnErr(err)
@ -297,6 +306,8 @@ func initCfg(path string) *cfg {
apiclient.WithDialTimeout(apiclientconfig.DialTimeout(appCfg)), apiclient.WithDialTimeout(apiclientconfig.DialTimeout(appCfg)),
), ),
persistate: persistate, persistate: persistate,
ownerIDFromKey: ownerIDFromKey,
} }
if metricsconfig.Address(c.appCfg) != "" { if metricsconfig.Address(c.appCfg) != "" {

View file

@ -120,14 +120,22 @@ func (r *localObjectInhumer) DeleteObjects(ts *objectSDK.Address, addr ...*objec
type delNetInfo struct { type delNetInfo struct {
netmap.State netmap.State
tsLifetime uint64 tsLifetime uint64
cfg *cfg
} }
func (i *delNetInfo) TombstoneLifetime() (uint64, error) { func (i *delNetInfo) TombstoneLifetime() (uint64, error) {
return i.tsLifetime, nil return i.tsLifetime, nil
} }
// returns node owner ID calculated from configured private key.
//
// Implements method needed for Object.Delete service.
func (i *delNetInfo) LocalNodeID() *owner.ID {
return i.cfg.ownerIDFromKey
}
type innerRingFetcherWithNotary struct { type innerRingFetcherWithNotary struct {
sidechain *morphClient.Client sidechain *morphClient.Client
} }
@ -334,6 +342,8 @@ func initObjectService(c *cfg) {
deletesvc.WithNetworkInfo(&delNetInfo{ deletesvc.WithNetworkInfo(&delNetInfo{
State: c.cfgNetmap.state, State: c.cfgNetmap.state,
tsLifetime: 5, tsLifetime: 5,
cfg: c,
}), }),
) )

View file

@ -232,9 +232,15 @@ func (exec *execCtx) initTombstoneObject() bool {
return false return false
} }
tombOwnerID := exec.commonParameters().SessionToken().OwnerID()
if tombOwnerID == nil {
// make local node a tombstone object owner
tombOwnerID = exec.svc.netInfo.LocalNodeID()
}
exec.tombstoneObj = object.NewRaw() exec.tombstoneObj = object.NewRaw()
exec.tombstoneObj.SetContainerID(exec.containerID()) exec.tombstoneObj.SetContainerID(exec.containerID())
exec.tombstoneObj.SetOwnerID(exec.commonParameters().SessionToken().OwnerID()) exec.tombstoneObj.SetOwnerID(tombOwnerID)
exec.tombstoneObj.SetType(objectSDK.TypeTombstone) exec.tombstoneObj.SetType(objectSDK.TypeTombstone)
exec.tombstoneObj.SetPayload(payload) exec.tombstoneObj.SetPayload(payload)

View file

@ -2,6 +2,7 @@ package deletesvc
import ( import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get" getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
@ -25,6 +26,10 @@ type NetworkInfo interface {
// Must return the lifespan of the tombstones // Must return the lifespan of the tombstones
// in the NeoFS epochs. // in the NeoFS epochs.
TombstoneLifetime() (uint64, error) TombstoneLifetime() (uint64, error)
// Returns user ID of the local storage node. Result must not be nil.
// New tombstone objects will have the result as an owner ID if removal is executed w/o a session.
LocalNodeID() *owner.ID
} }
type cfg struct { type cfg struct {