Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/neofs-lancet/internal/fstree/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

common "github.com/nspcc-dev/neofs-node/cmd/neofs-lancet/internal"
blobstorcommon "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/spf13/cobra"
)
Expand All @@ -30,7 +31,7 @@ func getFunc(cmd *cobra.Command, _ []string) error {
}
defer fst.Close()

err = fst.Init()
err = fst.Init(blobstorcommon.ID{})
if err != nil {
return fmt.Errorf("failed to init FSTree: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/neofs-lancet/internal/fstree/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"

common "github.com/nspcc-dev/neofs-node/cmd/neofs-lancet/internal"
blobstorcommon "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -36,7 +37,7 @@ func listFunc(cmd *cobra.Command, _ []string) error {
}
defer fst.Close()

err = fst.Init()
err = fst.Init(blobstorcommon.ID{})
if err != nil {
return fmt.Errorf("failed to init FSTree: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/neofs-lancet/internal/fstree/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

common "github.com/nspcc-dev/neofs-node/cmd/neofs-lancet/internal"
blobstorcommon "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -44,7 +45,7 @@ func removeFunc(cmd *cobra.Command, _ []string) error {
}
defer fst.Close()

err = fst.Init()
err = fst.Init(blobstorcommon.ID{})
if err != nil {
return fmt.Errorf("failed to init FSTree: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/neofs-lancet/internal/meta/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

common "github.com/nspcc-dev/neofs-node/cmd/neofs-lancet/internal"
blobstorcommon "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/nspcc-dev/neofs-sdk-go/object"
"github.com/spf13/cobra"
)
Expand All @@ -30,7 +31,7 @@ func writeObject(cmd *cobra.Command, _ []string) error {
}
defer db.Close()

err = db.Init()
err = db.Init(blobstorcommon.ID{})
if err != nil {
return fmt.Errorf("can't init metabase: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/neofs-lancet/internal/meta/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

common "github.com/nspcc-dev/neofs-node/cmd/neofs-lancet/internal"
blobstorcommon "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -43,7 +44,7 @@ func removeFunc(cmd *cobra.Command, _ []string) error {
}
defer db.Close()

err = db.Init()
err = db.Init(blobstorcommon.ID{})
if err != nil {
return fmt.Errorf("can't init metabase: %w", err)
}
Expand Down
16 changes: 11 additions & 5 deletions cmd/neofs-lancet/internal/meta/resync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package meta
import (
"fmt"

"github.com/mr-tron/base58"
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lancet/internal"
blobstorcommon "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"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
Expand Down Expand Up @@ -51,7 +51,7 @@ func resyncFunc(cmd *cobra.Command, _ []string) error {
}
defer db.Close()

err = db.Init()
err = db.Init(blobstorcommon.ID{})
if err != nil {
return fmt.Errorf("init metabase: %w", err)
}
Expand All @@ -74,7 +74,7 @@ func resyncFunc(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("failed to open FSTree: %w", err)
}

err = fst.Init()
err = fst.Init(blobstorcommon.ID{})
if err != nil {
return fmt.Errorf("init blobstor: %w", err)
}
Expand All @@ -84,8 +84,14 @@ func resyncFunc(cmd *cobra.Command, _ []string) error {
if err != nil {
return fmt.Errorf("read shard ID from metabase: %w", err)
}
metaShardID := base58.Encode(idRaw)
if len(metaShardID) > 0 && metaShardID != blobstorShardID && !vForce {
var metaShardID blobstorcommon.ID
if len(idRaw) != 0 {
metaShardID, err = blobstorcommon.NewIDFromBytes(idRaw)
if err != nil {
return fmt.Errorf("decode metabase shard ID: %w", err)
}
}
if !metaShardID.IsZero() && !metaShardID.Equal(blobstorShardID) && !vForce {
return fmt.Errorf("metabase shard ID %q does not match blobstor shard ID %q, use --%s to override", metaShardID, blobstorShardID, forceFlagName)
}

Expand Down
3 changes: 0 additions & 3 deletions cmd/neofs-lancet/internal/storage/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ func openEngine(readOnly bool) (*engine.StorageEngine, error) {
}
}

if err := ls.Open(); err != nil {
return nil, err
}
if err := ls.Init(); err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-lancet/internal/storage/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ func sanityCheck(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("moving metabase in readonly mode: %w", err)
}

if err := sh.m.Init(); err != nil {
if err := sh.m.Init(commonb.ID{}); err != nil {
return fmt.Errorf("init metabase: %w", err)
}
if sh.fsT != nil {
if err := sh.fsT.Init(); err != nil {
if err := sh.fsT.Init(commonb.ID{}); err != nil {
return fmt.Errorf("init fstree: %w", err)
}
}
Expand Down
1 change: 0 additions & 1 deletion cmd/neofs-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ func initApp(c *cfg) {

initAndLog(c, "container", initContainerService)
initAndLog(c, "storage engine", func(c *cfg) {
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open())
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Init())
})

Expand Down
1 change: 1 addition & 0 deletions cmd/neofs-node/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (c *cfg) shardOpts() []shardOptsWithID {
wcMaxBatchCount = sRead.CombinedCountLimit
wcMaxBatchThreshold = uint64(sRead.CombinedSizeThreshold)
s = fstree.New(
fstree.WithLogger(c.log),
fstree.WithPath(sRead.Path),
fstree.WithPerm(sRead.Perm),
fstree.WithDepth(sRead.Depth),
Expand Down
87 changes: 87 additions & 0 deletions pkg/local_object_storage/blobstor/common/id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package common

import (
"bytes"
"encoding/binary"
"fmt"

"github.com/google/uuid"
"github.com/mr-tron/base58"
)

// IDSize is the binary shard ID size in bytes.
const IDSize = 16

// ID represents a shard identifier.
type ID struct {
raw [IDSize]byte
str string
hash uint64
}

// NewID generates a new shard identifier.
func NewID() (ID, error) {
uid, err := uuid.NewRandom()
if err != nil {
return ID{}, err
}

return NewIDFromBytes(uid[:])
}

// NewIDFromBytes constructs ID from fixed-size raw bytes.
func NewIDFromBytes(v []byte) (ID, error) {
if len(v) != IDSize {
return ID{}, fmt.Errorf("invalid shard ID length %d, expected %d", len(v), IDSize)
}

var id ID
copy(id.raw[:], v)
id.str = base58.Encode(id.raw[:])
id.hash = binary.BigEndian.Uint64(id.raw[:8])

return id, nil
}

// DecodeIDString decodes base58 string into ID.
func DecodeIDString(s string) (ID, error) {
if s == "" {
return ID{}, fmt.Errorf("empty shard ID string")
}

b, err := base58.Decode(s)
if err != nil {
return ID{}, err
}

return NewIDFromBytes(b)
}

// String encodes ID into base58 form.
func (id ID) String() string {
return id.str
}

// Bytes returns a copy of the raw ID bytes.
func (id ID) Bytes() []byte {
if id.IsZero() {
return nil
}

return bytes.Clone(id.raw[:])
}

// Equal reports whether two IDs are equal.
func (id ID) Equal(other ID) bool {
return id == other
}

// Hash returns the cached HRW hash.
func (id ID) Hash() uint64 {
return id.hash
}

// IsZero reports whether ID is empty.
func (id ID) IsZero() bool {
return id.str == ""
}
11 changes: 4 additions & 7 deletions pkg/local_object_storage/blobstor/common/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/compression"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"go.uber.org/zap"
)

// Storage represents key-value object storage.
// It is used as a building block for a blobstor of a shard.
type Storage interface {
Open(readOnly bool) error
Init() error
Init(ID) error
Close() error

Type() string
Path() string
ShardID() string
SetLogger(*zap.Logger)
ShardID() ID
SetCompressor(cc *compression.Config)
SetShardID(id string)

// GetBytes reads object by address into memory buffer in a canonical NeoFS
// binary format. Returns [apistatus.ObjectNotFound] if object is missing.
Expand Down Expand Up @@ -58,7 +55,7 @@ func CopyBatched(dst, src Storage, batchSize int) error {

defer func() { _ = src.Close() }()

err = src.Init()
err = src.Init(ID{})
if err != nil {
return fmt.Errorf("initialize source sub-storage: %w", err)
}
Expand All @@ -70,7 +67,7 @@ func CopyBatched(dst, src Storage, batchSize int) error {

defer func() { _ = dst.Close() }()

err = dst.Init()
err = dst.Init(ID{})
if err != nil {
return fmt.Errorf("initialize destination sub-storage: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/local_object_storage/blobstor/common/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func testCopy(t *testing.T, copier func(dst, src common.Storage) error) {
src := fstree.New(fstree.WithPath(filepath.Join(dir, "src")))

require.NoError(t, src.Open(false))
require.NoError(t, src.Init())
require.NoError(t, src.Init(common.ID{}))

mObjs := make(map[oid.Address][]byte, nObjects)

Expand Down
3 changes: 2 additions & 1 deletion pkg/local_object_storage/blobstor/fstree/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"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-sdk-go/object"
Expand All @@ -26,7 +27,7 @@ var payloadSizes = []int{
func setupFSTree(tb testing.TB) *fstree.FSTree {
fsTree := fstree.New(fstree.WithPath(tb.TempDir()))
require.NoError(tb, fsTree.Open(false))
require.NoError(tb, fsTree.Init())
require.NoError(tb, fsTree.Init(common.ID{}))
return fsTree
}

Expand Down
Loading
Loading