2021-01-13 13:46:39 +00:00
|
|
|
package control
|
2021-01-13 12:49:46 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
2023-10-31 08:55:42 +00:00
|
|
|
"sync/atomic"
|
2021-01-13 13:34:59 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/replicator"
|
2023-11-20 16:35:16 +00:00
|
|
|
policyengine "git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
2021-01-13 12:49:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Server is an entity that serves
|
2021-01-13 13:46:39 +00:00
|
|
|
// Control service on storage node.
|
2021-01-13 12:49:46 +00:00
|
|
|
type Server struct {
|
|
|
|
*cfg
|
2023-10-31 08:55:42 +00:00
|
|
|
|
|
|
|
// TODO (aarifullin): this counter is used to assign id for rule chains
|
|
|
|
// added as local overrides and will be removed as soon as in-memory
|
|
|
|
// implementation will be replaced.
|
|
|
|
apeChainCounter atomic.Uint32
|
2021-01-13 12:49:46 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 13:34:59 +00:00
|
|
|
// HealthChecker is component interface for calculating
|
|
|
|
// the current health status of a node.
|
|
|
|
type HealthChecker interface {
|
2023-02-03 16:58:09 +00:00
|
|
|
// Must calculate and return current status of the node in FrostFS network map.
|
2021-01-13 13:34:59 +00:00
|
|
|
//
|
|
|
|
// If status can not be calculated for any reason,
|
2021-01-15 10:22:44 +00:00
|
|
|
// control.netmapStatus_STATUS_UNDEFINED should be returned.
|
2021-01-15 09:42:31 +00:00
|
|
|
NetmapStatus() control.NetmapStatus
|
2021-01-15 10:22:44 +00:00
|
|
|
|
|
|
|
// Must calculate and return current health status of the node application.
|
|
|
|
//
|
|
|
|
// If status can not be calculated for any reason,
|
|
|
|
// control.HealthStatus_HEALTH_STATUS_UNDEFINED should be returned.
|
|
|
|
HealthStatus() control.HealthStatus
|
2021-01-13 13:34:59 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 11:51:34 +00:00
|
|
|
// NodeState is an interface of storage node network state.
|
|
|
|
type NodeState interface {
|
2022-10-18 15:42:14 +00:00
|
|
|
// SetNetmapStatus switches the storage node to the given network status.
|
|
|
|
//
|
|
|
|
// If status is control.NetmapStatus_MAINTENANCE and maintenance is allowed
|
|
|
|
// in the network settings, the node additionally starts local maintenance.
|
|
|
|
SetNetmapStatus(st control.NetmapStatus) error
|
|
|
|
|
|
|
|
// ForceMaintenance works like SetNetmapStatus(control.NetmapStatus_MAINTENANCE)
|
|
|
|
// but starts local maintenance regardless of the network settings.
|
|
|
|
ForceMaintenance() error
|
2021-01-15 11:51:34 +00:00
|
|
|
}
|
|
|
|
|
2023-11-20 16:35:16 +00:00
|
|
|
// LocalOverrideStorageDecorator interface provides methods to decorate LocalOverrideEngine
|
|
|
|
// interface methods.
|
|
|
|
type LocalOverrideStorageDecorator interface {
|
|
|
|
// LocalStorage method can be decorated by using sync primitives in the case if the local
|
|
|
|
// override storage state should be consistent for chain router.
|
|
|
|
LocalStorage() policyengine.LocalOverrideStorage
|
|
|
|
}
|
|
|
|
|
2021-01-13 12:49:46 +00:00
|
|
|
// Option of the Server's constructor.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
key *ecdsa.PrivateKey
|
|
|
|
|
|
|
|
allowedKeys [][]byte
|
2021-01-13 13:34:59 +00:00
|
|
|
|
|
|
|
healthChecker HealthChecker
|
2021-01-14 16:32:23 +00:00
|
|
|
|
|
|
|
netMapSrc netmap.Source
|
2021-01-15 11:51:34 +00:00
|
|
|
|
2022-09-19 10:57:59 +00:00
|
|
|
cnrSrc container.Source
|
|
|
|
|
2023-11-20 16:35:16 +00:00
|
|
|
localOverrideStorage LocalOverrideStorageDecorator
|
2023-10-30 13:48:02 +00:00
|
|
|
|
2022-09-19 10:57:59 +00:00
|
|
|
replicator *replicator.Replicator
|
|
|
|
|
2021-01-15 11:51:34 +00:00
|
|
|
nodeState NodeState
|
2021-02-21 08:30:32 +00:00
|
|
|
|
2022-05-16 16:31:50 +00:00
|
|
|
treeService TreeService
|
|
|
|
|
2021-12-17 15:55:59 +00:00
|
|
|
s *engine.StorageEngine
|
2021-01-13 12:49:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns new Server instance.
|
|
|
|
func New(opts ...Option) *Server {
|
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Server{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithKey returns option to set private key
|
|
|
|
// used for signing responses.
|
|
|
|
func WithKey(key *ecdsa.PrivateKey) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.key = key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 07:47:18 +00:00
|
|
|
// WithAuthorizedKeys returns option to add list of public
|
2021-01-13 13:46:39 +00:00
|
|
|
// keys that have rights to use Control service.
|
2021-01-14 07:47:18 +00:00
|
|
|
func WithAuthorizedKeys(keys [][]byte) Option {
|
2021-01-13 12:49:46 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.allowedKeys = append(c.allowedKeys, keys...)
|
|
|
|
}
|
|
|
|
}
|
2021-01-13 13:34:59 +00:00
|
|
|
|
|
|
|
// WithHealthChecker returns option to set component
|
|
|
|
// to calculate node health status.
|
|
|
|
func WithHealthChecker(hc HealthChecker) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.healthChecker = hc
|
|
|
|
}
|
|
|
|
}
|
2021-01-14 16:32:23 +00:00
|
|
|
|
|
|
|
// WithNetMapSource returns option to set network map storage.
|
|
|
|
func WithNetMapSource(netMapSrc netmap.Source) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.netMapSrc = netMapSrc
|
|
|
|
}
|
|
|
|
}
|
2021-01-15 11:51:34 +00:00
|
|
|
|
2022-09-19 10:57:59 +00:00
|
|
|
// WithContainerSource returns option to set container storage.
|
|
|
|
func WithContainerSource(cnrSrc container.Source) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.cnrSrc = cnrSrc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithReplicator returns option to set network map storage.
|
|
|
|
func WithReplicator(r *replicator.Replicator) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.replicator = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 11:51:34 +00:00
|
|
|
// WithNodeState returns option to set node network state component.
|
|
|
|
func WithNodeState(state NodeState) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.nodeState = state
|
|
|
|
}
|
|
|
|
}
|
2021-02-21 08:30:32 +00:00
|
|
|
|
2021-12-17 15:55:59 +00:00
|
|
|
// WithLocalStorage returns option to set local storage engine that
|
|
|
|
// contains information about shards.
|
|
|
|
func WithLocalStorage(engine *engine.StorageEngine) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.s = engine
|
|
|
|
}
|
|
|
|
}
|
2022-05-16 16:31:50 +00:00
|
|
|
|
|
|
|
// WithTreeService returns an option to set tree service.
|
|
|
|
func WithTreeService(s TreeService) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.treeService = s
|
|
|
|
}
|
|
|
|
}
|
2023-10-30 13:48:02 +00:00
|
|
|
|
2023-11-20 16:35:16 +00:00
|
|
|
// WithLocalOverrideStorage returns the option to set access policy engine
|
|
|
|
// chain override storage.
|
|
|
|
func WithLocalOverrideStorage(localOverrideStorage LocalOverrideStorageDecorator) Option {
|
2023-10-30 13:48:02 +00:00
|
|
|
return func(c *cfg) {
|
2023-11-20 16:35:16 +00:00
|
|
|
c.localOverrideStorage = localOverrideStorage
|
2023-10-30 13:48:02 +00:00
|
|
|
}
|
|
|
|
}
|