Skip to content

Commit

Permalink
blobovnicza: Fix write error at zero depth
Browse files Browse the repository at this point in the history
Previously, blobovnicza tree with depth=0 (i.e. group of DBs without
subdirectories) failed to write any object. There was a mistake in code
which worked incorrectly for depth=0 particular case.

Fix `iterateDeepest` method iterating over paths to DBs as if they were
directories. From now it passes current directory only.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Jul 25, 2023
1 parent f751d71 commit be4bbfb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/local_object_storage/blobstor/blobovniczatree/iterate.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ func (b *Blobovniczas) iterateSortedLeaves(addr *oid.Address, f func(string) (bo

// iterator over directories with Blobovniczas sorted by weight.
func (b *Blobovniczas) iterateDeepest(addr oid.Address, f func(string) (bool, error)) error {
depth := b.blzShallowDepth
if depth > 0 {
depth--
if b.blzShallowDepth == 0 {
_, err := f(".")
return err
}

depth := b.blzShallowDepth - 1

_, err := b.iterateSorted(
&addr,
make([]string, 0, depth),
Expand Down
39 changes: 39 additions & 0 deletions pkg/local_object_storage/blobstor/blobovniczatree/put_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package blobovniczatree_test

import (
"testing"

. "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/blobovniczatree"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test"
"github.com/stretchr/testify/require"
)

func TestSingleDir(t *testing.T) {
tree := NewBlobovniczaTree(
WithRootPath(t.TempDir()),
WithBlobovniczaShallowDepth(0),
WithBlobovniczaShallowWidth(10),
)

require.NoError(t, tree.Open(false))
defer func() { _ = tree.Close() }()
require.NoError(t, tree.Init())

bObj, err := objecttest.Object(t).Marshal()
require.NoError(t, err)

putPrm := common.PutPrm{
Address: oidtest.Address(),
RawData: bObj,
}

_, err = tree.Put(putPrm)
require.NoError(t, err)

_, err = tree.Get(common.GetPrm{
Address: putPrm.Address,
})
require.NoError(t, err)
}

0 comments on commit be4bbfb

Please sign in to comment.