2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-30 13:42:24 +00:00
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2020-10-30 13:42:24 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2021-04-08 14:19:31 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2021-11-10 07:08:33 +00:00
|
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-12 16:37:46 +00:00
|
|
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test"
|
2020-10-30 13:42:24 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_Delete(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
t.Skip("not working, see neofs-sdk-go#242")
|
2020-12-08 07:51:34 +00:00
|
|
|
db := newDB(t)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2022-03-03 14:19:05 +00:00
|
|
|
parent := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
addAttribute(parent, "foo", "bar")
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
child := generateObjectWithCID(t, cid)
|
|
|
|
child.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
idParent, _ := parent.ID()
|
|
|
|
child.SetParentID(idParent)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// put object with parent
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, child)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// fill ToMoveIt index
|
2022-03-03 14:19:05 +00:00
|
|
|
err = meta.ToMoveIt(db, object.AddressOf(child))
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// check if Movable list is not empty
|
2020-12-08 09:56:14 +00:00
|
|
|
l, err := meta.Movable(db)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, l, 1)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 11:23:23 +00:00
|
|
|
// try to remove parent unsuccessfully
|
2022-03-03 14:19:05 +00:00
|
|
|
err = meta.Delete(db, object.AddressOf(parent))
|
2020-12-08 11:23:23 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// inhume parent and child so they will be on graveyard
|
2022-03-03 14:19:05 +00:00
|
|
|
ts := generateObjectWithCID(t, cid)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = meta.Inhume(db, object.AddressOf(child), object.AddressOf(ts))
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// delete object
|
2022-03-03 14:19:05 +00:00
|
|
|
err = meta.Delete(db, object.AddressOf(child))
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-09 10:09:09 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// check if there is no data in Movable index
|
2020-12-08 09:56:14 +00:00
|
|
|
l, err = meta.Movable(db)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, l, 0)
|
2020-11-09 10:09:09 +00:00
|
|
|
|
2021-04-08 14:19:31 +00:00
|
|
|
// check if they marked as already removed
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
ok, err := meta.Exists(db, object.AddressOf(child))
|
2021-04-08 14:19:31 +00:00
|
|
|
require.Error(t, apistatus.ObjectAlreadyRemoved{})
|
2020-12-08 07:51:34 +00:00
|
|
|
require.False(t, ok)
|
2020-11-09 10:09:09 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
ok, err = meta.Exists(db, object.AddressOf(parent))
|
2021-04-08 14:19:31 +00:00
|
|
|
require.Error(t, apistatus.ObjectAlreadyRemoved{})
|
2020-12-08 07:51:34 +00:00
|
|
|
require.False(t, ok)
|
2020-11-09 10:09:09 +00:00
|
|
|
}
|
2021-02-11 17:39:48 +00:00
|
|
|
|
|
|
|
func TestDeleteAllChildren(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
t.Skip("not working, see neofs-sdk-go#242")
|
2021-02-11 17:39:48 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2021-02-11 17:39:48 +00:00
|
|
|
|
|
|
|
// generate parent object
|
2022-03-03 14:19:05 +00:00
|
|
|
parent := generateObjectWithCID(t, cid)
|
2021-02-11 17:39:48 +00:00
|
|
|
|
|
|
|
// generate 2 children
|
2022-03-03 14:19:05 +00:00
|
|
|
child1 := generateObjectWithCID(t, cid)
|
|
|
|
child1.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
idParent, _ := parent.ID()
|
|
|
|
child1.SetParentID(idParent)
|
2021-02-11 17:39:48 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
child2 := generateObjectWithCID(t, cid)
|
|
|
|
child2.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
child2.SetParentID(idParent)
|
2021-02-11 17:39:48 +00:00
|
|
|
|
|
|
|
// put children
|
2022-03-03 14:19:05 +00:00
|
|
|
require.NoError(t, putBig(db, child1))
|
|
|
|
require.NoError(t, putBig(db, child2))
|
2021-02-11 17:39:48 +00:00
|
|
|
|
|
|
|
// Exists should return split info for parent
|
2022-03-03 14:19:05 +00:00
|
|
|
_, err := meta.Exists(db, object.AddressOf(parent))
|
2021-02-11 17:39:48 +00:00
|
|
|
siErr := objectSDK.NewSplitInfoError(nil)
|
|
|
|
require.True(t, errors.As(err, &siErr))
|
|
|
|
|
|
|
|
// remove all children in single call
|
2022-03-03 14:19:05 +00:00
|
|
|
err = meta.Delete(db, object.AddressOf(child1), object.AddressOf(child2))
|
2021-02-11 17:39:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// parent should not be found now
|
2022-03-03 14:19:05 +00:00
|
|
|
ex, err := meta.Exists(db, object.AddressOf(parent))
|
2021-02-11 17:39:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, ex)
|
|
|
|
}
|
2021-04-06 14:07:42 +00:00
|
|
|
|
|
|
|
func TestGraveOnlyDelete(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
addr := objecttest.Address()
|
2021-04-06 14:07:42 +00:00
|
|
|
|
|
|
|
// inhume non-existent object by address
|
|
|
|
require.NoError(t, meta.Inhume(db, addr, nil))
|
|
|
|
|
|
|
|
// delete the object data
|
|
|
|
require.NoError(t, meta.Delete(db, addr))
|
|
|
|
}
|