frostfs-node/pkg/innerring/processors/netmap/nodevalidation/state/validator.go
Alexander Chuprov 9b113c3156
Some checks failed
DCO action / DCO (pull_request) Successful in 59s
Vulncheck / Vulncheck (pull_request) Successful in 1m4s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m55s
Build / Build Components (pull_request) Successful in 2m4s
Tests and linters / Staticcheck (pull_request) Successful in 2m38s
Tests and linters / Lint (pull_request) Successful in 3m16s
Tests and linters / Run gofumpt (pull_request) Successful in 3m54s
Tests and linters / Tests (pull_request) Successful in 4m12s
Tests and linters / gopls check (pull_request) Successful in 4m31s
Tests and linters / Tests with -race (pull_request) Successful in 4m38s
OCI image / Build container images (push) Failing after 18s
Vulncheck / Vulncheck (push) Successful in 1m2s
Pre-commit hooks / Pre-commit (push) Successful in 1m39s
Build / Build Components (push) Successful in 1m45s
Tests and linters / Staticcheck (push) Successful in 2m18s
Tests and linters / Run gofumpt (push) Successful in 2m46s
Tests and linters / Lint (push) Successful in 3m5s
Tests and linters / Tests with -race (push) Successful in 3m23s
Tests and linters / Tests (push) Successful in 3m52s
Tests and linters / gopls check (push) Successful in 4m18s
[#1613] morph: Add tracing for morph queries to neo-go
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2025-02-05 16:38:20 +03:00

69 lines
2.5 KiB
Go

/*
Package state collects functionality for verifying states of network map members.
NetMapCandidateValidator type provides an interface for checking the network
map candidates.
*/
package state
import (
"context"
"errors"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
)
// ErrMaintenanceModeDisallowed is returned when maintenance mode is disallowed.
var ErrMaintenanceModeDisallowed = errors.New("maintenance mode is disallowed")
// NetworkSettings encapsulates current settings of the FrostFS network and
// provides interface used for processing the network map candidates.
type NetworkSettings interface {
// MaintenanceModeAllowed checks if maintenance state of the storage nodes
// is allowed to be set, and returns:
// no error if allowed;
// ErrMaintenanceModeDisallowed if disallowed;
// other error if there are any problems with the check.
MaintenanceModeAllowed(ctx context.Context) error
}
// NetMapCandidateValidator represents tool which checks state of nodes which
// are going to register in the FrostFS network (enter the network map).
//
// NetMapCandidateValidator can be instantiated using built-in var declaration
// and currently doesn't require any additional initialization.
//
// NetMapCandidateValidator implements
// github.com/nspcc-dev/frostfs-node/pkg/innerring/processors/netmap.NodeValidator.
type NetMapCandidateValidator struct {
netSettings NetworkSettings
}
// SetNetworkSettings specifies provider of the NetworkSettings interface.
// MUST be called before any VerifyAndUpdate call. Parameter MUST NOT be nil.
func (x *NetMapCandidateValidator) SetNetworkSettings(netSettings NetworkSettings) {
x.netSettings = netSettings
}
// VerifyAndUpdate checks state of the network map candidate described by
// netmap.NodeInfo parameter. Returns no error if status is correct, otherwise
// returns an error describing a violation of the rules:
//
// status MUST be either ONLINE or MAINTENANCE;
// if status is MAINTENANCE, then it SHOULD be allowed by the network.
//
// VerifyAndUpdate does not mutate the parameter in a binary format.
// MUST NOT be called before SetNetworkSettings.
//
// See also netmap.NodeInfo.IsOnline/SetOnline and other similar methods.
func (x *NetMapCandidateValidator) VerifyAndUpdate(ctx context.Context, node *netmap.NodeInfo) error {
if node.Status().IsOnline() {
return nil
}
if node.Status().IsMaintenance() {
return x.netSettings.MaintenanceModeAllowed(ctx)
}
return errors.New("invalid status: MUST be either ONLINE or MAINTENANCE")
}