2021-04-14 08:50:21 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2021-04-14 08:50:21 +00:00
|
|
|
"testing"
|
|
|
|
|
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
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2021-04-14 08:50:21 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeadRaw(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2023-07-06 12:36:41 +00:00
|
|
|
splitID := objectSDK.NewSplitID()
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(parent, "foo", "bar")
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var parentAddr oid.Address
|
|
|
|
parentAddr.SetContainer(cnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
|
|
|
|
idParent, _ := parent.ID()
|
2022-05-31 17:00:41 +00:00
|
|
|
parentAddr.SetObject(idParent)
|
2021-04-14 08:50:21 +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
|
|
|
child.SetParentID(idParent)
|
2021-04-14 08:50:21 +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)
|
2021-04-14 08:50:21 +00:00
|
|
|
link.SetSplitID(splitID)
|
|
|
|
|
|
|
|
t.Run("virtual object split in different shards", func(t *testing.T) {
|
2024-03-01 08:58:17 +00:00
|
|
|
s1 := testNewShard(t)
|
|
|
|
s2 := testNewShard(t)
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2023-03-30 11:58:20 +00:00
|
|
|
e := testNewEngine(t).setInitializedShards(t, s1, s2).engine
|
2023-08-31 16:26:47 +00:00
|
|
|
defer e.Close(context.Background())
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var putPrmLeft shard.PutPrm
|
2022-07-13 12:43:04 +00:00
|
|
|
putPrmLeft.SetObject(child)
|
2022-05-20 18:08:59 +00:00
|
|
|
|
|
|
|
var putPrmLink shard.PutPrm
|
2022-07-13 12:43:04 +00:00
|
|
|
putPrmLink.SetObject(link)
|
2021-04-14 08:50:21 +00:00
|
|
|
|
|
|
|
// put most left object in one shard
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := s1.Put(context.Background(), putPrmLeft)
|
2021-04-14 08:50:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// put link object in another shard
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = s2.Put(context.Background(), putPrmLink)
|
2021-04-14 08:50:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// head with raw flag should return SplitInfoError
|
2022-05-23 13:12:32 +00:00
|
|
|
var headPrm HeadPrm
|
|
|
|
headPrm.WithAddress(parentAddr)
|
|
|
|
headPrm.WithRaw(true)
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
_, err = e.Head(context.Background(), headPrm)
|
2021-04-14 08:50:21 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
var si *objectSDK.SplitInfoError
|
2022-10-26 12:23:12 +00:00
|
|
|
require.ErrorAs(t, err, &si)
|
2021-04-14 08:50:21 +00:00
|
|
|
|
|
|
|
// SplitInfoError should contain info from both shards
|
|
|
|
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)
|
2021-04-14 08:50:21 +00:00
|
|
|
})
|
|
|
|
}
|