[#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))