2020-08-21 15:01:59 +00:00
|
|
|
package main
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2020-08-24 09:40:32 +00:00
|
|
|
"net"
|
2020-11-19 10:58:27 +00:00
|
|
|
"path"
|
2020-08-22 11:03:45 +00:00
|
|
|
"sync"
|
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-08-25 10:49:59 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
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"
|
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"
|
|
|
|
"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"
|
2020-11-19 10:58:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
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"
|
2020-09-24 07:46:47 +00:00
|
|
|
nmwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
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"
|
2021-04-15 14:57:29 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/timer"
|
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"
|
2021-08-30 11:16:41 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl"
|
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"
|
2020-08-24 15:51:42 +00:00
|
|
|
tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
|
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
|
|
|
apiclient "github.com/nspcc-dev/neofs-sdk-go/client"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
|
|
|
"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
|
|
|
)
|
|
|
|
|
2021-06-02 12:36:39 +00:00
|
|
|
const addressSize = 72 // 32 bytes oid, 32 bytes cid, 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
|
|
|
|
|
2020-08-21 15:01:59 +00:00
|
|
|
type cfg struct {
|
2020-08-22 11:03:45 +00:00
|
|
|
ctx context.Context
|
|
|
|
|
2021-06-01 11:13:44 +00:00
|
|
|
appCfg *config.Config
|
|
|
|
|
2021-01-12 11:05:08 +00:00
|
|
|
ctxCancel func()
|
|
|
|
|
|
|
|
internalErr chan error // channel for internal application errors at runtime
|
|
|
|
|
2020-09-25 12:34:17 +00:00
|
|
|
log *zap.Logger
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
wg *sync.WaitGroup
|
|
|
|
|
2021-05-31 08:55:38 +00:00
|
|
|
key *keys.PrivateKey
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2021-11-08 12:10:49 +00:00
|
|
|
ownerIDFromKey *owner.ID // owner ID calculated from key
|
|
|
|
|
2021-11-10 07:08:33 +00:00
|
|
|
apiVersion *version.Version
|
2020-10-08 13:16:00 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
cfgGRPC cfgGRPC
|
|
|
|
|
|
|
|
cfgMorph cfgMorph
|
|
|
|
|
|
|
|
cfgAccounting cfgAccounting
|
2020-08-24 14:07:08 +00:00
|
|
|
|
|
|
|
cfgContainer cfgContainer
|
2020-08-24 15:51:42 +00:00
|
|
|
|
2020-08-31 15:19:21 +00:00
|
|
|
cfgNetmap cfgNetmap
|
|
|
|
|
2020-08-24 15:51:42 +00:00
|
|
|
privateTokenStore *tokenStorage.TokenStore
|
2020-08-31 15:19:21 +00:00
|
|
|
|
|
|
|
cfgNodeInfo cfgNodeInfo
|
2020-09-23 13:31:51 +00:00
|
|
|
|
2021-06-22 10:25:44 +00:00
|
|
|
localAddr network.AddressGroup
|
2020-09-23 13:55:46 +00:00
|
|
|
|
|
|
|
cfgObject cfgObject
|
2020-10-02 13:18:38 +00:00
|
|
|
|
2021-03-16 08:14:56 +00:00
|
|
|
metricsCollector *metrics.StorageMetrics
|
2021-03-15 13:11:40 +00:00
|
|
|
|
2020-10-03 09:57:02 +00:00
|
|
|
workers []worker
|
2020-10-22 11:07:06 +00:00
|
|
|
|
|
|
|
respSvc *response.Service
|
2021-01-13 12:51:05 +00:00
|
|
|
|
2021-01-13 13:46:39 +00:00
|
|
|
cfgControlService cfgControlService
|
2021-01-13 13:36:41 +00:00
|
|
|
|
|
|
|
healthStatus *atomic.Int32
|
2021-01-18 08:56:14 +00:00
|
|
|
|
|
|
|
closers []func()
|
2021-03-23 18:54:00 +00:00
|
|
|
|
|
|
|
cfgReputation cfgReputation
|
2021-05-11 10:24:13 +00:00
|
|
|
|
2021-07-13 11:12:23 +00:00
|
|
|
clientCache *cache.ClientCache
|
2021-09-06 13:05:45 +00:00
|
|
|
|
|
|
|
persistate *state.PersistentStorage
|
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
|
|
|
|
2021-08-25 10:49:59 +00:00
|
|
|
notaryEnabled bool
|
|
|
|
notaryDepositAmount fixedn.Fixed8
|
|
|
|
notaryDepositDuration uint32
|
|
|
|
|
2021-07-29 15:57:53 +00:00
|
|
|
disableCache bool
|
|
|
|
|
2021-04-15 14:57:29 +00:00
|
|
|
blockTimers []*timer.BlockTimer // all combined timers
|
|
|
|
eigenTrustTimer *timer.BlockTimer // timer 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
|
2020-09-24 07:46:47 +00:00
|
|
|
wrapper *nmwrapper.Wrapper
|
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 {
|
2021-07-29 15:57:53 +00:00
|
|
|
netMapSource netmapCore.Source
|
2020-09-23 13:55:46 +00:00
|
|
|
|
2021-07-29 15:57:53 +00:00
|
|
|
cnrSource container.Source
|
2020-09-29 12:38:44 +00:00
|
|
|
|
2021-08-30 11:16:41 +00:00
|
|
|
eaclSource eacl.Source
|
2020-11-09 15:40:06 +00:00
|
|
|
|
|
|
|
pool cfgObjectRoutines
|
2020-11-19 10:58:27 +00:00
|
|
|
|
|
|
|
cfgLocalStorage cfgLocalStorage
|
|
|
|
}
|
|
|
|
|
|
|
|
type cfgLocalStorage struct {
|
|
|
|
localStorage *engine.StorageEngine
|
|
|
|
|
|
|
|
shardOpts [][]shard.Option
|
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")
|
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
func initCfg(path string) *cfg {
|
2021-05-21 18:04:53 +00:00
|
|
|
var p config.Prm
|
|
|
|
|
|
|
|
appCfg := config.New(p,
|
|
|
|
config.WithConfigFile(path),
|
|
|
|
)
|
|
|
|
|
2021-06-04 11:02:22 +00:00
|
|
|
key := nodeconfig.Key(appCfg)
|
2020-09-16 07:45:08 +00:00
|
|
|
|
2022-01-21 12:15:10 +00:00
|
|
|
ownerIDFromKey := owner.NewIDFromPublicKey(&key.PrivateKey.PublicKey)
|
2021-11-08 12:10:49 +00:00
|
|
|
|
2021-05-11 08:54:59 +00:00
|
|
|
var logPrm logger.Prm
|
|
|
|
|
2022-01-21 12:15:10 +00:00
|
|
|
err := logPrm.SetLevelString(
|
2021-05-21 18:04:53 +00:00
|
|
|
loggerconfig.Level(appCfg),
|
2021-05-11 08:54:59 +00:00
|
|
|
)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
log, err := logger.NewLogger(logPrm)
|
2020-09-25 12:34:17 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2021-06-22 17:35:56 +00:00
|
|
|
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)
|
|
|
|
|
2021-06-01 17:50:46 +00:00
|
|
|
relayOnly := nodeconfig.Relay(appCfg)
|
2021-04-27 11:54:02 +00:00
|
|
|
|
2020-09-24 12:32:30 +00:00
|
|
|
c := &cfg{
|
2021-01-12 11:05:08 +00:00
|
|
|
ctx: context.Background(),
|
2021-06-01 11:13:44 +00:00
|
|
|
appCfg: appCfg,
|
2021-01-12 11:05:08 +00:00
|
|
|
internalErr: make(chan error),
|
|
|
|
log: log,
|
|
|
|
wg: new(sync.WaitGroup),
|
|
|
|
key: key,
|
2021-11-10 07:08:33 +00:00
|
|
|
apiVersion: version.Current(),
|
2020-08-24 09:40:32 +00:00
|
|
|
cfgAccounting: cfgAccounting{
|
2021-06-01 12:54:55 +00:00
|
|
|
scriptHash: contractsconfig.Balance(appCfg),
|
2020-08-22 15:20:47 +00:00
|
|
|
},
|
2020-08-24 14:07:08 +00:00
|
|
|
cfgContainer: cfgContainer{
|
2021-06-01 12:54:55 +00:00
|
|
|
scriptHash: contractsconfig.Container(appCfg),
|
2021-04-13 12:15:36 +00:00
|
|
|
workerPool: containerWorkerPool,
|
2020-08-24 14:07:08 +00:00
|
|
|
},
|
2020-08-31 15:19:21 +00:00
|
|
|
cfgNetmap: cfgNetmap{
|
2021-06-01 12:54:55 +00:00
|
|
|
scriptHash: contractsconfig.Netmap(appCfg),
|
2021-09-06 13:05:45 +00:00
|
|
|
state: netState,
|
2021-04-13 12:15:36 +00:00
|
|
|
workerPool: netmapWorkerPool,
|
2021-08-24 07:31:05 +00:00
|
|
|
needBootstrap: !relayOnly,
|
2021-04-27 11:54:02 +00:00
|
|
|
reBoostrapTurnedOff: atomic.NewBool(relayOnly),
|
2020-08-31 15:19:21 +00:00
|
|
|
},
|
2020-09-30 08:39:45 +00:00
|
|
|
cfgGRPC: cfgGRPC{
|
2021-05-12 08:00:46 +00:00
|
|
|
maxChunkSize: maxChunkSize,
|
|
|
|
maxAddrAmount: maxAddrAmount,
|
2020-09-30 08:39:45 +00:00
|
|
|
},
|
2021-08-31 14:02:42 +00:00
|
|
|
cfgMorph: cfgMorph{
|
|
|
|
proxyScriptHash: contractsconfig.Proxy(appCfg),
|
|
|
|
},
|
2021-06-22 17:35:56 +00:00
|
|
|
localAddr: netAddr,
|
2020-10-22 11:24:08 +00:00
|
|
|
respSvc: response.NewService(
|
2021-09-06 13:05:45 +00:00
|
|
|
response.WithNetworkState(netState),
|
2020-10-22 11:24:08 +00:00
|
|
|
),
|
2020-11-09 15:40:06 +00:00
|
|
|
cfgObject: cfgObject{
|
2021-06-02 12:36:39 +00:00
|
|
|
pool: initObjectPool(appCfg),
|
2020-11-09 15:40:06 +00:00
|
|
|
},
|
2021-01-15 10:23:46 +00:00
|
|
|
healthStatus: atomic.NewInt32(int32(control.HealthStatus_HEALTH_STATUS_UNDEFINED)),
|
2021-04-21 05:29:35 +00:00
|
|
|
cfgReputation: cfgReputation{
|
2021-06-01 12:54:55 +00:00
|
|
|
scriptHash: contractsconfig.Reputation(appCfg),
|
2021-04-21 05:29:35 +00:00
|
|
|
workerPool: reputationWorkerPool,
|
|
|
|
},
|
2021-07-13 11:12:23 +00:00
|
|
|
clientCache: cache.NewSDKClientCache(
|
|
|
|
apiclient.WithDialTimeout(apiclientconfig.DialTimeout(appCfg)),
|
|
|
|
),
|
2021-09-06 13:05:45 +00:00
|
|
|
persistate: persistate,
|
2021-11-08 12:10:49 +00:00
|
|
|
|
|
|
|
ownerIDFromKey: ownerIDFromKey,
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
2020-09-24 12:32:30 +00:00
|
|
|
|
2021-06-01 11:24:57 +00:00
|
|
|
if metricsconfig.Address(c.appCfg) != "" {
|
2021-03-16 08:14:56 +00:00
|
|
|
c.metricsCollector = metrics.NewStorageMetrics()
|
2021-12-28 10:39:42 +00:00
|
|
|
netState.metrics = c.metricsCollector
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 11:12:23 +00:00
|
|
|
c.onShutdown(c.clientCache.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
|
|
|
initLocalStorage(c)
|
|
|
|
|
|
|
|
return c
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
2020-09-16 07:45:08 +00:00
|
|
|
|
2021-06-22 10:25:44 +00:00
|
|
|
func (c *cfg) LocalAddress() network.AddressGroup {
|
2020-09-23 13:31:51 +00:00
|
|
|
return c.localAddr
|
|
|
|
}
|
2020-09-24 12:32:30 +00:00
|
|
|
|
|
|
|
func initLocalStorage(c *cfg) {
|
2020-11-19 10:58:27 +00:00
|
|
|
initShardOptions(c)
|
2020-09-24 12:32:30 +00:00
|
|
|
|
2021-10-08 13:25:56 +00:00
|
|
|
engineOpts := []engine.Option{
|
|
|
|
engine.WithLogger(c.log),
|
|
|
|
engine.WithShardPoolSize(engineconfig.ShardPoolSize(c.appCfg)),
|
|
|
|
}
|
2021-03-16 11:19:32 +00:00
|
|
|
if c.metricsCollector != nil {
|
|
|
|
engineOpts = append(engineOpts, engine.WithMetrics(c.metricsCollector))
|
|
|
|
}
|
|
|
|
|
|
|
|
ls := engine.New(engineOpts...)
|
2020-10-29 17:17:42 +00:00
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
for _, opts := range c.cfgObject.cfgLocalStorage.shardOpts {
|
|
|
|
id, err := ls.AddShard(opts...)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
c.log.Info("shard attached to engine",
|
|
|
|
zap.Stringer("id", id),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.cfgObject.cfgLocalStorage.localStorage = ls
|
2021-01-18 09:04:58 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func initShardOptions(c *cfg) {
|
|
|
|
var opts [][]shard.Option
|
|
|
|
|
2021-11-12 10:15:14 +00:00
|
|
|
require := !nodeconfig.Relay(c.appCfg) // relay node does not require shards
|
|
|
|
|
|
|
|
engineconfig.IterateShards(c.appCfg, require, func(sc *shardconfig.Config) {
|
2021-06-01 18:27:15 +00:00
|
|
|
var writeCacheOpts []writecache.Option
|
2020-12-01 09:26:19 +00:00
|
|
|
|
2021-06-01 18:27:15 +00:00
|
|
|
useWriteCache := sc.UseWriteCache()
|
|
|
|
if useWriteCache {
|
|
|
|
writeCacheCfg := sc.WriteCache()
|
2020-11-19 10:58:27 +00:00
|
|
|
|
2021-06-01 18:27:15 +00:00
|
|
|
writeCacheOpts = []writecache.Option{
|
|
|
|
writecache.WithPath(writeCacheCfg.Path()),
|
|
|
|
writecache.WithLogger(c.log),
|
|
|
|
writecache.WithMaxMemSize(writeCacheCfg.MemSize()),
|
|
|
|
writecache.WithMaxObjectSize(writeCacheCfg.MaxObjectSize()),
|
|
|
|
writecache.WithSmallObjectSize(writeCacheCfg.SmallObjectSize()),
|
|
|
|
writecache.WithFlushWorkersCount(writeCacheCfg.WorkersNumber()),
|
2021-09-08 09:46:12 +00:00
|
|
|
writecache.WithMaxCacheSize(writeCacheCfg.SizeLimit()),
|
2021-06-01 18:27:15 +00:00
|
|
|
}
|
2021-04-06 10:56:06 +00:00
|
|
|
}
|
2020-11-26 07:47:20 +00:00
|
|
|
|
2021-06-01 18:27:15 +00:00
|
|
|
blobStorCfg := sc.BlobStor()
|
|
|
|
blobovniczaCfg := blobStorCfg.Blobovnicza()
|
|
|
|
metabaseCfg := sc.Metabase()
|
|
|
|
gcCfg := sc.GC()
|
2020-11-19 10:58:27 +00:00
|
|
|
|
2021-06-01 18:27:15 +00:00
|
|
|
metaPath := metabaseCfg.Path()
|
|
|
|
metaPerm := metabaseCfg.Perm()
|
2021-07-28 16:19:33 +00:00
|
|
|
fatalOnErr(util.MkdirAllX(path.Dir(metaPath), metaPerm))
|
2020-11-19 10:58:27 +00:00
|
|
|
|
|
|
|
opts = append(opts, []shard.Option{
|
|
|
|
shard.WithLogger(c.log),
|
2021-09-13 13:58:05 +00:00
|
|
|
shard.WithRefillMetabase(sc.RefillMetabase()),
|
2021-12-27 11:05:30 +00:00
|
|
|
shard.WithMode(sc.Mode()),
|
2020-11-19 10:58:27 +00:00
|
|
|
shard.WithBlobStorOptions(
|
2021-06-01 18:27:15 +00:00
|
|
|
blobstor.WithRootPath(blobStorCfg.Path()),
|
2021-10-07 14:19:55 +00:00
|
|
|
blobstor.WithCompressObjects(blobStorCfg.Compress()),
|
2021-06-01 18:27:15 +00:00
|
|
|
blobstor.WithRootPerm(blobStorCfg.Perm()),
|
|
|
|
blobstor.WithShallowDepth(blobStorCfg.ShallowDepth()),
|
|
|
|
blobstor.WithSmallSizeLimit(blobStorCfg.SmallSizeLimit()),
|
|
|
|
blobstor.WithBlobovniczaSize(blobovniczaCfg.Size()),
|
|
|
|
blobstor.WithBlobovniczaShallowDepth(blobovniczaCfg.ShallowDepth()),
|
|
|
|
blobstor.WithBlobovniczaShallowWidth(blobovniczaCfg.ShallowWidth()),
|
|
|
|
blobstor.WithBlobovniczaOpenedCacheSize(blobovniczaCfg.OpenedCacheSize()),
|
2020-11-30 15:35:37 +00:00
|
|
|
blobstor.WithLogger(c.log),
|
2020-11-19 10:58:27 +00:00
|
|
|
),
|
|
|
|
shard.WithMetaBaseOptions(
|
|
|
|
meta.WithLogger(c.log),
|
2020-11-30 15:35:37 +00:00
|
|
|
meta.WithPath(metaPath),
|
|
|
|
meta.WithPermissions(metaPerm),
|
2021-01-18 13:04:13 +00:00
|
|
|
meta.WithBoltDBOptions(&bbolt.Options{
|
|
|
|
Timeout: 100 * time.Millisecond,
|
|
|
|
}),
|
2020-11-19 10:58:27 +00:00
|
|
|
),
|
2021-06-01 18:27:15 +00:00
|
|
|
shard.WithWriteCache(useWriteCache),
|
|
|
|
shard.WithWriteCacheOptions(writeCacheOpts...),
|
|
|
|
shard.WithRemoverBatchSize(gcCfg.RemoverBatchSize()),
|
|
|
|
shard.WithGCRemoverSleepInterval(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
|
|
|
|
}),
|
2021-02-17 12:19:54 +00:00
|
|
|
shard.WithGCEventChannelInitializer(func() <-chan shard.Event {
|
|
|
|
ch := make(chan shard.Event)
|
|
|
|
|
|
|
|
addNewEpochNotificationHandler(c, func(ev event.Event) {
|
|
|
|
ch <- shard.EventNewEpoch(ev.(netmap2.NewEpoch).EpochNumber())
|
|
|
|
})
|
|
|
|
|
|
|
|
return ch
|
|
|
|
}),
|
2020-11-19 10:58:27 +00:00
|
|
|
})
|
2021-06-01 18:27:15 +00:00
|
|
|
})
|
2020-12-01 14:57:37 +00:00
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
c.cfgObject.cfgLocalStorage.shardOpts = opts
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-06-11 10:55:11 +00:00
|
|
|
ni := c.cfgNetmap.state.getNodeInfo()
|
2021-01-25 08:23:06 +00:00
|
|
|
if ni != nil {
|
2021-06-11 10:55:11 +00:00
|
|
|
return ni.ToV2(), nil
|
2021-01-25 08:23:06 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 10:55:11 +00:00
|
|
|
return c.cfgNodeInfo.localInfo.ToV2(), nil
|
2021-01-25 08:23:06 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 10:55:11 +00:00
|
|
|
// handleLocalNodeInfo rewrites local node info from netmap
|
|
|
|
func (c *cfg) handleLocalNodeInfo(ni *netmap.NodeInfo) {
|
|
|
|
c.cfgNetmap.state.setNodeInfo(ni)
|
2021-01-25 08:23:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 07:25:27 +00:00
|
|
|
// bootstrap sets local node's netmap status to "online".
|
2021-06-11 10:55:11 +00:00
|
|
|
func (c *cfg) bootstrap() error {
|
|
|
|
ni := c.cfgNodeInfo.localInfo
|
2021-01-25 08:23:06 +00:00
|
|
|
ni.SetState(netmap.NodeStateOnline)
|
|
|
|
|
2021-11-10 11:05:51 +00:00
|
|
|
prm := nmwrapper.AddPeerPrm{}
|
|
|
|
prm.SetNodeInfo(&ni)
|
|
|
|
|
|
|
|
return c.cfgNetmap.wrapper.AddPeer(prm)
|
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)
|
|
|
|
}
|