diff --git a/pkg/core/object/metadata.go b/pkg/core/object/metadata.go deleted file mode 100644 index 9fd1fef73f..0000000000 --- a/pkg/core/object/metadata.go +++ /dev/null @@ -1,10 +0,0 @@ -package object - -import oid "github.com/nspcc-dev/neofs-sdk-go/object/id" - -// TODO: docs -// TODO: reuse type from SDK if possible -type SearchResultItem struct { - ID oid.ID - Attributes []string -} diff --git a/pkg/local_object_storage/metabase/containers.go b/pkg/local_object_storage/metabase/containers.go index 60ec058dcf..5053e941f7 100644 --- a/pkg/local_object_storage/metabase/containers.go +++ b/pkg/local_object_storage/metabase/containers.go @@ -184,6 +184,11 @@ func (db *DB) DeleteContainer(cID cid.ID) error { return fmt.Errorf("link objects' bucket cleanup: %w", err) } + // Metadata + if err = tx.DeleteBucket(metaBucketKey(cID)); err != nil && !errors.Is(err, bbolt.ErrBucketNotFound) { + return fmt.Errorf("metadata bucket cleanup: %w", err) + } + // indexes err = tx.DeleteBucket(ownerBucketName(cID, buff)) diff --git a/pkg/local_object_storage/metabase/metadata.go b/pkg/local_object_storage/metabase/metadata.go index abdd2adea8..3c43d189d6 100644 --- a/pkg/local_object_storage/metabase/metadata.go +++ b/pkg/local_object_storage/metabase/metadata.go @@ -12,7 +12,7 @@ import ( "github.com/google/uuid" "github.com/mr-tron/base58" - objectcore "github.com/nspcc-dev/neofs-node/pkg/core/object" + "github.com/nspcc-dev/neofs-sdk-go/client" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -116,7 +116,7 @@ func putMetadata(tx *bbolt.Tx, cnr cid.ID, id oid.ID, ver version.Version, owner // Search selects up to count container's objects from the given container // matching the specified filters. -func (db *DB) Search(cnr cid.ID, fs object.SearchFilters, attrs []string, cursor string, count uint32) ([]objectcore.SearchResultItem, string, error) { +func (db *DB) Search(cnr cid.ID, fs object.SearchFilters, attrs []string, cursor string, count uint32) ([]client.SearchResultItem, string, error) { if cnr.IsZero() { return nil, "", cid.ErrZero } @@ -148,7 +148,7 @@ func (db *DB) Search(cnr cid.ID, fs object.SearchFilters, attrs []string, cursor } } - var res []objectcore.SearchResultItem + var res []client.SearchResultItem var resCursor []byte var err error if len(fs) == 0 { @@ -162,7 +162,7 @@ func (db *DB) Search(cnr cid.ID, fs object.SearchFilters, attrs []string, cursor return res, base64.StdEncoding.EncodeToString(resCursor), nil } -func (db *DB) search(cnr cid.ID, fs object.SearchFilters, attrs []string, cursor []byte, count uint32) ([]objectcore.SearchResultItem, []byte, error) { +func (db *DB) search(cnr cid.ID, fs object.SearchFilters, attrs []string, cursor []byte, count uint32) ([]client.SearchResultItem, []byte, error) { seekKey := make([]byte, 1+base64.StdEncoding.DecodedLen(len(cursor))) // TODO: limit? n, err := base64.StdEncoding.Decode(seekKey[1:], cursor) if err != nil { @@ -170,7 +170,7 @@ func (db *DB) search(cnr cid.ID, fs object.SearchFilters, attrs []string, cursor } seekKey = seekKey[:1+n] - var res []objectcore.SearchResultItem + var res []client.SearchResultItem err = db.boltDB.View(func(tx *bbolt.Tx) error { mb := tx.Bucket(metaBucketKey(cnr)) if mb == nil { @@ -187,7 +187,7 @@ func (db *DB) search(cnr cid.ID, fs object.SearchFilters, attrs []string, cursor } func (db *DB) searchInBucket(metaBkt *bbolt.Bucket, fs object.SearchFilters, attrs []string, - primSeekKey []byte, count uint32) ([]objectcore.SearchResultItem, []byte, error) { + primSeekKey []byte, count uint32) ([]client.SearchResultItem, []byte, error) { // TODO: make as much as possible outside the Bolt tx primMatcher := fs[0].Operation() intPrimMatcher := isNumericOp(primMatcher) @@ -234,7 +234,7 @@ func (db *DB) searchInBucket(metaBkt *bbolt.Bucket, fs object.SearchFilters, att return nil, nil, nil } - res := make([]objectcore.SearchResultItem, count) + res := make([]client.SearchResultItem, count) collectedPrimVals := make([][]byte, count) collectedPrimKeys := make([][]byte, count) // TODO: can be done w/o slice var n uint32 @@ -419,7 +419,7 @@ nextPrimKey: } // TODO: can be merged with filtered code? -func (db *DB) searchUnfiltered(cnr cid.ID, cursor []byte, count uint32) ([]objectcore.SearchResultItem, []byte, error) { +func (db *DB) searchUnfiltered(cnr cid.ID, cursor []byte, count uint32) ([]client.SearchResultItem, []byte, error) { seekKey := make([]byte, 1+base64.StdEncoding.DecodedLen(len(cursor))) ln, err := base64.StdEncoding.Decode(seekKey[1:], cursor) if err != nil { @@ -431,7 +431,7 @@ func (db *DB) searchUnfiltered(cnr cid.ID, cursor []byte, count uint32) ([]objec seekKey[0] = metaPrefixID seekKey = seekKey[:1+ln] - res := make([]objectcore.SearchResultItem, count) + res := make([]client.SearchResultItem, count) var n uint32 err = db.boltDB.View(func(tx *bbolt.Tx) error { mb := tx.Bucket(metaBucketKey(cnr)) diff --git a/pkg/local_object_storage/metabase/metadata_test.go b/pkg/local_object_storage/metabase/metadata_test.go index 0726b90c5b..0ed3037527 100644 --- a/pkg/local_object_storage/metabase/metadata_test.go +++ b/pkg/local_object_storage/metabase/metadata_test.go @@ -10,9 +10,9 @@ import ( "strconv" "testing" - objectcore "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-sdk-go/checksum" checksumtest "github.com/nspcc-dev/neofs-sdk-go/checksum/test" + "github.com/nspcc-dev/neofs-sdk-go/client" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" @@ -1091,7 +1091,7 @@ func TestDB_SearchObjects(t *testing.T) { for i := range otherAttrs { appendAttribute(&objs[i], otherAttr, otherAttrs[i]) } - heightSorted := []objectcore.SearchResultItem{ + heightSorted := []client.SearchResultItem{ // attribute takes 1st order priority {ID: ids[9], Attributes: []string{"0", otherAttrs[0]}}, {ID: ids[8], Attributes: []string{"1", otherAttrs[1]}}, @@ -1332,13 +1332,13 @@ func TestDB_SearchObjects(t *testing.T) { res, cursor, err := db.Search(cnr, fs, []string{object.AttributeFilePath, object.AttributeTimestamp}, "", 1000) require.NoError(t, err) require.Empty(t, cursor) - require.Equal(t, []objectcore.SearchResultItem{ + require.Equal(t, []client.SearchResultItem{ {ID: ids[0], Attributes: []string{"cat1.jpg", "1738760790"}}, }, res) }) t.Run("multiple", func(t *testing.T) { t.Run("both attributes", func(t *testing.T) { - fullRes := []objectcore.SearchResultItem{ + fullRes := []client.SearchResultItem{ {ID: ids[1], Attributes: []string{"cat2.jpg", "1738760792"}}, {ID: ids[2], Attributes: []string{"cat2.jpg", "1738760791"}}, {ID: ids[3], Attributes: []string{"cat2.jpg", "1738760793"}}, @@ -1404,7 +1404,7 @@ func TestDB_SearchObjects(t *testing.T) { res, cursor, err := db.Search(cnr, fs, attrs, "", 1000) require.NoError(t, err) require.Empty(t, cursor) - require.Equal(t, []objectcore.SearchResultItem{ + require.Equal(t, []client.SearchResultItem{ {ID: ids[1], Attributes: []string{"/home/Downloads/cat.jpg", "val1_3", "val2_3"}}, {ID: ids[3], Attributes: []string{"/home/Downloads/dog.jpg", "val1_1", "val2_1"}}, }, res) @@ -1415,7 +1415,7 @@ func TestDB_SearchObjects(t *testing.T) { res, cursor, err = db.Search(cnr, fs, attrs, "", 1000) require.NoError(t, err) require.Empty(t, cursor) - require.Equal(t, []objectcore.SearchResultItem{ + require.Equal(t, []client.SearchResultItem{ {ID: ids[2], Attributes: []string{"/usr/local/bin/go", "val1_2", "val2_2"}}, }, res) @@ -1425,7 +1425,7 @@ func TestDB_SearchObjects(t *testing.T) { res, cursor, err = db.Search(cnr, fs, attrs, "", 1000) require.NoError(t, err) require.Empty(t, cursor) - require.Equal(t, []objectcore.SearchResultItem{ + require.Equal(t, []client.SearchResultItem{ {ID: ids[1], Attributes: []string{"/home/Downloads/cat.jpg", "val1_3", "val2_3"}}, {ID: ids[3], Attributes: []string{"/home/Downloads/dog.jpg", "val1_1", "val2_1"}}, {ID: ids[0], Attributes: []string{"/var/log/neofs/node", "val1_4", "val2_4"}}, @@ -1437,13 +1437,13 @@ func TestDB_SearchObjects(t *testing.T) { fs.AddFilter("Type", "TEXT", object.MatchStringNotEqual) res, cursor, err := db.Search(cnr, fs, attrs, "", 1) require.NoError(t, err) - require.Equal(t, []objectcore.SearchResultItem{ + require.Equal(t, []client.SearchResultItem{ {ID: ids[1], Attributes: []string{"/home/Downloads/cat.jpg", "val1_3", "val2_3"}}, }, res) require.NotEmpty(t, cursor) res, cursor, err = db.Search(cnr, fs, attrs, cursor, 1) require.NoError(t, err) - require.Equal(t, []objectcore.SearchResultItem{ + require.Equal(t, []client.SearchResultItem{ {ID: ids[3], Attributes: []string{"/home/Downloads/dog.jpg", "val1_1", "val2_1"}}, }, res) require.Empty(t, cursor)