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"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/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) {
|
|
|
|
db := newDB(t)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
|
|
|
parent := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
addAttribute(parent, "foo", "bar")
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
child := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
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-07-12 14:42:55 +00:00
|
|
|
err = metaToMoveIt(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
|
2022-07-12 14:42:55 +00:00
|
|
|
l, err := metaMovable(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
|
|
|
|
2022-09-04 08:52:01 +00:00
|
|
|
// try to remove parent, should be no-op, error-free
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaDelete(db, object.AddressOf(parent))
|
2022-09-04 08:52:01 +00:00
|
|
|
require.NoError(t, err)
|
2020-12-08 11:23:23 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// inhume parent and child so they will be on graveyard
|
2022-05-31 17:00:41 +00:00
|
|
|
ts := generateObjectWithCID(t, cnr)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaInhume(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-07-12 14:42:55 +00:00
|
|
|
err = metaDelete(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
|
2022-07-12 14:42:55 +00:00
|
|
|
l, err = metaMovable(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-07-12 14:42:55 +00:00
|
|
|
ok, err := metaExists(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-07-12 14:42:55 +00:00
|
|
|
ok, err = metaExists(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) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2021-02-11 17:39:48 +00:00
|
|
|
|
|
|
|
// generate parent object
|
2022-05-31 17:00:41 +00:00
|
|
|
parent := generateObjectWithCID(t, cnr)
|
2021-02-11 17:39:48 +00:00
|
|
|
|
|
|
|
// generate 2 children
|
2022-05-31 17:00:41 +00:00
|
|
|
child1 := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
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-05-31 17:00:41 +00:00
|
|
|
child2 := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
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-07-12 14:42:55 +00:00
|
|
|
_, err := metaExists(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-07-12 14:42:55 +00:00
|
|
|
err = metaDelete(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-07-12 14:42:55 +00:00
|
|
|
ex, err := metaExists(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-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
2021-04-06 14:07:42 +00:00
|
|
|
|
|
|
|
// inhume non-existent object by address
|
2022-07-12 14:42:55 +00:00
|
|
|
require.NoError(t, metaInhume(db, addr, oidtest.Address()))
|
2021-04-06 14:07:42 +00:00
|
|
|
|
|
|
|
// delete the object data
|
2022-07-12 14:42:55 +00:00
|
|
|
require.NoError(t, metaDelete(db, addr))
|
|
|
|
}
|
|
|
|
|
2022-07-27 18:38:28 +00:00
|
|
|
func TestExpiredObject(t *testing.T) {
|
|
|
|
db := newDB(t, meta.WithEpochState(epochState{currEpoch}))
|
|
|
|
|
|
|
|
checkExpiredObjects(t, db, func(exp, nonExp *objectSDK.Object) {
|
|
|
|
// removing expired object should be error-free
|
|
|
|
require.NoError(t, metaDelete(db, object.AddressOf(exp)))
|
|
|
|
|
|
|
|
require.NoError(t, metaDelete(db, object.AddressOf(nonExp)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
func metaDelete(db *meta.DB, addrs ...oid.Address) error {
|
|
|
|
var deletePrm meta.DeletePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
deletePrm.SetAddresses(addrs...)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
_, err := db.Delete(deletePrm)
|
|
|
|
return err
|
2021-04-06 14:07:42 +00:00
|
|
|
}
|