2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-30 13:42:24 +00:00
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
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"
|
2023-03-20 14:10:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2023-08-04 11:14:07 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 13:38:26 +00:00
|
|
|
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)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2023-03-20 14:10:26 +00:00
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(parent, "foo", "bar")
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
child := testutil.GenerateObjectWithCID(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
|
|
|
|
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
|
2023-03-20 14:10:26 +00:00
|
|
|
ts := testutil.GenerateObjectWithCID(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
|
|
|
|
2023-04-03 13:53:55 +00:00
|
|
|
ts = testutil.GenerateObjectWithCID(cnr)
|
|
|
|
|
|
|
|
err = metaInhume(db, object.AddressOf(parent), object.AddressOf(ts))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
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
|
|
|
|
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))
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, client.IsErrObjectAlreadyRemoved(err))
|
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))
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, client.IsErrObjectAlreadyRemoved(err))
|
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)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2021-02-11 17:39:48 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2021-02-11 17:39:48 +00:00
|
|
|
|
|
|
|
// generate parent object
|
2023-03-20 14:10:26 +00:00
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
2021-02-11 17:39:48 +00:00
|
|
|
|
|
|
|
// generate 2 children
|
2023-03-20 14:10:26 +00:00
|
|
|
child1 := testutil.GenerateObjectWithCID(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
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
child2 := testutil.GenerateObjectWithCID(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)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2021-04-06 14:07:42 +00:00
|
|
|
|
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}))
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2022-07-27 18:38:28 +00:00
|
|
|
|
|
|
|
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)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-01-24 15:41:02 +00:00
|
|
|
func TestDelete(t *testing.T) {
|
|
|
|
db := newDB(t, meta.WithEpochState(epochState{currEpoch}))
|
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
|
|
|
|
|
|
|
cnr := cidtest.ID()
|
2024-08-30 16:20:55 +00:00
|
|
|
for range 10 {
|
2024-01-24 15:41:02 +00:00
|
|
|
obj := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
|
|
|
|
var prm meta.PutPrm
|
|
|
|
prm.SetObject(obj)
|
|
|
|
prm.SetStorageID([]byte("0/0"))
|
|
|
|
_, err := db.Put(context.Background(), prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var inhumePrm meta.InhumePrm
|
|
|
|
inhumePrm.SetAddresses(object.AddressOf(obj))
|
|
|
|
_, err = db.Inhume(context.Background(), inhumePrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var addrs []oid.Address
|
|
|
|
var iprm meta.GarbageIterationPrm
|
|
|
|
iprm.SetHandler(func(o meta.GarbageObject) error {
|
|
|
|
addrs = append(addrs, o.Address())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
require.NoError(t, db.IterateOverGarbage(context.Background(), iprm))
|
|
|
|
require.Equal(t, 10, len(addrs))
|
|
|
|
var deletePrm meta.DeletePrm
|
|
|
|
deletePrm.SetAddresses(addrs...)
|
|
|
|
_, err := db.Delete(context.Background(), deletePrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
addrs = nil
|
|
|
|
iprm.SetHandler(func(o meta.GarbageObject) error {
|
|
|
|
addrs = append(addrs, o.Address())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
require.NoError(t, db.IterateOverGarbage(context.Background(), iprm))
|
|
|
|
require.Equal(t, 0, len(addrs))
|
|
|
|
}
|
|
|
|
|
2024-02-06 16:25:24 +00:00
|
|
|
func TestDeleteDropsGCMarkIfObjectNotFound(t *testing.T) {
|
|
|
|
db := newDB(t, meta.WithEpochState(epochState{currEpoch}))
|
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
|
|
|
|
|
|
|
addr := oidtest.Address()
|
|
|
|
|
|
|
|
var prm meta.InhumePrm
|
|
|
|
prm.SetAddresses(addr)
|
|
|
|
prm.SetGCMark()
|
|
|
|
_, err := db.Inhume(context.Background(), prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var garbageCount int
|
|
|
|
var itPrm meta.GarbageIterationPrm
|
|
|
|
itPrm.SetHandler(func(g meta.GarbageObject) error {
|
|
|
|
garbageCount++
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
require.NoError(t, db.IterateOverGarbage(context.Background(), itPrm))
|
|
|
|
require.Equal(t, 1, garbageCount)
|
|
|
|
|
|
|
|
var delPrm meta.DeletePrm
|
|
|
|
delPrm.SetAddresses(addr)
|
|
|
|
_, err = db.Delete(context.Background(), delPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
garbageCount = 0
|
|
|
|
require.NoError(t, db.IterateOverGarbage(context.Background(), itPrm))
|
|
|
|
require.Equal(t, 0, garbageCount)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := db.Delete(context.Background(), deletePrm)
|
2022-07-12 14:42:55 +00:00
|
|
|
return err
|
2021-04-06 14:07:42 +00:00
|
|
|
}
|