2022-10-04 14:59:18 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2023-04-04 11:40:01 +00:00
|
|
|
"context"
|
2022-10-04 14:59:18 +00:00
|
|
|
"os"
|
|
|
|
"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
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
|
|
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"
|
2022-10-04 14:59:18 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap/zaptest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDeleteBigObject(t *testing.T) {
|
2023-05-05 13:17:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-10-04 14:59:18 +00:00
|
|
|
defer os.RemoveAll(t.Name())
|
|
|
|
|
|
|
|
cnr := cidtest.ID()
|
|
|
|
parentID := oidtest.ID()
|
|
|
|
splitID := objectSDK.NewSplitID()
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
2022-10-04 14:59:18 +00:00
|
|
|
parent.SetID(parentID)
|
|
|
|
parent.SetPayload(nil)
|
|
|
|
|
|
|
|
const childCount = 10
|
|
|
|
children := make([]*objectSDK.Object, childCount)
|
|
|
|
childIDs := make([]oid.ID, childCount)
|
|
|
|
for i := range children {
|
2023-03-20 14:10:26 +00:00
|
|
|
children[i] = testutil.GenerateObjectWithCID(cnr)
|
2022-10-04 14:59:18 +00:00
|
|
|
if i != 0 {
|
|
|
|
children[i].SetPreviousID(childIDs[i-1])
|
|
|
|
}
|
|
|
|
if i == len(children)-1 {
|
|
|
|
children[i].SetParent(parent)
|
|
|
|
}
|
|
|
|
children[i].SetSplitID(splitID)
|
|
|
|
children[i].SetPayload([]byte{byte(i), byte(i + 1), byte(i + 2)})
|
|
|
|
childIDs[i], _ = children[i].ID()
|
|
|
|
}
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
link := testutil.GenerateObjectWithCID(cnr)
|
2022-10-04 14:59:18 +00:00
|
|
|
link.SetParent(parent)
|
|
|
|
link.SetParentID(parentID)
|
|
|
|
link.SetSplitID(splitID)
|
|
|
|
link.SetChildren(childIDs...)
|
|
|
|
|
|
|
|
s1 := testNewShard(t, 1)
|
|
|
|
s2 := testNewShard(t, 2)
|
|
|
|
s3 := testNewShard(t, 3)
|
|
|
|
|
2023-03-30 11:58:20 +00:00
|
|
|
e := testNewEngine(t).setInitializedShards(t, s1, s2, s3).engine
|
2022-09-28 07:41:01 +00:00
|
|
|
e.log = &logger.Logger{Logger: zaptest.NewLogger(t)}
|
2022-10-04 14:59:18 +00:00
|
|
|
defer e.Close()
|
|
|
|
|
|
|
|
for i := range children {
|
2023-04-12 14:01:29 +00:00
|
|
|
require.NoError(t, Put(context.Background(), e, children[i]))
|
2022-10-04 14:59:18 +00:00
|
|
|
}
|
2023-04-12 14:01:29 +00:00
|
|
|
require.NoError(t, Put(context.Background(), e, link))
|
2022-10-04 14:59:18 +00:00
|
|
|
|
|
|
|
addrParent := object.AddressOf(parent)
|
2023-08-04 11:14:07 +00:00
|
|
|
checkGetError[*objectSDK.SplitInfoError](t, e, addrParent, true)
|
2022-10-04 14:59:18 +00:00
|
|
|
|
|
|
|
addrLink := object.AddressOf(link)
|
2023-08-04 11:14:07 +00:00
|
|
|
checkGetError[error](t, e, addrLink, false)
|
2022-10-04 14:59:18 +00:00
|
|
|
|
|
|
|
for i := range children {
|
2023-08-04 11:14:07 +00:00
|
|
|
checkGetError[error](t, e, object.AddressOf(children[i]), false)
|
2022-10-04 14:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var deletePrm DeletePrm
|
|
|
|
deletePrm.WithForceRemoval()
|
|
|
|
deletePrm.WithAddress(addrParent)
|
|
|
|
|
2023-04-04 11:40:01 +00:00
|
|
|
_, err := e.Delete(context.Background(), deletePrm)
|
2022-10-04 14:59:18 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-08-04 11:14:07 +00:00
|
|
|
checkGetError[*apistatus.ObjectNotFound](t, e, addrParent, true)
|
|
|
|
checkGetError[*apistatus.ObjectNotFound](t, e, addrLink, true)
|
2022-10-04 14:59:18 +00:00
|
|
|
for i := range children {
|
2023-08-04 11:14:07 +00:00
|
|
|
checkGetError[*apistatus.ObjectNotFound](t, e, object.AddressOf(children[i]), true)
|
2022-10-04 14:59:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-04 11:14:07 +00:00
|
|
|
func checkGetError[E error](t *testing.T, e *StorageEngine, addr oid.Address, shouldFail bool) {
|
2022-10-04 14:59:18 +00:00
|
|
|
var getPrm GetPrm
|
|
|
|
getPrm.WithAddress(addr)
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
_, err := e.Get(context.Background(), getPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
if shouldFail {
|
|
|
|
var target E
|
|
|
|
require.ErrorAs(t, err, &target)
|
2022-10-04 14:59:18 +00:00
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|