2020-08-21 15:01:59 +00:00
|
|
|
package main
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2022-09-26 06:31:44 +00:00
|
|
|
"errors"
|
2022-09-12 13:51:13 +00:00
|
|
|
"fmt"
|
2022-09-26 18:31:45 +00:00
|
|
|
"io/fs"
|
2020-08-24 09:40:32 +00:00
|
|
|
"net"
|
2022-09-26 22:02:20 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2022-10-05 12:53:42 +00:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2020-08-22 11:03:45 +00:00
|
|
|
"sync"
|
2022-09-17 12:37:01 +00:00
|
|
|
atomicstd "sync/atomic"
|
2022-09-26 22:02:20 +00:00
|
|
|
"syscall"
|
2020-10-21 09:26:16 +00:00
|
|
|
"time"
|
2020-08-22 14:17:03 +00:00
|
|
|
|
2021-05-31 08:55:38 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2021-07-28 16:19:33 +00:00
|
|
|
neogoutil "github.com/nspcc-dev/neo-go/pkg/util"
|
2021-01-25 08:23:06 +00:00
|
|
|
netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
2021-05-21 18:04:53 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
2021-07-13 11:12:23 +00:00
|
|
|
apiclientconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/apiclient"
|
2021-06-01 12:54:55 +00:00
|
|
|
contractsconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/contracts"
|
2021-06-01 18:27:15 +00:00
|
|
|
engineconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine"
|
|
|
|
shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
|
2022-07-11 12:34:17 +00:00
|
|
|
blobovniczaconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/blobstor/blobovnicza"
|
|
|
|
fstreeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/blobstor/fstree"
|
2021-05-21 18:04:53 +00:00
|
|
|
loggerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/logger"
|
2021-06-01 11:24:57 +00:00
|
|
|
metricsconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/metrics"
|
2021-06-01 17:50:46 +00:00
|
|
|
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
|
2021-06-02 12:36:39 +00:00
|
|
|
objectconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/object"
|
2020-09-23 13:55:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
|
|
|
netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2020-11-19 10:58:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
2022-07-11 12:34:17 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/blobovniczatree"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
2020-11-19 10:58:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2020-12-08 07:51:34 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2022-06-09 08:09:18 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama"
|
2020-11-19 10:58:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
2022-09-26 18:31:45 +00:00
|
|
|
shardmode "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
2021-04-06 10:56:06 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
2021-03-16 08:14:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/metrics"
|
2020-08-22 15:20:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2022-10-06 20:18:46 +00:00
|
|
|
containerClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
2022-01-31 11:58:55 +00:00
|
|
|
nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
2020-10-21 09:26:16 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
2021-02-17 12:19:54 +00:00
|
|
|
netmap2 "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
2020-09-23 13:31:51 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
2021-07-13 11:12:23 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network/cache"
|
2021-01-13 13:46:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
2022-04-19 18:01:49 +00:00
|
|
|
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/tombstone"
|
|
|
|
tsourse "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/tombstone/source"
|
2022-09-19 10:57:59 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/replicator"
|
2021-03-23 18:54:00 +00:00
|
|
|
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
|
|
|
|
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
2022-05-16 16:31:50 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/tree"
|
2020-10-22 11:07:06 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/util/response"
|
2021-08-24 07:25:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util"
|
2020-09-25 12:34:17 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2021-09-06 13:05:45 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/state"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
2022-07-11 12:34:17 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-17 13:59:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/user"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
2020-11-09 15:40:06 +00:00
|
|
|
"github.com/panjf2000/ants/v2"
|
2021-01-18 13:04:13 +00:00
|
|
|
"go.etcd.io/bbolt"
|
2021-01-13 13:36:41 +00:00
|
|
|
"go.uber.org/atomic"
|
2020-09-25 12:34:17 +00:00
|
|
|
"go.uber.org/zap"
|
2020-08-22 15:20:47 +00:00
|
|
|
"google.golang.org/grpc"
|
2020-08-22 11:03:45 +00:00
|
|
|
)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
const addressSize = 72 // 32 bytes object ID, 32 bytes container ID, 8 bytes protobuf encoding
|
2020-10-02 08:01:54 +00:00
|
|
|
|
2021-05-12 08:00:46 +00:00
|
|
|
const maxMsgSize = 4 << 20 // transport msg limit 4 MiB
|
|
|
|
|
2021-05-12 08:28:23 +00:00
|
|
|
// capacity of the pools of the morph notification handlers
|
|
|
|
// for each contract listener.
|
|
|
|
const notificationHandlerPoolSize = 10
|
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
// applicationConfiguration reads and stores component-specific configuration
|
|
|
|
// values. It should not store any application helpers structs (pointers to shared
|
|
|
|
// structs).
|
|
|
|
// It must not be used concurrently.
|
|
|
|
type applicationConfiguration struct {
|
2022-09-26 21:39:34 +00:00
|
|
|
// _read indicated whether a config
|
|
|
|
// has already been read
|
|
|
|
_read bool
|
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
LoggerCfg struct {
|
|
|
|
level string
|
|
|
|
}
|
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
EngineCfg struct {
|
|
|
|
errorThreshold uint32
|
|
|
|
shardPoolSize uint32
|
|
|
|
shards []shardCfg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type shardCfg struct {
|
|
|
|
compress bool
|
|
|
|
smallSizeObjectLimit uint64
|
|
|
|
uncompressableContentType []string
|
|
|
|
refillMetabase bool
|
|
|
|
mode shardmode.Mode
|
|
|
|
|
|
|
|
metaCfg struct {
|
|
|
|
path string
|
|
|
|
perm fs.FileMode
|
|
|
|
maxBatchSize int
|
|
|
|
maxBatchDelay time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
subStorages []subStorageCfg
|
|
|
|
|
|
|
|
gcCfg struct {
|
|
|
|
removerBatchSize int
|
|
|
|
removerSleepInterval time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
writecacheCfg struct {
|
|
|
|
enabled bool
|
|
|
|
path string
|
|
|
|
maxBatchSize int
|
|
|
|
maxBatchDelay time.Duration
|
|
|
|
smallObjectSize uint64
|
|
|
|
maxObjSize uint64
|
|
|
|
flushWorkerCount int
|
|
|
|
sizeLimit uint64
|
2022-10-28 10:09:38 +00:00
|
|
|
noSync bool
|
2022-09-26 18:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
piloramaCfg struct {
|
|
|
|
enabled bool
|
|
|
|
path string
|
|
|
|
perm fs.FileMode
|
|
|
|
noSync bool
|
|
|
|
maxBatchSize int
|
|
|
|
maxBatchDelay time.Duration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 12:53:42 +00:00
|
|
|
// id returns persistent id of a shard. It is different from the ID used in runtime
|
|
|
|
// and is primarily used to identify shards in the configuration.
|
|
|
|
func (c *shardCfg) id() string {
|
|
|
|
// This calculation should be kept in sync with
|
|
|
|
// pkg/local_object_storage/engine/control.go file.
|
|
|
|
var sb strings.Builder
|
|
|
|
for i := range c.subStorages {
|
|
|
|
sb.WriteString(filepath.Clean(c.subStorages[i].path))
|
|
|
|
}
|
|
|
|
return sb.String()
|
|
|
|
}
|
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
type subStorageCfg struct {
|
|
|
|
// common for all storages
|
2022-10-28 10:00:11 +00:00
|
|
|
typ string
|
|
|
|
path string
|
|
|
|
perm fs.FileMode
|
|
|
|
depth uint64
|
|
|
|
noSync bool
|
2022-09-26 18:31:45 +00:00
|
|
|
|
|
|
|
// blobovnicza-specific
|
|
|
|
size uint64
|
|
|
|
width uint64
|
|
|
|
openedCacheSize int
|
|
|
|
}
|
|
|
|
|
|
|
|
// readConfig fills applicationConfiguration with raw configuration values
|
|
|
|
// not modifying them.
|
|
|
|
func (a *applicationConfiguration) readConfig(c *config.Config) error {
|
2022-09-26 21:39:34 +00:00
|
|
|
if a._read {
|
2022-09-30 13:33:30 +00:00
|
|
|
err := c.Reload()
|
|
|
|
if err != nil {
|
2022-09-30 14:13:16 +00:00
|
|
|
return fmt.Errorf("could not reload configuration: %w", err)
|
2022-09-30 13:33:30 +00:00
|
|
|
}
|
2022-09-30 14:13:16 +00:00
|
|
|
|
|
|
|
err = validateConfig(c)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("configuration's validation: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear if it is rereading
|
|
|
|
*a = applicationConfiguration{}
|
2022-09-26 21:39:34 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 14:48:29 +00:00
|
|
|
a._read = true
|
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
// Logger
|
|
|
|
|
|
|
|
a.LoggerCfg.level = loggerconfig.Level(c)
|
|
|
|
|
|
|
|
// Storage Engine
|
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
a.EngineCfg.errorThreshold = engineconfig.ShardErrorThreshold(c)
|
|
|
|
a.EngineCfg.shardPoolSize = engineconfig.ShardPoolSize(c)
|
|
|
|
|
|
|
|
return engineconfig.IterateShards(c, false, func(sc *shardconfig.Config) error {
|
|
|
|
var sh shardCfg
|
|
|
|
|
|
|
|
sh.refillMetabase = sc.RefillMetabase()
|
|
|
|
sh.mode = sc.Mode()
|
|
|
|
sh.compress = sc.Compress()
|
|
|
|
sh.uncompressableContentType = sc.UncompressableContentTypes()
|
|
|
|
sh.smallSizeObjectLimit = sc.SmallSizeLimit()
|
|
|
|
|
|
|
|
// write-cache
|
|
|
|
|
|
|
|
writeCacheCfg := sc.WriteCache()
|
|
|
|
if writeCacheCfg.Enabled() {
|
|
|
|
wc := &sh.writecacheCfg
|
|
|
|
|
|
|
|
wc.enabled = true
|
|
|
|
wc.path = writeCacheCfg.Path()
|
|
|
|
wc.maxBatchSize = writeCacheCfg.BoltDB().MaxBatchSize()
|
|
|
|
wc.maxBatchDelay = writeCacheCfg.BoltDB().MaxBatchDelay()
|
2022-10-18 12:54:25 +00:00
|
|
|
wc.maxObjSize = writeCacheCfg.MaxObjectSize()
|
2022-09-26 18:31:45 +00:00
|
|
|
wc.smallObjectSize = writeCacheCfg.SmallObjectSize()
|
|
|
|
wc.flushWorkerCount = writeCacheCfg.WorkersNumber()
|
|
|
|
wc.sizeLimit = writeCacheCfg.SizeLimit()
|
2022-10-28 10:09:38 +00:00
|
|
|
wc.noSync = writeCacheCfg.NoSync()
|
2022-09-26 18:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// blobstor with substorages
|
|
|
|
|
|
|
|
blobStorCfg := sc.BlobStor()
|
|
|
|
storagesCfg := blobStorCfg.Storages()
|
|
|
|
metabaseCfg := sc.Metabase()
|
|
|
|
gcCfg := sc.GC()
|
|
|
|
|
|
|
|
if config.BoolSafe(c.Sub("tree"), "enabled") {
|
|
|
|
piloramaCfg := sc.Pilorama()
|
|
|
|
pr := &sh.piloramaCfg
|
|
|
|
|
|
|
|
pr.enabled = true
|
|
|
|
pr.path = piloramaCfg.Path()
|
|
|
|
pr.perm = piloramaCfg.Perm()
|
|
|
|
pr.noSync = piloramaCfg.NoSync()
|
|
|
|
pr.maxBatchSize = piloramaCfg.MaxBatchSize()
|
|
|
|
pr.maxBatchDelay = piloramaCfg.MaxBatchDelay()
|
|
|
|
}
|
|
|
|
|
|
|
|
ss := make([]subStorageCfg, 0, len(storagesCfg))
|
|
|
|
for i := range storagesCfg {
|
|
|
|
var sCfg subStorageCfg
|
|
|
|
|
|
|
|
sCfg.typ = storagesCfg[i].Type()
|
|
|
|
sCfg.path = storagesCfg[i].Path()
|
|
|
|
sCfg.perm = storagesCfg[i].Perm()
|
|
|
|
|
|
|
|
switch storagesCfg[i].Type() {
|
|
|
|
case blobovniczatree.Type:
|
|
|
|
sub := blobovniczaconfig.From((*config.Config)(storagesCfg[i]))
|
|
|
|
|
|
|
|
sCfg.size = sub.Size()
|
|
|
|
sCfg.depth = sub.ShallowDepth()
|
|
|
|
sCfg.width = sub.ShallowWidth()
|
|
|
|
sCfg.openedCacheSize = sub.OpenedCacheSize()
|
|
|
|
case fstree.Type:
|
|
|
|
sub := fstreeconfig.From((*config.Config)(storagesCfg[i]))
|
|
|
|
sCfg.depth = sub.Depth()
|
2022-10-28 10:00:11 +00:00
|
|
|
sCfg.noSync = sub.NoSync()
|
2022-09-26 18:31:45 +00:00
|
|
|
default:
|
|
|
|
return fmt.Errorf("invalid storage type: %s", storagesCfg[i].Type())
|
|
|
|
}
|
|
|
|
|
|
|
|
ss = append(ss, sCfg)
|
|
|
|
}
|
|
|
|
|
|
|
|
sh.subStorages = ss
|
|
|
|
|
|
|
|
// meta
|
|
|
|
|
|
|
|
m := &sh.metaCfg
|
|
|
|
|
|
|
|
m.path = metabaseCfg.Path()
|
|
|
|
m.perm = metabaseCfg.BoltDB().Perm()
|
|
|
|
m.maxBatchDelay = metabaseCfg.BoltDB().MaxBatchDelay()
|
|
|
|
m.maxBatchSize = metabaseCfg.BoltDB().MaxBatchSize()
|
|
|
|
|
|
|
|
// GC
|
|
|
|
|
|
|
|
sh.gcCfg.removerBatchSize = gcCfg.RemoverBatchSize()
|
|
|
|
sh.gcCfg.removerSleepInterval = gcCfg.RemoverSleepInterval()
|
|
|
|
|
|
|
|
a.EngineCfg.shards = append(a.EngineCfg.shards, sh)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-27 13:13:49 +00:00
|
|
|
// internals contains application-specific internals that are created
|
|
|
|
// on application startup and are shared b/w the components during
|
|
|
|
// the application life cycle.
|
|
|
|
// It should not contain any read configuration values, component-specific
|
|
|
|
// helpers and fields.
|
|
|
|
type internals struct {
|
|
|
|
ctx context.Context
|
|
|
|
ctxCancel func()
|
|
|
|
internalErr chan error // channel for internal application errors at runtime
|
2020-08-22 11:03:45 +00:00
|
|
|
|
2021-06-01 11:13:44 +00:00
|
|
|
appCfg *config.Config
|
|
|
|
|
2022-09-28 07:41:01 +00:00
|
|
|
log *logger.Logger
|
2020-09-25 12:34:17 +00:00
|
|
|
|
2022-09-27 13:13:49 +00:00
|
|
|
wg *sync.WaitGroup
|
2020-10-03 09:57:02 +00:00
|
|
|
workers []worker
|
2021-01-18 08:56:14 +00:00
|
|
|
closers []func()
|
2021-03-23 18:54:00 +00:00
|
|
|
|
2022-09-27 13:13:49 +00:00
|
|
|
apiVersion version.Version
|
|
|
|
healthStatus *atomic.Int32
|
2022-10-04 13:01:16 +00:00
|
|
|
// is node under maintenance
|
|
|
|
isMaintenance atomic.Bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// starts node's maintenance.
|
2022-10-28 07:08:49 +00:00
|
|
|
func (c *cfg) startMaintenance() {
|
2022-10-04 13:01:16 +00:00
|
|
|
c.isMaintenance.Store(true)
|
2022-10-28 07:08:49 +00:00
|
|
|
c.cfgNetmap.state.setControlNetmapStatus(control.NetmapStatus_MAINTENANCE)
|
2022-10-04 13:01:16 +00:00
|
|
|
c.log.Info("started local node's maintenance")
|
|
|
|
}
|
|
|
|
|
|
|
|
// stops node's maintenance.
|
2022-09-27 13:13:49 +00:00
|
|
|
func (c *internals) stopMaintenance() {
|
2022-10-04 13:01:16 +00:00
|
|
|
c.isMaintenance.Store(false)
|
|
|
|
c.log.Info("stopped local node's maintenance")
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsMaintenance checks if storage node is under maintenance.
|
|
|
|
//
|
|
|
|
// Provides util.NodeState to Object service.
|
2022-09-27 13:13:49 +00:00
|
|
|
func (c *internals) IsMaintenance() bool {
|
2022-10-04 13:01:16 +00:00
|
|
|
return c.isMaintenance.Load()
|
2022-09-17 12:37:01 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 13:13:49 +00:00
|
|
|
// shared contains component-specific structs/helpers that should
|
|
|
|
// be shared during initialization of the application.
|
|
|
|
type shared struct {
|
|
|
|
privateTokenStore sessionStorage
|
|
|
|
persistate *state.PersistentStorage
|
|
|
|
|
2022-11-12 07:46:23 +00:00
|
|
|
clientCache *cache.ClientCache
|
|
|
|
bgClientCache *cache.ClientCache
|
|
|
|
localAddr network.AddressGroup
|
2022-09-27 13:13:49 +00:00
|
|
|
|
|
|
|
key *keys.PrivateKey
|
|
|
|
binPublicKey []byte
|
|
|
|
ownerIDFromKey user.ID // user ID calculated from key
|
|
|
|
|
|
|
|
// current network map
|
|
|
|
netMap atomicstd.Value // type netmap.NetMap
|
|
|
|
netMapSource netmapCore.Source
|
|
|
|
|
2022-10-06 20:18:46 +00:00
|
|
|
cnrClient *containerClient.Client
|
|
|
|
|
2022-09-27 13:13:49 +00:00
|
|
|
respSvc *response.Service
|
|
|
|
|
|
|
|
replicator *replicator.Replicator
|
|
|
|
|
|
|
|
treeService *tree.Service
|
|
|
|
|
|
|
|
metricsCollector *metrics.NodeMetrics
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
// dynamicConfiguration stores parameters of the
|
2022-10-17 12:03:55 +00:00
|
|
|
// components that supports runtime reconfigurations.
|
2022-09-28 09:19:23 +00:00
|
|
|
type dynamicConfiguration struct {
|
|
|
|
logger *logger.Prm
|
|
|
|
}
|
|
|
|
|
2022-09-27 13:13:49 +00:00
|
|
|
type cfg struct {
|
|
|
|
applicationConfiguration
|
|
|
|
internals
|
|
|
|
shared
|
2022-09-28 09:19:23 +00:00
|
|
|
dynamicConfiguration
|
2022-09-27 13:13:49 +00:00
|
|
|
|
|
|
|
// configuration of the internal
|
|
|
|
// services
|
|
|
|
cfgGRPC cfgGRPC
|
|
|
|
cfgMorph cfgMorph
|
|
|
|
cfgAccounting cfgAccounting
|
|
|
|
cfgContainer cfgContainer
|
|
|
|
cfgNodeInfo cfgNodeInfo
|
|
|
|
cfgNetmap cfgNetmap
|
|
|
|
cfgControlService cfgControlService
|
|
|
|
cfgReputation cfgReputation
|
|
|
|
cfgObject cfgObject
|
|
|
|
cfgNotifications cfgNotifications
|
|
|
|
}
|
|
|
|
|
2022-09-26 06:31:44 +00:00
|
|
|
// ReadCurrentNetMap reads network map which has been cached at the
|
|
|
|
// latest epoch. Returns an error if value has not been cached yet.
|
|
|
|
//
|
|
|
|
// Provides interface for NetmapService server.
|
|
|
|
func (c *cfg) ReadCurrentNetMap(msg *netmapV2.NetMap) error {
|
|
|
|
val := c.netMap.Load()
|
|
|
|
if val == nil {
|
|
|
|
return errors.New("missing local network map")
|
|
|
|
}
|
|
|
|
|
|
|
|
val.(netmap.NetMap).WriteToV2(msg)
|
|
|
|
|
|
|
|
return nil
|
2020-08-24 09:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cfgGRPC struct {
|
2021-06-22 17:25:18 +00:00
|
|
|
listeners []net.Listener
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2021-06-22 17:25:18 +00:00
|
|
|
servers []*grpc.Server
|
2020-09-30 08:39:45 +00:00
|
|
|
|
|
|
|
maxChunkSize uint64
|
|
|
|
|
|
|
|
maxAddrAmount uint64
|
2020-08-24 09:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cfgMorph struct {
|
|
|
|
client *client.Client
|
2021-04-15 14:57:29 +00:00
|
|
|
|
2022-01-29 13:36:29 +00:00
|
|
|
notaryEnabled bool
|
2021-08-25 10:49:59 +00:00
|
|
|
|
2022-08-16 11:59:30 +00:00
|
|
|
// TTL of Sidechain cached values. Non-positive value disables caching.
|
|
|
|
cacheTTL time.Duration
|
2021-07-29 15:57:53 +00:00
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
eigenTrustTicker *eigenTrustTickers // timers for EigenTrust iterations
|
2021-08-31 14:02:42 +00:00
|
|
|
|
|
|
|
proxyScriptHash neogoutil.Uint160
|
2020-08-24 09:40:32 +00:00
|
|
|
}
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
type cfgAccounting struct {
|
2021-07-28 16:19:33 +00:00
|
|
|
scriptHash neogoutil.Uint160
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 14:07:08 +00:00
|
|
|
type cfgContainer struct {
|
2021-07-28 16:19:33 +00:00
|
|
|
scriptHash neogoutil.Uint160
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
parsers map[event.Type]event.NotificationParser
|
2021-02-01 12:33:58 +00:00
|
|
|
subscribers map[event.Type][]event.Handler
|
2021-07-28 16:19:33 +00:00
|
|
|
workerPool util.WorkerPool // pool for asynchronous handlers
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 15:19:21 +00:00
|
|
|
type cfgNetmap struct {
|
2021-07-28 16:19:33 +00:00
|
|
|
scriptHash neogoutil.Uint160
|
2022-01-31 11:58:55 +00:00
|
|
|
wrapper *nmClient.Client
|
2020-08-31 15:19:21 +00:00
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
parsers map[event.Type]event.NotificationParser
|
2020-10-21 09:26:16 +00:00
|
|
|
|
|
|
|
subscribers map[event.Type][]event.Handler
|
2021-07-28 16:19:33 +00:00
|
|
|
workerPool util.WorkerPool // pool for asynchronous handlers
|
2020-10-21 15:12:31 +00:00
|
|
|
|
|
|
|
state *networkState
|
2020-10-30 12:57:49 +00:00
|
|
|
|
2021-08-24 07:31:05 +00:00
|
|
|
needBootstrap bool
|
2021-04-21 13:26:04 +00:00
|
|
|
reBoostrapTurnedOff *atomic.Bool // managed by control service in runtime
|
2021-05-12 09:27:12 +00:00
|
|
|
startEpoch uint64 // epoch number when application is started
|
2020-08-31 15:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cfgNodeInfo struct {
|
2020-10-08 13:17:50 +00:00
|
|
|
// values from config
|
2021-06-11 10:55:11 +00:00
|
|
|
localInfo netmap.NodeInfo
|
2020-08-31 15:19:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 13:55:46 +00:00
|
|
|
type cfgObject struct {
|
2022-04-19 18:01:49 +00:00
|
|
|
getSvc *getsvc.Service
|
|
|
|
|
2021-07-29 15:57:53 +00:00
|
|
|
cnrSource container.Source
|
2020-09-29 12:38:44 +00:00
|
|
|
|
2022-09-08 10:32:25 +00:00
|
|
|
eaclSource container.EACLSource
|
2020-11-09 15:40:06 +00:00
|
|
|
|
|
|
|
pool cfgObjectRoutines
|
2020-11-19 10:58:27 +00:00
|
|
|
|
|
|
|
cfgLocalStorage cfgLocalStorage
|
|
|
|
}
|
|
|
|
|
2022-03-15 19:42:15 +00:00
|
|
|
type cfgNotifications struct {
|
|
|
|
enabled bool
|
|
|
|
nw notificationWriter
|
|
|
|
defaultTopic string
|
|
|
|
}
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
type cfgLocalStorage struct {
|
|
|
|
localStorage *engine.StorageEngine
|
2020-11-09 15:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cfgObjectRoutines struct {
|
2021-10-08 13:34:39 +00:00
|
|
|
putRemote *ants.Pool
|
2021-11-10 08:34:00 +00:00
|
|
|
|
|
|
|
putRemoteCapacity int
|
|
|
|
|
|
|
|
replication *ants.Pool
|
2020-09-23 13:55:46 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 13:46:39 +00:00
|
|
|
type cfgControlService struct {
|
2021-01-13 12:51:05 +00:00
|
|
|
server *grpc.Server
|
|
|
|
}
|
|
|
|
|
2021-03-23 18:54:00 +00:00
|
|
|
type cfgReputation struct {
|
2021-07-28 16:19:33 +00:00
|
|
|
workerPool util.WorkerPool // pool for EigenTrust algorithm's iterations
|
2021-04-21 05:29:35 +00:00
|
|
|
|
2021-03-23 18:54:00 +00:00
|
|
|
localTrustStorage *truststorage.Storage
|
|
|
|
|
|
|
|
localTrustCtrl *trustcontroller.Controller
|
2021-04-29 05:32:24 +00:00
|
|
|
|
2021-07-28 16:19:33 +00:00
|
|
|
scriptHash neogoutil.Uint160
|
2021-03-23 18:54:00 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 13:05:45 +00:00
|
|
|
var persistateSideChainLastBlockKey = []byte("side_chain_last_processed_block")
|
|
|
|
|
2022-09-20 13:20:45 +00:00
|
|
|
func initCfg(appCfg *config.Config) *cfg {
|
2022-09-28 09:19:23 +00:00
|
|
|
c := &cfg{}
|
2020-09-16 07:45:08 +00:00
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
err := c.readConfig(appCfg)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("config reading: %w", err))
|
|
|
|
}
|
2021-05-11 08:54:59 +00:00
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
key := nodeconfig.Key(appCfg)
|
|
|
|
|
|
|
|
logPrm, err := c.loggerPrm()
|
2021-05-11 08:54:59 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
log, err := logger.NewLogger(logPrm)
|
2020-09-25 12:34:17 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2022-03-01 07:52:24 +00:00
|
|
|
var netAddr network.AddressGroup
|
|
|
|
|
|
|
|
relayOnly := nodeconfig.Relay(appCfg)
|
|
|
|
if !relayOnly {
|
|
|
|
netAddr = nodeconfig.BootstrapAddresses(appCfg)
|
|
|
|
}
|
2020-09-23 13:31:51 +00:00
|
|
|
|
2021-05-12 08:00:46 +00:00
|
|
|
maxChunkSize := uint64(maxMsgSize) * 3 / 4 // 25% to meta, 75% to payload
|
|
|
|
maxAddrAmount := uint64(maxChunkSize) / addressSize // each address is about 72 bytes
|
2020-10-02 08:01:54 +00:00
|
|
|
|
2021-09-06 13:05:45 +00:00
|
|
|
netState := newNetworkState()
|
|
|
|
|
|
|
|
persistate, err := state.NewPersistentStorage(nodeconfig.PersistentState(appCfg).Path())
|
|
|
|
fatalOnErr(err)
|
2020-10-22 11:24:08 +00:00
|
|
|
|
2021-05-12 08:28:23 +00:00
|
|
|
containerWorkerPool, err := ants.NewPool(notificationHandlerPoolSize)
|
2021-04-13 12:15:36 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2021-05-12 08:28:23 +00:00
|
|
|
netmapWorkerPool, err := ants.NewPool(notificationHandlerPoolSize)
|
2021-04-13 12:15:36 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2021-05-12 08:28:23 +00:00
|
|
|
reputationWorkerPool, err := ants.NewPool(notificationHandlerPoolSize)
|
2021-04-21 05:29:35 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
c.internals = internals{
|
|
|
|
ctx: context.Background(),
|
|
|
|
appCfg: appCfg,
|
|
|
|
internalErr: make(chan error),
|
|
|
|
log: log,
|
|
|
|
wg: new(sync.WaitGroup),
|
|
|
|
apiVersion: version.Current(),
|
|
|
|
healthStatus: atomic.NewInt32(int32(control.HealthStatus_HEALTH_STATUS_UNDEFINED)),
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
2022-11-12 07:46:23 +00:00
|
|
|
|
|
|
|
cacheOpts := cache.ClientCacheOpts{
|
|
|
|
DialTimeout: apiclientconfig.DialTimeout(appCfg),
|
|
|
|
StreamTimeout: apiclientconfig.StreamTimeout(appCfg),
|
|
|
|
Key: &key.PrivateKey,
|
|
|
|
AllowExternal: apiclientconfig.AllowExternal(appCfg),
|
|
|
|
}
|
2022-09-28 09:19:23 +00:00
|
|
|
c.shared = shared{
|
2022-11-12 07:46:23 +00:00
|
|
|
key: key,
|
|
|
|
binPublicKey: key.PublicKey().Bytes(),
|
|
|
|
localAddr: netAddr,
|
|
|
|
respSvc: response.NewService(response.WithNetworkState(netState)),
|
|
|
|
clientCache: cache.NewSDKClientCache(cacheOpts),
|
|
|
|
bgClientCache: cache.NewSDKClientCache(cacheOpts),
|
|
|
|
persistate: persistate,
|
2022-09-28 09:19:23 +00:00
|
|
|
}
|
|
|
|
c.cfgAccounting = cfgAccounting{
|
|
|
|
scriptHash: contractsconfig.Balance(appCfg),
|
|
|
|
}
|
|
|
|
c.cfgContainer = cfgContainer{
|
|
|
|
scriptHash: contractsconfig.Container(appCfg),
|
|
|
|
workerPool: containerWorkerPool,
|
|
|
|
}
|
|
|
|
c.cfgNetmap = cfgNetmap{
|
|
|
|
scriptHash: contractsconfig.Netmap(appCfg),
|
|
|
|
state: netState,
|
|
|
|
workerPool: netmapWorkerPool,
|
|
|
|
needBootstrap: !relayOnly,
|
|
|
|
reBoostrapTurnedOff: atomic.NewBool(relayOnly),
|
|
|
|
}
|
|
|
|
c.cfgGRPC = cfgGRPC{
|
|
|
|
maxChunkSize: maxChunkSize,
|
|
|
|
maxAddrAmount: maxAddrAmount,
|
|
|
|
}
|
|
|
|
c.cfgMorph = cfgMorph{
|
|
|
|
proxyScriptHash: contractsconfig.Proxy(appCfg),
|
|
|
|
}
|
|
|
|
c.cfgObject = cfgObject{
|
|
|
|
pool: initObjectPool(appCfg),
|
|
|
|
}
|
|
|
|
c.cfgReputation = cfgReputation{
|
|
|
|
scriptHash: contractsconfig.Reputation(appCfg),
|
|
|
|
workerPool: reputationWorkerPool,
|
2022-09-26 18:31:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
user.IDFromKey(&c.ownerIDFromKey, key.PrivateKey.PublicKey)
|
|
|
|
|
2022-07-13 09:17:37 +00:00
|
|
|
if metricsconfig.Enabled(c.appCfg) {
|
2022-07-19 15:16:42 +00:00
|
|
|
c.metricsCollector = metrics.NewNodeMetrics()
|
2021-12-28 10:39:42 +00:00
|
|
|
netState.metrics = c.metricsCollector
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 07:46:23 +00:00
|
|
|
c.onShutdown(c.clientCache.CloseAll) // clean up connections
|
|
|
|
c.onShutdown(c.bgClientCache.CloseAll) // clean up connections
|
2021-09-06 13:05:45 +00:00
|
|
|
c.onShutdown(func() { _ = c.persistate.Close() })
|
2021-07-13 11:12:23 +00:00
|
|
|
|
2020-09-24 12:32:30 +00:00
|
|
|
return c
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
2020-09-16 07:45:08 +00:00
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
func (c *cfg) engineOpts() []engine.Option {
|
|
|
|
opts := make([]engine.Option, 0, 4)
|
2020-09-24 12:32:30 +00:00
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
opts = append(opts,
|
|
|
|
engine.WithShardPoolSize(c.EngineCfg.shardPoolSize),
|
|
|
|
engine.WithErrorThreshold(c.EngineCfg.errorThreshold),
|
2020-09-24 12:32:30 +00:00
|
|
|
|
2021-10-08 13:25:56 +00:00
|
|
|
engine.WithLogger(c.log),
|
2022-04-19 18:01:49 +00:00
|
|
|
)
|
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
if c.metricsCollector != nil {
|
|
|
|
opts = append(opts, engine.WithMetrics(c.metricsCollector))
|
2020-11-19 10:58:27 +00:00
|
|
|
}
|
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
return opts
|
2020-11-19 10:58:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 12:53:42 +00:00
|
|
|
type shardOptsWithID struct {
|
|
|
|
configID string
|
2022-09-26 22:02:20 +00:00
|
|
|
shOpts []shard.Option
|
|
|
|
}
|
|
|
|
|
2022-10-05 12:53:42 +00:00
|
|
|
func (c *cfg) shardOpts() []shardOptsWithID {
|
|
|
|
shards := make([]shardOptsWithID, 0, len(c.EngineCfg.shards))
|
2020-11-19 10:58:27 +00:00
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
for _, shCfg := range c.EngineCfg.shards {
|
2021-06-01 18:27:15 +00:00
|
|
|
var writeCacheOpts []writecache.Option
|
2022-09-26 18:31:45 +00:00
|
|
|
if wcRead := shCfg.writecacheCfg; wcRead.enabled {
|
|
|
|
writeCacheOpts = append(writeCacheOpts,
|
|
|
|
writecache.WithPath(wcRead.path),
|
|
|
|
writecache.WithMaxBatchSize(wcRead.maxBatchSize),
|
|
|
|
writecache.WithMaxBatchDelay(wcRead.maxBatchDelay),
|
|
|
|
writecache.WithMaxObjectSize(wcRead.maxObjSize),
|
|
|
|
writecache.WithSmallObjectSize(wcRead.smallObjectSize),
|
|
|
|
writecache.WithFlushWorkersCount(wcRead.flushWorkerCount),
|
|
|
|
writecache.WithMaxCacheSize(wcRead.sizeLimit),
|
2022-10-28 10:09:38 +00:00
|
|
|
writecache.WithNoSync(wcRead.noSync),
|
2021-06-01 18:27:15 +00:00
|
|
|
writecache.WithLogger(c.log),
|
2022-09-26 18:31:45 +00:00
|
|
|
)
|
2021-04-06 10:56:06 +00:00
|
|
|
}
|
2020-11-26 07:47:20 +00:00
|
|
|
|
2022-07-18 10:16:23 +00:00
|
|
|
var piloramaOpts []pilorama.Option
|
2022-09-26 18:31:45 +00:00
|
|
|
if prRead := shCfg.piloramaCfg; prRead.enabled {
|
|
|
|
piloramaOpts = append(piloramaOpts,
|
|
|
|
pilorama.WithPath(prRead.path),
|
|
|
|
pilorama.WithPerm(prRead.perm),
|
|
|
|
pilorama.WithNoSync(prRead.noSync),
|
|
|
|
pilorama.WithMaxBatchSize(prRead.maxBatchSize),
|
|
|
|
pilorama.WithMaxBatchDelay(prRead.maxBatchDelay),
|
|
|
|
)
|
2022-07-18 10:16:23 +00:00
|
|
|
}
|
2022-06-09 08:09:18 +00:00
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
var ss []blobstor.SubStorage
|
|
|
|
for _, sRead := range shCfg.subStorages {
|
|
|
|
switch sRead.typ {
|
2022-09-20 12:42:56 +00:00
|
|
|
case blobovniczatree.Type:
|
2022-09-26 18:31:45 +00:00
|
|
|
ss = append(ss, blobstor.SubStorage{
|
2022-07-11 12:34:17 +00:00
|
|
|
Storage: blobovniczatree.NewBlobovniczaTree(
|
2022-09-26 18:31:45 +00:00
|
|
|
blobovniczatree.WithRootPath(sRead.path),
|
|
|
|
blobovniczatree.WithPermissions(sRead.perm),
|
|
|
|
blobovniczatree.WithBlobovniczaSize(sRead.size),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowDepth(sRead.depth),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowWidth(sRead.width),
|
|
|
|
blobovniczatree.WithOpenedCacheSize(sRead.openedCacheSize),
|
|
|
|
|
|
|
|
blobovniczatree.WithLogger(c.log)),
|
2022-07-11 12:34:17 +00:00
|
|
|
Policy: func(_ *objectSDK.Object, data []byte) bool {
|
2022-09-26 18:31:45 +00:00
|
|
|
return uint64(len(data)) < shCfg.smallSizeObjectLimit
|
2022-07-11 12:34:17 +00:00
|
|
|
},
|
|
|
|
})
|
2022-09-20 12:42:56 +00:00
|
|
|
case fstree.Type:
|
2022-09-26 18:31:45 +00:00
|
|
|
ss = append(ss, blobstor.SubStorage{
|
2022-07-11 12:34:17 +00:00
|
|
|
Storage: fstree.New(
|
2022-09-26 18:31:45 +00:00
|
|
|
fstree.WithPath(sRead.path),
|
|
|
|
fstree.WithPerm(sRead.perm),
|
2022-10-28 10:00:11 +00:00
|
|
|
fstree.WithDepth(sRead.depth),
|
|
|
|
fstree.WithNoSync(sRead.noSync)),
|
2022-07-11 12:34:17 +00:00
|
|
|
Policy: func(_ *objectSDK.Object, data []byte) bool {
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
})
|
2022-09-12 13:51:13 +00:00
|
|
|
default:
|
2022-09-26 18:31:45 +00:00
|
|
|
// should never happen, that has already
|
|
|
|
// been handled: when the config was read
|
2022-07-11 12:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 12:53:42 +00:00
|
|
|
var sh shardOptsWithID
|
|
|
|
sh.configID = shCfg.id()
|
2022-09-26 22:02:20 +00:00
|
|
|
sh.shOpts = []shard.Option{
|
2020-11-19 10:58:27 +00:00
|
|
|
shard.WithLogger(c.log),
|
2022-09-26 18:31:45 +00:00
|
|
|
shard.WithRefillMetabase(shCfg.refillMetabase),
|
|
|
|
shard.WithMode(shCfg.mode),
|
2020-11-19 10:58:27 +00:00
|
|
|
shard.WithBlobStorOptions(
|
2022-09-26 18:31:45 +00:00
|
|
|
blobstor.WithCompressObjects(shCfg.compress),
|
|
|
|
blobstor.WithUncompressableContentTypes(shCfg.uncompressableContentType),
|
|
|
|
blobstor.WithStorages(ss),
|
|
|
|
|
2020-11-30 15:35:37 +00:00
|
|
|
blobstor.WithLogger(c.log),
|
2020-11-19 10:58:27 +00:00
|
|
|
),
|
|
|
|
shard.WithMetaBaseOptions(
|
2022-09-26 18:31:45 +00:00
|
|
|
meta.WithPath(shCfg.metaCfg.path),
|
|
|
|
meta.WithPermissions(shCfg.metaCfg.perm),
|
|
|
|
meta.WithMaxBatchSize(shCfg.metaCfg.maxBatchSize),
|
|
|
|
meta.WithMaxBatchDelay(shCfg.metaCfg.maxBatchDelay),
|
2021-01-18 13:04:13 +00:00
|
|
|
meta.WithBoltDBOptions(&bbolt.Options{
|
|
|
|
Timeout: 100 * time.Millisecond,
|
|
|
|
}),
|
2022-09-26 18:31:45 +00:00
|
|
|
|
|
|
|
meta.WithLogger(c.log),
|
2022-07-27 18:34:25 +00:00
|
|
|
meta.WithEpochState(c.cfgNetmap.state),
|
2020-11-19 10:58:27 +00:00
|
|
|
),
|
2022-06-09 08:09:18 +00:00
|
|
|
shard.WithPiloramaOptions(piloramaOpts...),
|
2022-09-26 18:31:45 +00:00
|
|
|
shard.WithWriteCache(shCfg.writecacheCfg.enabled),
|
2021-06-01 18:27:15 +00:00
|
|
|
shard.WithWriteCacheOptions(writeCacheOpts...),
|
2022-09-26 18:31:45 +00:00
|
|
|
shard.WithRemoverBatchSize(shCfg.gcCfg.removerBatchSize),
|
|
|
|
shard.WithGCRemoverSleepInterval(shCfg.gcCfg.removerSleepInterval),
|
2021-07-28 16:19:33 +00:00
|
|
|
shard.WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
|
2021-02-16 11:40:06 +00:00
|
|
|
pool, err := ants.NewPool(sz)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
return pool
|
|
|
|
}),
|
2022-09-26 22:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shards = append(shards, sh)
|
2022-09-26 18:31:45 +00:00
|
|
|
}
|
|
|
|
|
2022-09-26 22:02:20 +00:00
|
|
|
return shards
|
2022-09-26 18:31:45 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
func (c *cfg) loggerPrm() (*logger.Prm, error) {
|
|
|
|
// check if it has been inited before
|
|
|
|
if c.dynamicConfiguration.logger == nil {
|
|
|
|
c.dynamicConfiguration.logger = new(logger.Prm)
|
|
|
|
}
|
|
|
|
|
|
|
|
// (re)init read configuration
|
|
|
|
err := c.dynamicConfiguration.logger.SetLevelString(c.LoggerCfg.level)
|
|
|
|
if err != nil {
|
|
|
|
// not expected since validation should be performed before
|
|
|
|
panic(fmt.Sprintf("incorrect log level format: %s", c.LoggerCfg.level))
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.dynamicConfiguration.logger, nil
|
|
|
|
}
|
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
func (c *cfg) LocalAddress() network.AddressGroup {
|
|
|
|
return c.localAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
func initLocalStorage(c *cfg) {
|
|
|
|
ls := engine.New(c.engineOpts()...)
|
|
|
|
|
|
|
|
addNewEpochAsyncNotificationHandler(c, func(ev event.Event) {
|
|
|
|
ls.HandleNewEpoch(ev.(netmap2.NewEpoch).EpochNumber())
|
2021-06-01 18:27:15 +00:00
|
|
|
})
|
2022-09-26 18:31:45 +00:00
|
|
|
|
|
|
|
// allocate memory for the service;
|
|
|
|
// service will be created later
|
|
|
|
c.cfgObject.getSvc = new(getsvc.Service)
|
|
|
|
|
|
|
|
var tssPrm tsourse.TombstoneSourcePrm
|
|
|
|
tssPrm.SetGetService(c.cfgObject.getSvc)
|
|
|
|
tombstoneSrc := tsourse.NewSource(tssPrm)
|
|
|
|
|
|
|
|
tombstoneSource := tombstone.NewChecker(
|
|
|
|
tombstone.WithLogger(c.log),
|
|
|
|
tombstone.WithTombstoneSource(tombstoneSrc),
|
|
|
|
)
|
|
|
|
|
2022-09-26 22:02:20 +00:00
|
|
|
for _, optsWithMeta := range c.shardOpts() {
|
|
|
|
id, err := ls.AddShard(append(optsWithMeta.shOpts, shard.WithTombstoneSource(tombstoneSource))...)
|
2022-09-26 18:31:45 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
c.log.Info("shard attached to engine",
|
|
|
|
zap.Stringer("id", id),
|
|
|
|
)
|
2022-09-20 12:33:59 +00:00
|
|
|
}
|
2020-12-01 14:57:37 +00:00
|
|
|
|
2022-09-26 18:31:45 +00:00
|
|
|
c.cfgObject.cfgLocalStorage.localStorage = ls
|
|
|
|
|
|
|
|
c.onShutdown(func() {
|
|
|
|
c.log.Info("closing components of the storage engine...")
|
|
|
|
|
|
|
|
err := ls.Close()
|
|
|
|
if err != nil {
|
|
|
|
c.log.Info("storage engine closing failure",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
c.log.Info("all components of the storage engine closed successfully")
|
|
|
|
}
|
|
|
|
})
|
2020-11-19 10:58:27 +00:00
|
|
|
}
|
|
|
|
|
2021-06-02 12:36:39 +00:00
|
|
|
func initObjectPool(cfg *config.Config) (pool cfgObjectRoutines) {
|
2020-11-09 15:40:06 +00:00
|
|
|
var err error
|
|
|
|
|
2020-11-23 12:09:41 +00:00
|
|
|
optNonBlocking := ants.WithNonblocking(true)
|
|
|
|
|
2021-11-10 08:34:00 +00:00
|
|
|
pool.putRemoteCapacity = objectconfig.Put(cfg).PoolSizeRemote()
|
|
|
|
|
|
|
|
pool.putRemote, err = ants.NewPool(pool.putRemoteCapacity, optNonBlocking)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
pool.replication, err = ants.NewPool(pool.putRemoteCapacity)
|
|
|
|
fatalOnErr(err)
|
2021-09-24 10:36:54 +00:00
|
|
|
|
2020-11-09 15:40:06 +00:00
|
|
|
return pool
|
|
|
|
}
|
2021-01-25 08:23:06 +00:00
|
|
|
|
|
|
|
func (c *cfg) LocalNodeInfo() (*netmapV2.NodeInfo, error) {
|
2022-06-08 23:18:26 +00:00
|
|
|
var res netmapV2.NodeInfo
|
|
|
|
|
|
|
|
ni, ok := c.cfgNetmap.state.getNodeInfo()
|
|
|
|
if ok {
|
|
|
|
ni.WriteToV2(&res)
|
|
|
|
} else {
|
|
|
|
c.cfgNodeInfo.localInfo.WriteToV2(&res)
|
2021-01-25 08:23:06 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
return &res, nil
|
2021-01-25 08:23:06 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
// handleLocalNodeInfo rewrites local node info from the NeoFS network map.
|
|
|
|
// Called with nil when storage node is outside the NeoFS network map
|
|
|
|
// (before entering the network and after leaving it).
|
2021-06-11 10:55:11 +00:00
|
|
|
func (c *cfg) handleLocalNodeInfo(ni *netmap.NodeInfo) {
|
|
|
|
c.cfgNetmap.state.setNodeInfo(ni)
|
2021-01-25 08:23:06 +00:00
|
|
|
}
|
|
|
|
|
2022-10-28 07:02:55 +00:00
|
|
|
// bootstrapWithState calls "addPeer" method of the Sidechain Netmap contract
|
|
|
|
// with the binary-encoded information from the current node's configuration.
|
|
|
|
// The state is set using the provided setter which MUST NOT be nil.
|
|
|
|
func (c *cfg) bootstrapWithState(stateSetter func(*netmap.NodeInfo)) error {
|
2021-06-11 10:55:11 +00:00
|
|
|
ni := c.cfgNodeInfo.localInfo
|
2022-10-28 07:02:55 +00:00
|
|
|
stateSetter(&ni)
|
2022-10-17 15:28:22 +00:00
|
|
|
|
2022-10-28 07:02:55 +00:00
|
|
|
prm := nmClient.AddPeerPrm{}
|
|
|
|
prm.SetNodeInfo(ni)
|
2022-10-17 15:28:22 +00:00
|
|
|
|
2022-10-28 07:02:55 +00:00
|
|
|
return c.cfgNetmap.wrapper.AddPeer(prm)
|
|
|
|
}
|
2022-10-17 15:28:22 +00:00
|
|
|
|
2022-10-28 07:02:55 +00:00
|
|
|
// bootstrapOnline calls cfg.bootstrapWithState with "online" state.
|
|
|
|
func bootstrapOnline(c *cfg) error {
|
|
|
|
return c.bootstrapWithState((*netmap.NodeInfo).SetOnline)
|
|
|
|
}
|
|
|
|
|
|
|
|
// bootstrap calls bootstrapWithState with:
|
|
|
|
// - "maintenance" state if maintenance is in progress on the current node
|
|
|
|
// - "online", otherwise
|
|
|
|
func (c *cfg) bootstrap() error {
|
|
|
|
// switch to online except when under maintenance
|
|
|
|
st := c.cfgNetmap.state.controlNetmapStatus()
|
|
|
|
if st == control.NetmapStatus_MAINTENANCE {
|
|
|
|
c.log.Info("bootstrapping with the maintenance state")
|
|
|
|
return c.bootstrapWithState((*netmap.NodeInfo).SetMaintenance)
|
2022-10-17 15:28:22 +00:00
|
|
|
}
|
2021-01-25 08:23:06 +00:00
|
|
|
|
2022-10-28 07:02:55 +00:00
|
|
|
c.log.Info("bootstrapping with online state",
|
|
|
|
zap.Stringer("previous", st),
|
|
|
|
)
|
2021-11-10 11:05:51 +00:00
|
|
|
|
2022-10-28 07:02:55 +00:00
|
|
|
return bootstrapOnline(c)
|
2021-02-03 14:59:57 +00:00
|
|
|
}
|
2021-08-24 07:43:21 +00:00
|
|
|
|
|
|
|
// needBootstrap checks if local node should be registered in network on bootup.
|
|
|
|
func (c *cfg) needBootstrap() bool {
|
|
|
|
return c.cfgNetmap.needBootstrap
|
|
|
|
}
|
2021-11-10 08:34:00 +00:00
|
|
|
|
|
|
|
// ObjectServiceLoad implements system loader interface for policer component.
|
|
|
|
// It is calculated as size/capacity ratio of "remote object put" worker.
|
|
|
|
// Returns float value between 0.0 and 1.0.
|
|
|
|
func (c *cfg) ObjectServiceLoad() float64 {
|
|
|
|
return float64(c.cfgObject.pool.putRemote.Running()) / float64(c.cfgObject.pool.putRemoteCapacity)
|
|
|
|
}
|
2022-09-26 22:02:20 +00:00
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
type dCfg struct {
|
|
|
|
name string
|
|
|
|
cfg interface {
|
|
|
|
Reload() error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 22:02:20 +00:00
|
|
|
func (c *cfg) configWatcher(ctx context.Context) {
|
|
|
|
ch := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(ch, syscall.SIGHUP)
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ch:
|
|
|
|
c.log.Info("SIGHUP has been received, rereading configuration...")
|
|
|
|
|
|
|
|
err := c.readConfig(c.appCfg)
|
|
|
|
if err != nil {
|
|
|
|
c.log.Error("configuration reading", zap.Error(err))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
// all the components are expected to support
|
|
|
|
// Logger's dynamic reconfiguration approach
|
|
|
|
var components []dCfg
|
|
|
|
|
|
|
|
// Logger
|
|
|
|
|
|
|
|
logPrm, err := c.loggerPrm()
|
|
|
|
if err != nil {
|
|
|
|
c.log.Error("logger configuration preparation", zap.Error(err))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
components = append(components, dCfg{name: "logger", cfg: logPrm})
|
|
|
|
|
|
|
|
// Storage Engine
|
|
|
|
|
2022-09-26 22:02:20 +00:00
|
|
|
var rcfg engine.ReConfiguration
|
2022-10-05 12:53:42 +00:00
|
|
|
for _, optsWithID := range c.shardOpts() {
|
|
|
|
rcfg.AddShard(optsWithID.configID, optsWithID.shOpts)
|
2022-09-26 22:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = c.cfgObject.cfgLocalStorage.localStorage.Reload(rcfg)
|
|
|
|
if err != nil {
|
|
|
|
c.log.Error("storage engine configuration update", zap.Error(err))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:19:23 +00:00
|
|
|
for _, component := range components {
|
|
|
|
err = component.cfg.Reload()
|
|
|
|
if err != nil {
|
|
|
|
c.log.Error("updated configuration applying",
|
|
|
|
zap.String("component", component.name),
|
|
|
|
zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 22:02:20 +00:00
|
|
|
c.log.Info("configuration has been reloaded successfully")
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|