Skip to content

Commit

Permalink
[nspcc-dev#1840] blobstor: Return info about all components
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
  • Loading branch information
fyrchik authored and aprasolova committed Oct 19, 2022
1 parent 5297e79 commit 7874d19
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 88 deletions.
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
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
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{}
}
4 changes: 2 additions & 2 deletions pkg/local_object_storage/engine/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ func TestBlobstorFailback(t *testing.T) {
checkShardState(t, e, id[0], 0, mode.ReadWrite)
require.NoError(t, e.Close())

p1 := e.shards[id[0].String()].Shard.DumpInfo().BlobStorInfo.RootPath
p2 := e.shards[id[1].String()].Shard.DumpInfo().BlobStorInfo.RootPath
p1 := e.shards[id[0].String()].Shard.DumpInfo().BlobStorInfo.SubStorages[1].Path
p2 := e.shards[id[1].String()].Shard.DumpInfo().BlobStorInfo.SubStorages[1].Path
tmp := filepath.Join(dir, "tmp")
require.NoError(t, os.Rename(p1, tmp))
require.NoError(t, os.Rename(p2, p1))
Expand Down
16 changes: 6 additions & 10 deletions pkg/local_object_storage/shard/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ func TestShardOpen(t *testing.T) {
func TestRefillMetabaseCorrupted(t *testing.T) {
dir := t.TempDir()

fsTree := fstree.New(
fstree.WithDirNameLen(2),
fstree.WithPath(filepath.Join(dir, "blob")),
fstree.WithDepth(1))
blobOpts := []blobstor.Option{
blobstor.WithStorages([]blobstor.SubStorage{
{
Storage: fstree.New(
fstree.WithDirNameLen(2),
fstree.WithPath(filepath.Join(dir, "blob")),
fstree.WithDepth(1)),
Storage: fsTree,
},
}),
}
Expand All @@ -111,12 +112,7 @@ func TestRefillMetabaseCorrupted(t *testing.T) {
require.NoError(t, sh.Close())

addr := object.AddressOf(obj)
fs := fstree.FSTree{
DirNameLen: 2,
Depth: 1,
Info: sh.blobStor.DumpInfo(),
}
_, err = fs.Put(common.PutPrm{Address: addr, RawData: []byte("not an object")})
_, err = fsTree.Put(common.PutPrm{Address: addr, RawData: []byte("not an object")})
require.NoError(t, err)

sh = New(
Expand Down
14 changes: 13 additions & 1 deletion pkg/services/control/server/list_shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package control
import (
"context"

"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -30,7 +31,7 @@ func (s *Server) ListShards(_ context.Context, req *control.ListShardsRequest) (

si.SetID(*sh.ID)
si.SetMetabasePath(sh.MetaBaseInfo.Path)
si.SetBlobstorPath(sh.BlobStorInfo.RootPath)
si.Blobstor = blobstorInfoToProto(sh.BlobStorInfo)
si.SetWriteCachePath(sh.WriteCacheInfo.Path)
si.SetPiloramaPath(sh.PiloramaInfo.Path)

Expand Down Expand Up @@ -64,3 +65,14 @@ func (s *Server) ListShards(_ context.Context, req *control.ListShardsRequest) (

return resp, nil
}

func blobstorInfoToProto(info blobstor.Info) []*control.BlobstorInfo {
res := make([]*control.BlobstorInfo, len(info.SubStorages))
for i := range info.SubStorages {
res[i] = &control.BlobstorInfo{
Path: info.SubStorages[i].Path,
Type: info.SubStorages[i].Type,
}
}
return res
}
19 changes: 17 additions & 2 deletions pkg/services/control/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,21 @@ func equalListShardResponseBodies(b1, b2 *control.ListShardsResponse_Body) bool

for i := range b1.Shards {
if b1.Shards[i].GetMetabasePath() != b2.Shards[i].GetMetabasePath() ||
b1.Shards[i].GetBlobstorPath() != b2.Shards[i].GetBlobstorPath() ||
b1.Shards[i].GetWritecachePath() != b2.Shards[i].GetWritecachePath() ||
b1.Shards[i].GetPiloramaPath() != b2.Shards[i].GetPiloramaPath() ||
!bytes.Equal(b1.Shards[i].GetShard_ID(), b2.Shards[i].GetShard_ID()) {
return false
}

info1 := b1.Shards[i].GetBlobstor()
info2 := b2.Shards[i].GetBlobstor()
return compareBlobstorInfo(info1, info2)
}

for i := range b1.Shards {
for j := i + 1; j < len(b1.Shards); j++ {
if b1.Shards[i].GetMetabasePath() == b2.Shards[j].GetMetabasePath() ||
b1.Shards[i].GetBlobstorPath() == b2.Shards[j].GetBlobstorPath() ||
!compareBlobstorInfo(b1.Shards[i].Blobstor, b2.Shards[i].Blobstor) ||
b1.Shards[i].GetWritecachePath() == b2.Shards[j].GetWritecachePath() ||
bytes.Equal(b1.Shards[i].GetShard_ID(), b2.Shards[j].GetShard_ID()) {
return false
Expand All @@ -98,6 +101,18 @@ func equalListShardResponseBodies(b1, b2 *control.ListShardsResponse_Body) bool

return true
}
func compareBlobstorInfo(a, b []*control.BlobstorInfo) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i].Type != b[i].Type ||
a[i].Path != b[i].Path {
return false
}
}
return true
}

func generateListShardsResponseBody() *control.ListShardsResponse_Body {
body := new(control.ListShardsResponse_Body)
Expand Down
5 changes: 0 additions & 5 deletions pkg/services/control/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ func (x *ShardInfo) SetMetabasePath(v string) {
x.MetabasePath = v
}

// SetBlobstorPath sets path to shard's blobstor.
func (x *ShardInfo) SetBlobstorPath(v string) {
x.BlobstorPath = v
}

// SetWriteCachePath sets path to shard's write-cache.
func (x *ShardInfo) SetWriteCachePath(v string) {
x.WritecachePath = v
Expand Down
Loading

0 comments on commit 7874d19

Please sign in to comment.