[#168] node: Refactor node config

Resolve containedctx linter for cfg

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-03-23 17:59:14 +03:00
parent 8426d25f4b
commit a7c79c773a
20 changed files with 93 additions and 83 deletions

View file

@ -1,6 +1,7 @@
package engine
import (
"context"
"errors"
"fmt"
"path/filepath"
@ -68,7 +69,7 @@ func (e *StorageEngine) open() error {
}
// Init initializes all StorageEngine's components.
func (e *StorageEngine) Init() error {
func (e *StorageEngine) Init(ctx context.Context) error {
e.mtx.Lock()
defer e.mtx.Unlock()
@ -79,7 +80,7 @@ func (e *StorageEngine) Init() error {
wg.Add(1)
go func(id string, sh *shard.Shard) {
defer wg.Done()
if err := sh.Init(); err != nil {
if err := sh.Init(ctx); err != nil {
errCh <- shardInitError{
err: err,
id: id,
@ -264,7 +265,7 @@ func (rCfg *ReConfiguration) AddShard(id string, opts []shard.Option) {
}
// Reload reloads StorageEngine's configuration in runtime.
func (e *StorageEngine) Reload(rcfg ReConfiguration) error {
func (e *StorageEngine) Reload(ctx context.Context, rcfg ReConfiguration) error {
type reloadInfo struct {
sh *shard.Shard
opts []shard.Option
@ -324,7 +325,7 @@ loop:
err = sh.Open()
if err == nil {
err = sh.Init()
err = sh.Init(ctx)
}
if err != nil {
_ = sh.Close()

View file

@ -1,6 +1,7 @@
package engine
import (
"context"
"errors"
"fmt"
"io/fs"
@ -169,7 +170,7 @@ func testEngineFailInitAndReload(t *testing.T, errOnAdd bool, opts []shard.Optio
err = e.Open()
if err == nil {
require.Error(t, e.Init())
require.Error(t, e.Init(context.Background()))
}
}
@ -180,7 +181,7 @@ func testEngineFailInitAndReload(t *testing.T, errOnAdd bool, opts []shard.Optio
beforeReload()
require.NoError(t, e.Reload(ReConfiguration{
require.NoError(t, e.Reload(context.Background(), ReConfiguration{
shards: map[string][]shard.Option{configID: opts},
}))
@ -273,7 +274,7 @@ func TestReload(t *testing.T) {
}
rcfg.AddShard(currShards[0], nil) // same path
require.NoError(t, e.Reload(rcfg))
require.NoError(t, e.Reload(context.Background(), rcfg))
// no new paths => no new shards
require.Equal(t, shardNum, len(e.shards))
@ -286,7 +287,7 @@ func TestReload(t *testing.T) {
meta.WithPath(newMeta),
meta.WithEpochState(epochState{}),
)})
require.NoError(t, e.Reload(rcfg))
require.NoError(t, e.Reload(context.Background(), rcfg))
require.Equal(t, shardNum+1, len(e.shards))
require.Equal(t, shardNum+1, len(e.shardPools))
@ -303,7 +304,7 @@ func TestReload(t *testing.T) {
rcfg.AddShard(currShards[i], nil)
}
require.NoError(t, e.Reload(rcfg))
require.NoError(t, e.Reload(context.Background(), rcfg))
// removed one
require.Equal(t, shardNum-1, len(e.shards))
@ -339,7 +340,7 @@ func engineWithShards(t *testing.T, path string, num int) (*StorageEngine, []str
require.Equal(t, num, len(e.shardPools))
require.NoError(t, e.Open())
require.NoError(t, e.Init())
require.NoError(t, e.Init(context.Background()))
return e, currShards
}

View file

@ -1,6 +1,7 @@
package engine
import (
"context"
"fmt"
"os"
"path/filepath"
@ -159,7 +160,7 @@ func testNewShard(t testing.TB, id int) *shard.Shard {
))
require.NoError(t, s.Open())
require.NoError(t, s.Init())
require.NoError(t, s.Init(context.Background()))
return s
}
@ -185,7 +186,7 @@ func testEngineFromShardOpts(t *testing.T, num int, extraOpts []shard.Option) *S
}
require.NoError(t, engine.Open())
require.NoError(t, engine.Init())
require.NoError(t, engine.Init(context.Background()))
return engine
}

View file

@ -1,6 +1,7 @@
package engine
import (
"context"
"fmt"
"os"
"path/filepath"
@ -76,7 +77,7 @@ func newEngineWithErrorThreshold(t testing.TB, dir string, errThreshold uint32)
}
}
require.NoError(t, e.Open())
require.NoError(t, e.Init())
require.NoError(t, e.Init(context.Background()))
return &testEngine{
ng: e,

View file

@ -1,6 +1,7 @@
package engine
import (
"context"
"errors"
"fmt"
"os"
@ -51,7 +52,7 @@ func newEngineEvacuate(t *testing.T, shardNum int, objPerShard int) (*StorageEng
require.NoError(t, err)
}
require.NoError(t, e.Open())
require.NoError(t, e.Init())
require.NoError(t, e.Init(context.Background()))
objects := make([]*objectSDK.Object, 0, objPerShard*len(ids))

View file

@ -1,6 +1,7 @@
package shard
import (
"context"
"errors"
"fmt"
@ -82,7 +83,7 @@ func (x *metabaseSynchronizer) Init() error {
}
// Init initializes all Shard's components.
func (s *Shard) Init() error {
func (s *Shard) Init(ctx context.Context) error {
type initializer interface {
Init() error
}
@ -151,7 +152,7 @@ func (s *Shard) Init() error {
},
}
s.gc.init()
s.gc.init(ctx)
return nil
}

View file

@ -1,6 +1,7 @@
package shard
import (
"context"
"io/fs"
"math"
"os"
@ -83,7 +84,7 @@ func TestShardOpen(t *testing.T) {
sh := newShard()
require.NoError(t, sh.Open())
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
require.Equal(t, mode.ReadWrite, sh.GetMode())
require.NoError(t, sh.Close())
@ -92,7 +93,7 @@ func TestShardOpen(t *testing.T) {
sh = newShard()
require.NoError(t, sh.Open())
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
require.Equal(t, mode.ReadOnly, sh.GetMode())
require.Error(t, sh.SetMode(mode.ReadWrite))
require.Equal(t, mode.ReadOnly, sh.GetMode())
@ -103,7 +104,7 @@ func TestShardOpen(t *testing.T) {
sh = newShard()
require.NoError(t, sh.Open())
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
require.Equal(t, mode.DegradedReadOnly, sh.GetMode())
require.NoError(t, sh.Close())
}
@ -128,7 +129,7 @@ func TestRefillMetabaseCorrupted(t *testing.T) {
WithPiloramaOptions(pilorama.WithPath(filepath.Join(dir, "pilorama"))),
WithMetaBaseOptions(meta.WithPath(filepath.Join(dir, "meta")), meta.WithEpochState(epochState{})))
require.NoError(t, sh.Open())
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
obj := objecttest.Object()
obj.SetType(objectSDK.TypeRegular)
@ -150,7 +151,7 @@ func TestRefillMetabaseCorrupted(t *testing.T) {
WithMetaBaseOptions(meta.WithPath(filepath.Join(dir, "meta_new")), meta.WithEpochState(epochState{})),
WithRefillMetabase(true))
require.NoError(t, sh.Open())
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
var getPrm GetPrm
getPrm.SetAddress(addr)
@ -188,7 +189,7 @@ func TestRefillMetabase(t *testing.T) {
require.NoError(t, sh.Open())
// initialize Blobstor
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
const objNum = 5
@ -355,7 +356,7 @@ func TestRefillMetabase(t *testing.T) {
require.NoError(t, sh.Open())
// initialize Blobstor
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
defer sh.Close()

View file

@ -102,7 +102,7 @@ func defaultGCCfg() gcCfg {
}
}
func (gc *gc) init() {
func (gc *gc) init(ctx context.Context) {
sz := 0
for _, v := range gc.mEventHandler {
@ -115,10 +115,10 @@ func (gc *gc) init() {
gc.wg.Add(2)
go gc.tickRemover()
go gc.listenEvents()
go gc.listenEvents(ctx)
}
func (gc *gc) listenEvents() {
func (gc *gc) listenEvents(ctx context.Context) {
defer gc.wg.Done()
for {
@ -136,8 +136,7 @@ func (gc *gc) listenEvents() {
v.cancelFunc()
v.prevGroup.Wait()
var ctx context.Context
ctx, v.cancelFunc = context.WithCancel(context.Background())
ctx, v.cancelFunc = context.WithCancel(ctx)
v.prevGroup.Add(len(v.handlers))

View file

@ -72,7 +72,7 @@ func Test_GCDropsLockedExpiredObject(t *testing.T) {
sh = shard.New(opts...)
require.NoError(t, sh.Open())
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
t.Cleanup(func() {
releaseShard(sh, t)

View file

@ -56,7 +56,7 @@ func TestShard_Lock(t *testing.T) {
sh = shard.New(opts...)
require.NoError(t, sh.Open())
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
t.Cleanup(func() {
releaseShard(sh, t)

View file

@ -1,6 +1,7 @@
package shard_test
import (
"context"
"path/filepath"
"testing"
@ -215,7 +216,7 @@ func shardWithMetrics(t *testing.T, path string) (*shard.Shard, *metricsStore) {
shard.WithMetricsWriter(mm),
)
require.NoError(t, sh.Open())
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
t.Cleanup(func() {
sh.Close()

View file

@ -1,6 +1,7 @@
package shard
import (
"context"
"os"
"path/filepath"
"testing"
@ -51,7 +52,7 @@ func TestShardReload(t *testing.T) {
sh := New(opts...)
require.NoError(t, sh.Open())
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
objects := make([]objAddr, 5)
for i := range objects {

View file

@ -1,6 +1,7 @@
package shard_test
import (
"context"
"path/filepath"
"testing"
@ -80,7 +81,7 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts
sh := shard.New(opts...)
require.NoError(t, sh.Open())
require.NoError(t, sh.Init())
require.NoError(t, sh.Init(context.Background()))
return sh
}