2020-08-21 15:01:59 +00:00
|
|
|
package main
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2020-08-22 14:17:03 +00:00
|
|
|
"crypto/ecdsa"
|
2020-08-24 09:40:32 +00:00
|
|
|
"net"
|
2020-10-29 17:17:42 +00:00
|
|
|
"os"
|
2020-11-19 10:58:27 +00:00
|
|
|
"path"
|
|
|
|
"strconv"
|
2020-09-16 07:45:08 +00:00
|
|
|
"strings"
|
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
|
|
|
|
2020-08-22 15:20:47 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2020-10-08 13:16:00 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg"
|
2020-11-16 10:26:35 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
2020-08-22 14:17:03 +00:00
|
|
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
2020-09-16 07:45:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/misc"
|
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"
|
2020-09-24 12:32:30 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/bucket"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/bucket/fsbucket"
|
2020-11-19 10:58:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2020-11-30 15:35:37 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase/v2"
|
2020-11-19 10:58:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
2020-08-22 15:20:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2020-10-03 07:46:57 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
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"
|
2020-09-23 13:31:51 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
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"
|
2020-09-25 12:34:17 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2020-10-02 13:18:38 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/profiler"
|
2020-11-09 15:40:06 +00:00
|
|
|
"github.com/panjf2000/ants/v2"
|
2020-09-24 12:32:30 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-09-16 07:45:08 +00:00
|
|
|
"github.com/spf13/viper"
|
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
|
|
|
)
|
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
const (
|
2020-09-25 12:34:17 +00:00
|
|
|
// logger keys
|
|
|
|
cfgLogLevel = "logger.level"
|
|
|
|
cfgLogFormat = "logger.format"
|
|
|
|
cfgLogTrace = "logger.trace_level"
|
|
|
|
cfgLogInitSampling = "logger.sampling.initial"
|
|
|
|
cfgLogThereafterSampling = "logger.sampling.thereafter"
|
|
|
|
|
2020-10-02 13:18:38 +00:00
|
|
|
// pprof keys
|
|
|
|
cfgProfilerEnable = "pprof.enabled"
|
|
|
|
cfgProfilerAddr = "pprof.address"
|
|
|
|
cfgProfilerTTL = "pprof.shutdown_ttl"
|
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
// config keys for cfgNodeInfo
|
2020-09-22 11:02:32 +00:00
|
|
|
cfgNodeKey = "node.key"
|
|
|
|
cfgBootstrapAddress = "node.address"
|
|
|
|
cfgNodeAttributePrefix = "node.attribute"
|
2020-09-16 07:45:08 +00:00
|
|
|
|
|
|
|
// config keys for cfgGRPC
|
2020-10-14 20:35:48 +00:00
|
|
|
cfgListenAddress = "grpc.endpoint"
|
|
|
|
cfgMaxMsgSize = "grpc.maxmessagesize"
|
|
|
|
cfgReflectService = "grpc.enable_reflect_service"
|
2020-09-16 07:45:08 +00:00
|
|
|
|
|
|
|
// config keys for cfgMorph
|
|
|
|
cfgMorphRPCAddress = "morph.endpoint"
|
|
|
|
|
2020-10-21 09:26:16 +00:00
|
|
|
cfgMorphNotifyRPCAddress = "morph.notification.endpoint"
|
|
|
|
cfgMorphNotifyDialTimeout = "morph.notification.dial_timeout"
|
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
// config keys for cfgAccounting
|
|
|
|
cfgAccountingContract = "accounting.scripthash"
|
|
|
|
cfgAccountingFee = "accounting.fee"
|
|
|
|
|
|
|
|
// config keys for cfgNetmap
|
|
|
|
cfgNetmapContract = "netmap.scripthash"
|
|
|
|
cfgNetmapFee = "netmap.fee"
|
|
|
|
|
|
|
|
// config keys for cfgContainer
|
|
|
|
cfgContainerContract = "container.scripthash"
|
|
|
|
cfgContainerFee = "container.fee"
|
2020-09-29 12:38:44 +00:00
|
|
|
|
2020-10-05 10:44:28 +00:00
|
|
|
cfgGCQueueSize = "gc.queuesize"
|
|
|
|
cfgGCQueueTick = "gc.duration.sleep"
|
|
|
|
cfgGCTimeout = "gc.duration.timeout"
|
2020-10-21 09:28:42 +00:00
|
|
|
|
|
|
|
cfgPolicerWorkScope = "policer.work_scope"
|
|
|
|
cfgPolicerExpRate = "policer.expansion_rate"
|
|
|
|
cfgPolicerHeadTimeout = "policer.head_timeout"
|
2020-11-23 12:59:30 +00:00
|
|
|
cfgPolicerDialTimeout = "policer.dial_timeout"
|
2020-10-21 11:51:20 +00:00
|
|
|
|
2020-11-23 12:59:30 +00:00
|
|
|
cfgReplicatorPutTimeout = "replicator.put_timeout"
|
|
|
|
cfgReplicatorDialTimeout = "replicator.dial_timeout"
|
2020-10-30 12:57:49 +00:00
|
|
|
|
|
|
|
cfgReBootstrapEnabled = "bootstrap.periodic.enabled"
|
|
|
|
cfgReBootstrapInterval = "bootstrap.periodic.interval"
|
2020-11-09 15:40:06 +00:00
|
|
|
|
|
|
|
cfgObjectPutPoolSize = "pool.object.put.size"
|
|
|
|
cfgObjectGetPoolSize = "pool.object.get.size"
|
|
|
|
cfgObjectHeadPoolSize = "pool.object.head.size"
|
|
|
|
cfgObjectSearchPoolSize = "pool.object.search.size"
|
|
|
|
cfgObjectRangePoolSize = "pool.object.range.size"
|
|
|
|
cfgObjectRangeHashPoolSize = "pool.object.rangehash.size"
|
2020-11-23 12:59:30 +00:00
|
|
|
|
|
|
|
cfgObjectPutDialTimeout = "object.put.dial_timeout"
|
|
|
|
cfgObjectHeadDialTimeout = "object.head.dial_timeout"
|
|
|
|
cfgObjectRangeDialTimeout = "object.range.dial_timeout"
|
|
|
|
cfgObjectRangeHashDialTimeout = "object.rangehash.dial_timeout"
|
|
|
|
cfgObjectSearchDialTimeout = "object.search.dial_timeout"
|
2020-09-16 07:45:08 +00:00
|
|
|
)
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
const (
|
|
|
|
cfgLocalStorageSection = "storage"
|
|
|
|
cfgStorageShardSection = "shard"
|
|
|
|
|
2020-11-30 17:03:15 +00:00
|
|
|
cfgShardUseWriteCache = "use_write_cache"
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
cfgBlobStorSection = "blobstor"
|
2020-12-01 09:26:19 +00:00
|
|
|
cfgWriteCacheSection = "writecache"
|
2020-11-19 10:58:27 +00:00
|
|
|
cfgBlobStorCompress = "compress"
|
|
|
|
cfgBlobStorShallowDepth = "shallow_depth"
|
|
|
|
cfgBlobStorTreePath = "path"
|
|
|
|
cfgBlobStorTreePerm = "perm"
|
2020-11-26 07:47:20 +00:00
|
|
|
cfgBlobStorSmallSzLimit = "small_size_limit"
|
2020-11-19 10:58:27 +00:00
|
|
|
|
2020-11-30 15:35:37 +00:00
|
|
|
cfgBlobStorBlzSection = "blobovnicza"
|
|
|
|
cfgBlzSize = "size"
|
|
|
|
cfgBlzShallowDepth = "shallow_depth"
|
|
|
|
cfgBlzShallowWidth = "shallow_width"
|
|
|
|
cfgBlzOpenedCacheSize = "opened_cache_size"
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
cfgMetaBaseSection = "metabase"
|
|
|
|
cfgMetaBasePath = "path"
|
|
|
|
cfgMetaBasePerm = "perm"
|
|
|
|
)
|
|
|
|
|
2020-10-02 08:01:54 +00:00
|
|
|
const (
|
|
|
|
addressSize = 72 // 32 bytes oid, 32 bytes cid, 8 bytes protobuf encoding
|
|
|
|
)
|
|
|
|
|
2020-08-21 15:01:59 +00:00
|
|
|
type cfg struct {
|
2020-08-22 11:03:45 +00:00
|
|
|
ctx context.Context
|
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
viper *viper.Viper
|
|
|
|
|
2020-09-25 12:34:17 +00:00
|
|
|
log *zap.Logger
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
wg *sync.WaitGroup
|
|
|
|
|
2020-08-22 14:17:03 +00:00
|
|
|
key *ecdsa.PrivateKey
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2020-10-08 13:16:00 +00:00
|
|
|
apiVersion *pkg.Version
|
|
|
|
|
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
|
|
|
|
|
|
|
localAddr *network.Address
|
2020-09-23 13:55:46 +00:00
|
|
|
|
|
|
|
cfgObject cfgObject
|
2020-10-02 13:18:38 +00:00
|
|
|
|
|
|
|
profiler profiler.Profiler
|
2020-10-03 09:57:02 +00:00
|
|
|
|
|
|
|
workers []worker
|
2020-10-22 11:07:06 +00:00
|
|
|
|
|
|
|
respSvc *response.Service
|
2020-08-24 09:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cfgGRPC struct {
|
|
|
|
listener net.Listener
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
server *grpc.Server
|
2020-09-30 08:39:45 +00:00
|
|
|
|
|
|
|
maxChunkSize uint64
|
|
|
|
|
|
|
|
maxAddrAmount uint64
|
2020-10-14 20:35:48 +00:00
|
|
|
|
|
|
|
enableReflectService bool
|
2020-08-24 09:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cfgMorph struct {
|
|
|
|
client *client.Client
|
|
|
|
}
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
type cfgAccounting struct {
|
2020-09-16 07:45:08 +00:00
|
|
|
scriptHash util.Uint160
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
fee util.Fixed8
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 14:07:08 +00:00
|
|
|
type cfgContainer struct {
|
2020-09-16 07:45:08 +00:00
|
|
|
scriptHash util.Uint160
|
2020-08-24 14:07:08 +00:00
|
|
|
|
|
|
|
fee util.Fixed8
|
|
|
|
}
|
|
|
|
|
2020-08-31 15:19:21 +00:00
|
|
|
type cfgNetmap struct {
|
2020-09-16 07:45:08 +00:00
|
|
|
scriptHash util.Uint160
|
2020-09-24 07:46:47 +00:00
|
|
|
wrapper *nmwrapper.Wrapper
|
2020-08-31 15:19:21 +00:00
|
|
|
|
|
|
|
fee util.Fixed8
|
2020-10-21 09:26:16 +00:00
|
|
|
|
|
|
|
parsers map[event.Type]event.Parser
|
|
|
|
|
|
|
|
subscribers map[event.Type][]event.Handler
|
2020-10-21 15:12:31 +00:00
|
|
|
|
|
|
|
state *networkState
|
2020-10-30 12:57:49 +00:00
|
|
|
|
|
|
|
reBootstrapEnabled bool
|
|
|
|
reBootstrapInterval uint64 // in epochs
|
2020-08-31 15:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type BootstrapType uint32
|
|
|
|
|
|
|
|
type cfgNodeInfo struct {
|
2020-10-08 13:17:50 +00:00
|
|
|
// values from config
|
2020-09-22 11:02:32 +00:00
|
|
|
bootType BootstrapType
|
2020-11-16 10:26:35 +00:00
|
|
|
attributes []*netmap.NodeAttribute
|
2020-10-08 13:17:50 +00:00
|
|
|
|
|
|
|
// values at runtime
|
|
|
|
info *netmap.NodeInfo
|
2020-08-31 15:19:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 13:55:46 +00:00
|
|
|
type cfgObject struct {
|
|
|
|
netMapStorage netmapCore.Source
|
|
|
|
|
|
|
|
cnrStorage container.Source
|
2020-09-29 12:38:44 +00:00
|
|
|
|
2020-10-03 07:46:57 +00:00
|
|
|
cnrClient *wrapper.Wrapper
|
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 {
|
|
|
|
get, head, put, search, rng, rngHash *ants.Pool
|
2020-09-23 13:55:46 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 15:19:21 +00:00
|
|
|
const (
|
|
|
|
_ BootstrapType = iota
|
|
|
|
StorageNode
|
|
|
|
RelayNode
|
|
|
|
)
|
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
func initCfg(path string) *cfg {
|
|
|
|
viperCfg := initViper(path)
|
|
|
|
|
|
|
|
key, err := crypto.LoadPrivateKey(viperCfg.GetString(cfgNodeKey))
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
u160Accounting, err := util.Uint160DecodeStringLE(
|
|
|
|
viperCfg.GetString(cfgAccountingContract))
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
u160Netmap, err := util.Uint160DecodeStringLE(
|
|
|
|
viperCfg.GetString(cfgNetmapContract))
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
u160Container, err := util.Uint160DecodeStringLE(
|
|
|
|
viperCfg.GetString(cfgContainerContract))
|
2020-08-22 14:17:03 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2020-09-25 12:34:17 +00:00
|
|
|
log, err := logger.NewLogger(viperCfg)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
2020-09-24 08:27:14 +00:00
|
|
|
netAddr, err := network.AddressFromString(viperCfg.GetString(cfgBootstrapAddress))
|
2020-09-23 13:31:51 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2020-10-02 08:01:54 +00:00
|
|
|
maxChunkSize := viperCfg.GetUint64(cfgMaxMsgSize) * 3 / 4 // 25% to meta, 75% to payload
|
|
|
|
maxAddrAmount := maxChunkSize / addressSize // each address is about 72 bytes
|
|
|
|
|
2020-10-22 11:24:08 +00:00
|
|
|
state := newNetworkState()
|
|
|
|
|
2020-09-24 12:32:30 +00:00
|
|
|
c := &cfg{
|
2020-10-08 13:16:00 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
viper: viperCfg,
|
|
|
|
log: log,
|
|
|
|
wg: new(sync.WaitGroup),
|
|
|
|
key: key,
|
|
|
|
apiVersion: pkg.SDKVersion(),
|
2020-08-24 09:40:32 +00:00
|
|
|
cfgAccounting: cfgAccounting{
|
2020-09-16 07:45:08 +00:00
|
|
|
scriptHash: u160Accounting,
|
|
|
|
fee: util.Fixed8(viperCfg.GetInt(cfgAccountingFee)),
|
2020-08-22 15:20:47 +00:00
|
|
|
},
|
2020-08-24 14:07:08 +00:00
|
|
|
cfgContainer: cfgContainer{
|
2020-09-16 07:45:08 +00:00
|
|
|
scriptHash: u160Container,
|
|
|
|
fee: util.Fixed8(viperCfg.GetInt(cfgContainerFee)),
|
2020-08-24 14:07:08 +00:00
|
|
|
},
|
2020-08-31 15:19:21 +00:00
|
|
|
cfgNetmap: cfgNetmap{
|
2020-10-30 12:57:49 +00:00
|
|
|
scriptHash: u160Netmap,
|
|
|
|
fee: util.Fixed8(viperCfg.GetInt(cfgNetmapFee)),
|
|
|
|
state: state,
|
|
|
|
reBootstrapInterval: viperCfg.GetUint64(cfgReBootstrapInterval),
|
|
|
|
reBootstrapEnabled: viperCfg.GetBool(cfgReBootstrapEnabled),
|
2020-08-31 15:19:21 +00:00
|
|
|
},
|
|
|
|
cfgNodeInfo: cfgNodeInfo{
|
2020-09-22 11:02:32 +00:00
|
|
|
bootType: StorageNode,
|
2020-09-22 12:59:09 +00:00
|
|
|
attributes: parseAttributes(viperCfg),
|
2020-08-31 15:19:21 +00:00
|
|
|
},
|
2020-09-30 08:39:45 +00:00
|
|
|
cfgGRPC: cfgGRPC{
|
2020-10-14 20:35:48 +00:00
|
|
|
maxChunkSize: maxChunkSize,
|
|
|
|
maxAddrAmount: maxAddrAmount,
|
|
|
|
enableReflectService: viperCfg.GetBool(cfgReflectService),
|
2020-09-30 08:39:45 +00:00
|
|
|
},
|
2020-09-23 13:31:51 +00:00
|
|
|
localAddr: netAddr,
|
2020-10-22 11:24:08 +00:00
|
|
|
respSvc: response.NewService(
|
|
|
|
response.WithNetworkState(state),
|
|
|
|
),
|
2020-11-09 15:40:06 +00:00
|
|
|
cfgObject: cfgObject{
|
|
|
|
pool: initObjectPool(viperCfg),
|
|
|
|
},
|
2020-08-21 15:01:59 +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
|
|
|
|
|
|
|
func initViper(path string) *viper.Viper {
|
|
|
|
v := viper.New()
|
|
|
|
|
|
|
|
v.SetEnvPrefix(misc.Prefix)
|
|
|
|
v.AutomaticEnv()
|
|
|
|
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
|
|
|
|
|
|
|
v.SetDefault("app.name", misc.NodeName)
|
|
|
|
v.SetDefault("app.version", misc.Version)
|
|
|
|
|
|
|
|
defaultConfiguration(v)
|
|
|
|
|
|
|
|
if path != "" {
|
|
|
|
v.SetConfigFile(path)
|
|
|
|
v.SetConfigType("yml")
|
|
|
|
fatalOnErr(v.ReadInConfig())
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultConfiguration(v *viper.Viper) {
|
|
|
|
// fixme: all hardcoded private keys must be removed
|
|
|
|
v.SetDefault(cfgNodeKey, "Kwk6k2eC3L3QuPvD8aiaNyoSXgQ2YL1bwS5CP1oKoA9waeAze97s")
|
2020-10-23 11:06:55 +00:00
|
|
|
v.SetDefault(cfgBootstrapAddress, "") // address to bootstrap with
|
2020-09-16 07:45:08 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgMorphRPCAddress, "http://morph_chain.localtest.nspcc.ru:30333/")
|
2020-10-21 09:26:16 +00:00
|
|
|
v.SetDefault(cfgMorphNotifyRPCAddress, "ws://morph_chain:30333/ws")
|
|
|
|
v.SetDefault(cfgMorphNotifyDialTimeout, 5*time.Second)
|
2020-09-16 07:45:08 +00:00
|
|
|
v.SetDefault(cfgListenAddress, "127.0.0.1:50501") // listen address
|
2020-10-02 08:01:54 +00:00
|
|
|
v.SetDefault(cfgMaxMsgSize, 4<<20) // transport msg limit 4 MiB
|
2020-09-16 07:45:08 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgAccountingContract, "1aeefe1d0dfade49740fff779c02cd4a0538ffb1")
|
|
|
|
v.SetDefault(cfgAccountingFee, "1")
|
|
|
|
|
|
|
|
v.SetDefault(cfgContainerContract, "9d2ca84d7fb88213c4baced5a6ed4dc402309039")
|
|
|
|
v.SetDefault(cfgContainerFee, "1")
|
|
|
|
|
|
|
|
v.SetDefault(cfgNetmapContract, "75194459637323ea8837d2afe8225ec74a5658c3")
|
|
|
|
v.SetDefault(cfgNetmapFee, "1")
|
2020-09-25 12:34:17 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgLogLevel, "info")
|
|
|
|
v.SetDefault(cfgLogFormat, "console")
|
|
|
|
v.SetDefault(cfgLogTrace, "fatal")
|
|
|
|
v.SetDefault(cfgLogInitSampling, 1000)
|
|
|
|
v.SetDefault(cfgLogThereafterSampling, 1000)
|
2020-10-02 13:18:38 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgProfilerEnable, false)
|
|
|
|
v.SetDefault(cfgProfilerAddr, ":6060")
|
|
|
|
v.SetDefault(cfgProfilerTTL, "30s")
|
2020-10-05 10:44:28 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgGCQueueSize, 1000)
|
|
|
|
v.SetDefault(cfgGCQueueTick, "5s")
|
|
|
|
v.SetDefault(cfgGCTimeout, "5s")
|
2020-10-21 09:28:42 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgPolicerWorkScope, 100)
|
|
|
|
v.SetDefault(cfgPolicerExpRate, 10) // in %
|
|
|
|
v.SetDefault(cfgPolicerHeadTimeout, 5*time.Second)
|
2020-10-21 11:51:20 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgReplicatorPutTimeout, 5*time.Second)
|
2020-10-30 12:57:49 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgReBootstrapEnabled, false) // in epochs
|
|
|
|
v.SetDefault(cfgReBootstrapInterval, 2) // in epochs
|
2020-11-09 15:40:06 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgObjectGetPoolSize, 10)
|
|
|
|
v.SetDefault(cfgObjectHeadPoolSize, 10)
|
|
|
|
v.SetDefault(cfgObjectPutPoolSize, 10)
|
|
|
|
v.SetDefault(cfgObjectSearchPoolSize, 10)
|
|
|
|
v.SetDefault(cfgObjectRangePoolSize, 10)
|
|
|
|
v.SetDefault(cfgObjectRangeHashPoolSize, 10)
|
2020-09-16 07:45:08 +00:00
|
|
|
}
|
2020-09-23 13:31:51 +00:00
|
|
|
|
|
|
|
func (c *cfg) LocalAddress() *network.Address {
|
|
|
|
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
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
ls := engine.New(
|
|
|
|
engine.WithLogger(c.log),
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func initShardOptions(c *cfg) {
|
|
|
|
var opts [][]shard.Option
|
|
|
|
|
|
|
|
for i := 0; ; i++ {
|
|
|
|
prefix := configPath(
|
|
|
|
cfgLocalStorageSection,
|
|
|
|
cfgStorageShardSection,
|
|
|
|
strconv.Itoa(i),
|
|
|
|
)
|
|
|
|
|
2020-11-30 17:03:15 +00:00
|
|
|
useCache := c.viper.GetBool(
|
|
|
|
configPath(prefix, cfgShardUseWriteCache),
|
|
|
|
)
|
|
|
|
|
2020-12-01 09:26:19 +00:00
|
|
|
writeCachePrefix := configPath(prefix, cfgWriteCacheSection)
|
|
|
|
|
|
|
|
writeCachePath := c.viper.GetString(
|
|
|
|
configPath(writeCachePrefix, cfgBlobStorTreePath),
|
|
|
|
)
|
|
|
|
if useCache && writeCachePath == "" {
|
2020-12-01 14:57:37 +00:00
|
|
|
c.log.Warn("incorrect writeCache path, ignore shard")
|
2020-12-01 09:26:19 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
blobPrefix := configPath(prefix, cfgBlobStorSection)
|
|
|
|
|
|
|
|
blobPath := c.viper.GetString(
|
|
|
|
configPath(blobPrefix, cfgBlobStorTreePath),
|
|
|
|
)
|
|
|
|
if blobPath == "" {
|
2020-12-01 14:57:37 +00:00
|
|
|
c.log.Warn("incorrect blobStor path, ignore shard")
|
2020-11-19 10:58:27 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
compressObjects := c.viper.GetBool(
|
|
|
|
configPath(blobPrefix, cfgBlobStorCompress),
|
|
|
|
)
|
|
|
|
|
|
|
|
blobPerm := os.FileMode(c.viper.GetInt(
|
|
|
|
configPath(blobPrefix, cfgBlobStorTreePerm),
|
|
|
|
))
|
|
|
|
|
|
|
|
shallowDepth := c.viper.GetInt(
|
|
|
|
configPath(blobPrefix, cfgBlobStorShallowDepth),
|
|
|
|
)
|
|
|
|
|
2020-11-26 07:47:20 +00:00
|
|
|
smallSzLimit := c.viper.GetUint64(
|
|
|
|
configPath(blobPrefix, cfgBlobStorSmallSzLimit),
|
|
|
|
)
|
|
|
|
|
2020-11-30 15:35:37 +00:00
|
|
|
blzPrefix := configPath(blobPrefix, cfgBlobStorBlzSection)
|
|
|
|
|
|
|
|
blzSize := c.viper.GetUint64(
|
|
|
|
configPath(blzPrefix, cfgBlzSize),
|
|
|
|
)
|
|
|
|
|
|
|
|
blzShallowDepth := c.viper.GetUint64(
|
|
|
|
configPath(blzPrefix, cfgBlzShallowDepth),
|
|
|
|
)
|
|
|
|
|
|
|
|
blzShallowWidth := c.viper.GetUint64(
|
|
|
|
configPath(blzPrefix, cfgBlzShallowWidth),
|
|
|
|
)
|
|
|
|
|
|
|
|
blzCacheSize := c.viper.GetInt(
|
|
|
|
configPath(blzPrefix, cfgBlzOpenedCacheSize),
|
|
|
|
)
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
metaPrefix := configPath(prefix, cfgMetaBaseSection)
|
|
|
|
|
|
|
|
metaPath := c.viper.GetString(
|
|
|
|
configPath(metaPrefix, cfgMetaBasePath),
|
|
|
|
)
|
|
|
|
|
|
|
|
metaPerm := os.FileMode(c.viper.GetUint32(
|
|
|
|
configPath(metaPrefix, cfgMetaBasePerm),
|
|
|
|
))
|
|
|
|
|
|
|
|
fatalOnErr(os.MkdirAll(path.Dir(metaPath), metaPerm))
|
|
|
|
|
|
|
|
opts = append(opts, []shard.Option{
|
|
|
|
shard.WithLogger(c.log),
|
|
|
|
shard.WithBlobStorOptions(
|
2020-12-01 09:50:16 +00:00
|
|
|
blobstor.WithRootPath(blobPath),
|
2020-11-19 10:58:27 +00:00
|
|
|
blobstor.WithCompressObjects(compressObjects, c.log),
|
2020-12-01 09:50:16 +00:00
|
|
|
blobstor.WithRootPerm(blobPerm),
|
2020-11-19 10:58:27 +00:00
|
|
|
blobstor.WithShallowDepth(shallowDepth),
|
2020-11-26 07:47:20 +00:00
|
|
|
blobstor.WithSmallSizeLimit(smallSzLimit),
|
2020-11-30 15:35:37 +00:00
|
|
|
blobstor.WithBlobovniczaSize(blzSize),
|
|
|
|
blobstor.WithBlobovniczaShallowDepth(blzShallowDepth),
|
|
|
|
blobstor.WithBlobovniczaShallowWidth(blzShallowWidth),
|
|
|
|
blobstor.WithBlobovniczaOpenedCacheSize(blzCacheSize),
|
|
|
|
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),
|
2020-11-19 10:58:27 +00:00
|
|
|
),
|
2020-11-30 17:03:15 +00:00
|
|
|
shard.WithWriteCache(useCache),
|
2020-12-01 09:26:19 +00:00
|
|
|
shard.WithWriteCacheOptions(
|
2020-12-01 09:50:16 +00:00
|
|
|
blobstor.WithRootPath(writeCachePath),
|
2020-12-01 16:14:42 +00:00
|
|
|
blobstor.WithBlobovniczaShallowDepth(0),
|
|
|
|
blobstor.WithBlobovniczaShallowWidth(1),
|
2020-12-01 09:26:19 +00:00
|
|
|
),
|
2020-11-19 10:58:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
c.log.Info("storage shard options",
|
2020-11-30 17:03:15 +00:00
|
|
|
zap.Bool("with write cache", useCache),
|
2020-12-01 09:26:19 +00:00
|
|
|
zap.String("with write cache path", writeCachePath),
|
2020-11-19 10:58:27 +00:00
|
|
|
zap.String("BLOB path", blobPath),
|
|
|
|
zap.Stringer("BLOB permissions", blobPerm),
|
|
|
|
zap.Bool("BLOB compress", compressObjects),
|
|
|
|
zap.Int("BLOB shallow depth", shallowDepth),
|
2020-11-26 07:47:20 +00:00
|
|
|
zap.Uint64("BLOB small size limit", smallSzLimit),
|
2020-11-19 10:58:27 +00:00
|
|
|
zap.String("metabase path", metaPath),
|
|
|
|
zap.Stringer("metabase permissions", metaPerm),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-01 14:57:37 +00:00
|
|
|
if len(opts) == 0 {
|
|
|
|
fatalOnErr(errors.New("no correctly set up shards, exit"))
|
|
|
|
}
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
c.cfgObject.cfgLocalStorage.shardOpts = opts
|
|
|
|
}
|
|
|
|
|
|
|
|
func configPath(sections ...string) string {
|
|
|
|
return strings.Join(sections, ".")
|
2020-09-24 12:32:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initBucket(prefix string, c *cfg) (bucket bucket.Bucket, err error) {
|
|
|
|
const inmemory = "inmemory"
|
|
|
|
|
|
|
|
switch c.viper.GetString(prefix + ".type") {
|
|
|
|
case inmemory:
|
|
|
|
bucket = newBucket()
|
|
|
|
c.log.Info("using in-memory bucket", zap.String("storage", prefix))
|
|
|
|
case fsbucket.Name:
|
|
|
|
bucket, err = fsbucket.NewBucket(prefix, c.viper)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "can't create fs bucket")
|
|
|
|
}
|
|
|
|
c.log.Info("using filesystem bucket", zap.String("storage", prefix))
|
|
|
|
default:
|
|
|
|
return nil, errors.New("unknown storage type")
|
|
|
|
}
|
|
|
|
|
|
|
|
return bucket, nil
|
|
|
|
}
|
2020-11-09 15:40:06 +00:00
|
|
|
|
|
|
|
func initObjectPool(cfg *viper.Viper) (pool cfgObjectRoutines) {
|
|
|
|
var err error
|
|
|
|
|
2020-11-23 12:09:41 +00:00
|
|
|
optNonBlocking := ants.WithNonblocking(true)
|
|
|
|
|
|
|
|
pool.get, err = ants.NewPool(cfg.GetInt(cfgObjectGetPoolSize), optNonBlocking)
|
2020-11-09 15:40:06 +00:00
|
|
|
if err != nil {
|
|
|
|
fatalOnErr(err)
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:09:41 +00:00
|
|
|
pool.head, err = ants.NewPool(cfg.GetInt(cfgObjectHeadPoolSize), optNonBlocking)
|
2020-11-09 15:40:06 +00:00
|
|
|
if err != nil {
|
|
|
|
fatalOnErr(err)
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:09:41 +00:00
|
|
|
pool.search, err = ants.NewPool(cfg.GetInt(cfgObjectSearchPoolSize), optNonBlocking)
|
2020-11-09 15:40:06 +00:00
|
|
|
if err != nil {
|
|
|
|
fatalOnErr(err)
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:09:41 +00:00
|
|
|
pool.put, err = ants.NewPool(cfg.GetInt(cfgObjectPutPoolSize), optNonBlocking)
|
2020-11-09 15:40:06 +00:00
|
|
|
if err != nil {
|
|
|
|
fatalOnErr(err)
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:09:41 +00:00
|
|
|
pool.rng, err = ants.NewPool(cfg.GetInt(cfgObjectRangePoolSize), optNonBlocking)
|
2020-11-09 15:40:06 +00:00
|
|
|
if err != nil {
|
|
|
|
fatalOnErr(err)
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:09:41 +00:00
|
|
|
pool.rngHash, err = ants.NewPool(cfg.GetInt(cfgObjectRangeHashPoolSize), optNonBlocking)
|
2020-11-09 15:40:06 +00:00
|
|
|
if err != nil {
|
|
|
|
fatalOnErr(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return pool
|
|
|
|
}
|