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) {
|
|
|
|
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
|
|
|
|
|
|
|
var splitErr *objectSDK.SplitInfoError
|
|
|
|
|
|
|
|
addrParent := object.AddressOf(parent)
|
|
|
|
checkGetError(t, e, addrParent, &splitErr)
|
|
|
|
|
|
|
|
addrLink := object.AddressOf(link)
|
|
|
|
checkGetError(t, e, addrLink, nil)
|
|
|
|
|
|
|
|
for i := range children {
|
|
|
|
checkGetError(t, e, object.AddressOf(children[i]), nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
checkGetError(t, e, addrParent, &apistatus.ObjectNotFound{})
|
|
|
|
checkGetError(t, e, addrLink, &apistatus.ObjectNotFound{})
|
|
|
|
for i := range children {
|
|
|
|
checkGetError(t, e, object.AddressOf(children[i]), &apistatus.ObjectNotFound{})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-21 11:42:45 +00:00
|
|
|
func checkGetError(t *testing.T, e *StorageEngine, addr oid.Address, expected any) {
|
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)
|
2022-10-04 14:59:18 +00:00
|
|
|
if expected != nil {
|
|
|
|
require.ErrorAs(t, err, expected)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|