[#253] metabase: Add prefix to Graveyard and ToMoveIt bucket names

In previous implementation DB.Containers method could return an error about
invalid container ID string format. This could happen if some of top-level
buckets had name w/o "_" substring.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-12-17 11:07:51 +03:00 committed by Alex Vanin
parent df3d30d1ec
commit edef9463d7
3 changed files with 47 additions and 12 deletions

View file

@ -39,7 +39,7 @@ func (db *DB) containers(tx *bbolt.Tx) ([]*container.ID, error) {
func parseContainerID(name []byte) (*container.ID, error) { func parseContainerID(name []byte) (*container.ID, error) {
strName := string(name) strName := string(name)
if strings.Contains(strName, "_") { if strings.Contains(strName, invalidBase58String) {
return nil, nil return nil, nil
} }

View file

@ -3,6 +3,7 @@ package meta_test
import ( import (
"testing" "testing"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -33,4 +34,36 @@ func TestDB_Containers(t *testing.T) {
cids[cid.String()] = 1 cids[cid.String()] = 1
} }
t.Run("Inhume", func(t *testing.T) {
obj := generateRawObject(t).Object()
require.NoError(t, putBig(db, obj))
cnrs, err := db.Containers()
require.NoError(t, err)
require.Contains(t, cnrs, obj.ContainerID())
require.NoError(t, meta.Inhume(db, obj.Address(), generateAddress()))
cnrs, err = db.Containers()
require.NoError(t, err)
require.Contains(t, cnrs, obj.ContainerID())
})
t.Run("ToMoveIt", func(t *testing.T) {
obj := generateRawObject(t).Object()
require.NoError(t, putBig(db, obj))
cnrs, err := db.Containers()
require.NoError(t, err)
require.Contains(t, cnrs, obj.ContainerID())
require.NoError(t, meta.ToMoveIt(db, obj.Address()))
cnrs, err = db.Containers()
require.NoError(t, err)
require.Contains(t, cnrs, obj.ContainerID())
})
} }

View file

@ -14,22 +14,24 @@ slows execution. Instead we can try to marshal these structures directly into
bytes. Check it later. bytes. Check it later.
*/ */
const invalidBase58String = "_"
var ( var (
graveyardBucketName = []byte("Graveyard") graveyardBucketName = []byte(invalidBase58String + "Graveyard")
toMoveItBucketName = []byte("ToMoveIt") toMoveItBucketName = []byte(invalidBase58String + "ToMoveIt")
zeroValue = []byte{0xFF} zeroValue = []byte{0xFF}
smallPostfix = "_small" smallPostfix = invalidBase58String + "small"
storageGroupPostfix = "_SG" storageGroupPostfix = invalidBase58String + "SG"
tombstonePostfix = "_TS" tombstonePostfix = invalidBase58String + "TS"
ownerPostfix = "_ownerid" ownerPostfix = invalidBase58String + "ownerid"
payloadHashPostfix = "_payloadhash" payloadHashPostfix = invalidBase58String + "payloadhash"
rootPostfix = "_root" rootPostfix = invalidBase58String + "root"
parentPostfix = "_parent" parentPostfix = invalidBase58String + "parent"
splitPostfix = "_splitid" splitPostfix = invalidBase58String + "splitid"
userAttributePostfix = "_attr_" userAttributePostfix = invalidBase58String + "attr_"
splitInfoError *object.SplitInfoError // for errors.As comparisons splitInfoError *object.SplitInfoError // for errors.As comparisons
) )