2020-11-23 13:30:56 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
2020-12-03 09:31:51 +00:00
|
|
|
"errors"
|
2020-11-23 13:30:56 +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"
|
|
|
|
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"
|
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
2020-11-23 13:30:56 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-07-27 18:38:28 +00:00
|
|
|
const currEpoch = 1000
|
|
|
|
|
2020-11-23 13:30:56 +00:00
|
|
|
func TestDB_Exists(t *testing.T) {
|
2022-07-27 18:38:28 +00:00
|
|
|
db := newDB(t, meta.WithEpochState(epochState{currEpoch}))
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("no object", func(t *testing.T) {
|
2023-03-20 14:10:26 +00:00
|
|
|
nonExist := testutil.GenerateObject()
|
2022-07-12 14:42:55 +00:00
|
|
|
exists, err := metaExists(db, object.AddressOf(nonExist))
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, exists)
|
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("regular object", func(t *testing.T) {
|
2023-03-20 14:10:26 +00:00
|
|
|
regular := testutil.GenerateObject()
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, regular)
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
exists, err := metaExists(db, object.AddressOf(regular))
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
2022-07-01 11:21:33 +00:00
|
|
|
|
|
|
|
t.Run("removed object", func(t *testing.T) {
|
|
|
|
err := metaInhume(db, object.AddressOf(regular), oidtest.Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
exists, err := metaExists(db, object.AddressOf(regular))
|
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))
|
|
|
|
require.False(t, exists)
|
|
|
|
})
|
2020-11-27 07:59:47 +00:00
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("tombstone object", func(t *testing.T) {
|
2023-03-20 14:10:26 +00:00
|
|
|
ts := testutil.GenerateObject()
|
2020-11-27 07:59:47 +00:00
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, ts)
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
exists, err := metaExists(db, object.AddressOf(ts))
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("storage group object", func(t *testing.T) {
|
2023-03-20 14:10:26 +00:00
|
|
|
sg := testutil.GenerateObject()
|
2020-11-27 07:59:47 +00:00
|
|
|
sg.SetType(objectSDK.TypeStorageGroup)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, sg)
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
exists, err := metaExists(db, object.AddressOf(sg))
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
|
|
|
|
2022-02-15 12:51:56 +00:00
|
|
|
t.Run("lock object", func(t *testing.T) {
|
2023-03-20 14:10:26 +00:00
|
|
|
lock := testutil.GenerateObject()
|
2022-02-15 12:51:56 +00:00
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
|
|
|
|
err := putBig(db, lock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
exists, err := metaExists(db, object.AddressOf(lock))
|
2022-02-15 12:51:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("virtual object", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2023-03-20 14:10:26 +00:00
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
2020-11-27 07:59:47 +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-11-27 07:59:47 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, child)
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
_, err = metaExists(db, object.AddressOf(parent))
|
2020-12-03 09:31:51 +00:00
|
|
|
|
|
|
|
var expectedErr *objectSDK.SplitInfoError
|
|
|
|
require.True(t, errors.As(err, &expectedErr))
|
2020-11-27 07:59:47 +00:00
|
|
|
})
|
2020-12-04 09:01:41 +00:00
|
|
|
|
|
|
|
t.Run("merge split info", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-12-04 09:01:41 +00:00
|
|
|
splitID := objectSDK.NewSplitID()
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(parent, "foo", "bar")
|
2020-12-04 09:01:41 +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-12-04 09:01:41 +00:00
|
|
|
child.SetSplitID(splitID)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
link := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
link.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
link.SetParentID(idParent)
|
|
|
|
idChild, _ := child.ID()
|
|
|
|
link.SetChildren(idChild)
|
2020-12-04 09:01:41 +00:00
|
|
|
link.SetSplitID(splitID)
|
|
|
|
|
|
|
|
t.Run("direct order", func(t *testing.T) {
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, child)
|
2020-12-04 09:01:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, link)
|
2020-12-04 09:01:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
_, err = metaExists(db, object.AddressOf(parent))
|
2020-12-04 09:01:41 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-10-26 12:23:12 +00:00
|
|
|
var si *objectSDK.SplitInfoError
|
|
|
|
require.ErrorAs(t, err, &si)
|
2020-12-04 09:01:41 +00:00
|
|
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
2022-05-12 16:37:46 +00:00
|
|
|
|
|
|
|
id1, _ := child.ID()
|
|
|
|
id2, _ := si.SplitInfo().LastPart()
|
|
|
|
require.Equal(t, id1, id2)
|
|
|
|
|
|
|
|
id1, _ = link.ID()
|
|
|
|
id2, _ = si.SplitInfo().Link()
|
|
|
|
require.Equal(t, id1, id2)
|
2020-12-04 09:01:41 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("reverse order", func(t *testing.T) {
|
2022-07-12 14:42:55 +00:00
|
|
|
err := metaPut(db, link, nil)
|
2020-12-04 09:01:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, child)
|
2020-12-04 09:01:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
_, err = metaExists(db, object.AddressOf(parent))
|
2020-12-04 09:01:41 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-10-26 12:23:12 +00:00
|
|
|
var si *objectSDK.SplitInfoError
|
|
|
|
require.ErrorAs(t, err, &si)
|
2020-12-04 09:01:41 +00:00
|
|
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
2022-05-12 16:37:46 +00:00
|
|
|
|
|
|
|
id1, _ := child.ID()
|
|
|
|
id2, _ := si.SplitInfo().LastPart()
|
|
|
|
require.Equal(t, id1, id2)
|
|
|
|
|
|
|
|
id1, _ = link.ID()
|
|
|
|
id2, _ = si.SplitInfo().Link()
|
|
|
|
require.Equal(t, id1, id2)
|
2020-12-04 09:01:41 +00:00
|
|
|
})
|
|
|
|
})
|
2022-07-01 11:21:33 +00:00
|
|
|
|
|
|
|
t.Run("random object", func(t *testing.T) {
|
|
|
|
addr := oidtest.Address()
|
|
|
|
|
|
|
|
exists, err := metaExists(db, addr)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, exists)
|
|
|
|
})
|
2022-07-27 18:38:28 +00:00
|
|
|
|
|
|
|
t.Run("expired object", func(t *testing.T) {
|
|
|
|
checkExpiredObjects(t, db, func(exp, nonExp *objectSDK.Object) {
|
|
|
|
gotObj, err := metaExists(db, object.AddressOf(exp))
|
|
|
|
require.False(t, gotObj)
|
2022-10-31 07:08:30 +00:00
|
|
|
require.ErrorIs(t, err, meta.ErrObjectIsExpired)
|
2022-07-27 18:38:28 +00:00
|
|
|
|
|
|
|
gotObj, err = metaExists(db, object.AddressOf(nonExp))
|
|
|
|
require.True(t, gotObj)
|
|
|
|
})
|
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|