Skip to content

Commit

Permalink
Merge 96f35f7 into 01ddb3f
Browse files Browse the repository at this point in the history
  • Loading branch information
fyrchik committed Oct 5, 2022
2 parents 01ddb3f + 96f35f7 commit 22e69f9
Show file tree
Hide file tree
Showing 25 changed files with 363 additions and 120 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changelog for NeoFS Node
- `flush-cache` control service command to flush write-cache (#1806)
- `wallet-address` flag in `neofs-adm morph refill-gas` command (#1820)
- Validate policy before container creation (#1704)
- Shards can be marked with `mode: disabled` to be ignored by node (#1840)

### Changed
- Allow to evacuate shard data with `EvacuateShard` control RPC (#1800)
Expand Down
12 changes: 10 additions & 2 deletions cmd/neofs-cli/modules/control/shards_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"strings"

"github.com/mr-tron/base58"
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
Expand Down Expand Up @@ -65,7 +66,7 @@ func prettyPrintShardsJSON(cmd *cobra.Command, ii []*control.ShardInfo) {
"shard_id": base58.Encode(i.Shard_ID),
"mode": shardModeToString(i.GetMode()),
"metabase": i.GetMetabasePath(),
"blobstor": i.GetBlobstorPath(),
"blobstor": i.GetBlobstor(),
"writecache": i.GetWritecachePath(),
"error_count": i.GetErrorCount(),
})
Expand All @@ -89,9 +90,16 @@ func prettyPrintShards(cmd *cobra.Command, ii []*control.ShardInfo) {
return fmt.Sprintf("%s: %s\n", name, path)
}

var sb strings.Builder
sb.WriteString("Blobstor:\n")
for j, info := range i.GetBlobstor() {
sb.WriteString(fmt.Sprintf("\tPath %d: %s\n\tType %d: %s\n",
j, info.GetPath(), j, info.GetType()))
}

cmd.Printf("Shard %s:\nMode: %s\n"+
pathPrinter("Metabase", i.GetMetabasePath())+
pathPrinter("Blobstor", i.GetBlobstorPath())+
sb.String()+
pathPrinter("Write-cache", i.GetWritecachePath())+
pathPrinter("Pilorama", i.GetPiloramaPath())+
fmt.Sprintf("Error count: %d\n", i.GetErrorCount()),
Expand Down
30 changes: 22 additions & 8 deletions cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net"
"os"
"os/signal"
"path/filepath"
"strings"
"sync"
atomicstd "sync/atomic"
"syscall"
Expand Down Expand Up @@ -135,6 +137,18 @@ type shardCfg struct {
}
}

// 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()
}

type subStorageCfg struct {
// common for all storages
typ string
Expand Down Expand Up @@ -597,13 +611,13 @@ func (c *cfg) engineOpts() []engine.Option {
return opts
}

type shardOptsWithMetaPath struct {
metaPath string
type shardOptsWithID struct {
configID string
shOpts []shard.Option
}

func (c *cfg) shardOpts() []shardOptsWithMetaPath {
shards := make([]shardOptsWithMetaPath, 0, len(c.EngineCfg.shards))
func (c *cfg) shardOpts() []shardOptsWithID {
shards := make([]shardOptsWithID, 0, len(c.EngineCfg.shards))

for _, shCfg := range c.EngineCfg.shards {
var writeCacheOpts []writecache.Option
Expand Down Expand Up @@ -666,8 +680,8 @@ func (c *cfg) shardOpts() []shardOptsWithMetaPath {
}
}

var sh shardOptsWithMetaPath
sh.metaPath = shCfg.metaCfg.path
var sh shardOptsWithID
sh.configID = shCfg.id()
sh.shOpts = []shard.Option{
shard.WithLogger(c.log),
shard.WithRefillMetabase(shCfg.refillMetabase),
Expand Down Expand Up @@ -834,8 +848,8 @@ func (c *cfg) configWatcher(ctx context.Context) {
}

var rcfg engine.ReConfiguration
for _, optsWithMeta := range c.shardOpts() {
rcfg.AddShard(optsWithMeta.metaPath, optsWithMeta.shOpts)
for _, optsWithID := range c.shardOpts() {
rcfg.AddShard(optsWithID.configID, optsWithID.shOpts)
}

err = c.cfgObject.cfgLocalStorage.localStorage.Reload(rcfg)
Expand Down
9 changes: 8 additions & 1 deletion cmd/neofs-node/config/engine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
)

const (
Expand All @@ -31,6 +32,7 @@ func IterateShards(c *config.Config, required bool, f func(*shardconfig.Config)
c = c.Sub("shard")
def := c.Sub("default")

alive := 0
i := uint64(0)
for ; ; i++ {
si := strconv.FormatUint(i, 10)
Expand All @@ -48,11 +50,16 @@ func IterateShards(c *config.Config, required bool, f func(*shardconfig.Config)
}
(*config.Config)(sc).SetDefault(def)

if sc.Mode() == mode.Disabled {
continue
}

if err := f(sc); err != nil {
return err
}
alive++
}
if i == 0 && required {
if alive == 0 && required {
return ErrNoShardConfigured
}
return nil
Expand Down
2 changes: 2 additions & 0 deletions cmd/neofs-node/config/engine/shard/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ func (x *Config) Mode() (m mode.Mode) {
m = mode.Degraded
case "degraded-read-only":
m = mode.DegradedReadOnly
case "disabled":
m = mode.Disabled
default:
panic(fmt.Sprintf("unknown shard mode: %s", s))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ func (b *Blobovniczas) Type() string {
return Type
}

// Path implements common.Storage.
func (b *Blobovniczas) Path() string {
return b.rootPath
}

// SetCompressor implements common.Storage.
func (b *Blobovniczas) SetCompressor(cc *compression.Config) {
b.compression = cc
Expand Down
17 changes: 14 additions & 3 deletions pkg/local_object_storage/blobstor/blobovniczatree/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ func TestGeneric(t *testing.T) {

defer func() { _ = os.RemoveAll(t.Name()) }()

var n int
newTree := func(t *testing.T) common.Storage {
dir := filepath.Join(t.Name(), strconv.Itoa(n))
helper := func(t *testing.T, dir string) common.Storage {
return NewBlobovniczaTree(
WithLogger(zaptest.NewLogger(t)),
WithObjectSizeLimit(maxObjectSize),
Expand All @@ -28,7 +26,20 @@ func TestGeneric(t *testing.T) {
WithBlobovniczaSize(1<<20))
}

var n int
newTree := func(t *testing.T) common.Storage {
dir := filepath.Join(t.Name(), strconv.Itoa(n))
return helper(t, dir)
}

blobstortest.TestAll(t, newTree, 1024, maxObjectSize)

t.Run("info", func(t *testing.T) {
dir := filepath.Join(t.Name(), "info")
blobstortest.TestInfo(t, func(t *testing.T) common.Storage {
return helper(t, dir)
}, Type, dir)
})
}

func TestControl(t *testing.T) {
Expand Down
12 changes: 10 additions & 2 deletions pkg/local_object_storage/blobstor/blobstor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/compression"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
Expand All @@ -26,7 +25,16 @@ type BlobStor struct {
mode mode.Mode
}

type Info = fstree.Info
// Info contains information about blobstor.
type Info struct {
SubStorages []SubStorageInfo
}

// SubStorageInfo contains information about blobstor storage component.
type SubStorageInfo struct {
Type string
Path string
}

// Option represents BlobStor's constructor option.
type Option func(*cfg)
Expand Down
1 change: 1 addition & 0 deletions pkg/local_object_storage/blobstor/common/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Storage interface {
Close() error

Type() string
Path() string
SetCompressor(cc *compression.Config)

Get(GetPrm) (GetRes, error)
Expand Down
5 changes: 5 additions & 0 deletions pkg/local_object_storage/blobstor/fstree/fstree.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ func (*FSTree) Type() string {
return Type
}

// Path implements common.Storage.
func (t *FSTree) Path() string {
return t.RootPath
}

// SetCompressor implements common.Storage.
func (t *FSTree) SetCompressor(cc *compression.Config) {
t.Config = cc
Expand Down
17 changes: 14 additions & 3 deletions pkg/local_object_storage/blobstor/fstree/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,27 @@ import (
func TestGeneric(t *testing.T) {
defer func() { _ = os.RemoveAll(t.Name()) }()

var n int
newTree := func(t *testing.T) common.Storage {
dir := filepath.Join(t.Name(), strconv.Itoa(n))
helper := func(t *testing.T, dir string) common.Storage {
return New(
WithPath(dir),
WithDepth(2),
WithDirNameLen(2))
}

var n int
newTree := func(t *testing.T) common.Storage {
dir := filepath.Join(t.Name(), strconv.Itoa(n))
return helper(t, dir)
}

blobstortest.TestAll(t, newTree, 2048, 16*1024)

t.Run("info", func(t *testing.T) {
dir := filepath.Join(t.Name(), "info")
blobstortest.TestInfo(t, func(t *testing.T) common.Storage {
return helper(t, dir)
}, Type, dir)
})
}

func TestControl(t *testing.T) {
Expand Down
15 changes: 8 additions & 7 deletions pkg/local_object_storage/blobstor/info.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package blobstor

import "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"

// DumpInfo returns information about blob stor.
func (b *BlobStor) DumpInfo() fstree.Info {
func (b *BlobStor) DumpInfo() Info {
sub := make([]SubStorageInfo, len(b.storage))
for i := range b.storage {
if b.storage[i].Storage.Type() == "fstree" {
return b.storage[i].Storage.(*fstree.FSTree).Info
}
sub[i].Path = b.storage[i].Storage.Path()
sub[i].Type = b.storage[i].Storage.Type()
}

return Info{
SubStorages: sub,
}
return fstree.Info{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func TestAll(t *testing.T, cons Constructor, min, max uint64) {
})
}

func TestInfo(t *testing.T, cons Constructor, expectedType string, expectedPath string) {
s := cons(t)
require.Equal(t, expectedType, s.Type())
require.Equal(t, expectedPath, s.Path())
}

func prepare(t *testing.T, count int, s common.Storage, min, max uint64) []objectDesc {
objects := make([]objectDesc, count)

Expand Down
Loading

0 comments on commit 22e69f9

Please sign in to comment.