forked from TrueCloudLab/frostfs-node
[#1681] ir/netmap: Check MAINTENANCE state in UpdateState
Storage node can be requested to be switched into `MAINTENANCE` state. Inner Ring should accept such requests only if network configuration allows it. Make `Processor` of Netmap contract's notifications to depend on `state.NetworkSettings`. Make `Processor.processUpdatePeer` to call `MaintenanceModeAllowed` if notification event relates to `MAINTENANCE` mode`. Share singe `state.NetworkSettings` provider in Inner Ring application. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
bdb8243a5a
commit
6a2ec21641
3 changed files with 30 additions and 2 deletions
|
@ -690,8 +690,10 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<-
|
|||
}
|
||||
}
|
||||
|
||||
netSettings := (*networkSettings)(server.netmapClient)
|
||||
|
||||
var netMapCandidateStateValidator statevalidation.NetMapCandidateValidator
|
||||
netMapCandidateStateValidator.SetNetworkSettings((*networkSettings)(server.netmapClient))
|
||||
netMapCandidateStateValidator.SetNetworkSettings(netSettings)
|
||||
|
||||
// create netmap processor
|
||||
server.netmapProcessor, err = netmap.New(&netmap.Params{
|
||||
|
@ -722,6 +724,8 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<-
|
|||
),
|
||||
NotaryDisabled: server.sideNotaryConfig.disabled,
|
||||
SubnetContract: &server.contracts.subnet,
|
||||
|
||||
NodeStateSettings: netSettings,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -107,14 +107,29 @@ func (np *Processor) processUpdatePeer(ev netmapEvent.UpdatePeer) {
|
|||
|
||||
var err error
|
||||
|
||||
if ev.Maintenance() {
|
||||
err = np.nodeStateSettings.MaintenanceModeAllowed()
|
||||
if err != nil {
|
||||
np.log.Info("prevent switching node to maintenance state",
|
||||
zap.Error(err),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if nr := ev.NotaryRequest(); nr != nil {
|
||||
err = np.netmapClient.Morph().NotarySignAndInvokeTX(nr.MainTransaction)
|
||||
} else {
|
||||
prm := netmapclient.UpdatePeerPrm{}
|
||||
|
||||
if ev.Online() {
|
||||
switch {
|
||||
case ev.Online():
|
||||
prm.SetOnline()
|
||||
case ev.Maintenance():
|
||||
prm.SetMaintenance()
|
||||
}
|
||||
|
||||
prm.SetKey(ev.PublicKey().Bytes())
|
||||
|
||||
err = np.netmapClient.UpdatePeerState(prm)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap/nodevalidation/state"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
||||
nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
|
@ -74,6 +75,8 @@ type (
|
|||
nodeValidator NodeValidator
|
||||
|
||||
notaryDisabled bool
|
||||
|
||||
nodeStateSettings state.NetworkSettings
|
||||
}
|
||||
|
||||
// Params of the processor constructor.
|
||||
|
@ -97,6 +100,8 @@ type (
|
|||
NodeValidator NodeValidator
|
||||
|
||||
NotaryDisabled bool
|
||||
|
||||
NodeStateSettings state.NetworkSettings
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -132,6 +137,8 @@ func New(p *Params) (*Processor, error) {
|
|||
return nil, errors.New("ir/netmap: node validator is not set")
|
||||
case p.SubnetContract == nil:
|
||||
return nil, errors.New("ir/netmap: subnet contract script hash is not set")
|
||||
case p.NodeStateSettings == nil:
|
||||
return nil, errors.New("ir/netmap: node state settings is not set")
|
||||
}
|
||||
|
||||
p.Log.Debug("netmap worker pool", zap.Int("size", p.PoolSize))
|
||||
|
@ -162,6 +169,8 @@ func New(p *Params) (*Processor, error) {
|
|||
nodeValidator: p.NodeValidator,
|
||||
|
||||
notaryDisabled: p.NotaryDisabled,
|
||||
|
||||
nodeStateSettings: p.NodeStateSettings,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue