2022-10-04 14:59:18 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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-28 14:16:03 +00:00
|
|
|
e := testNewEngineWithShards(t, s1, s2, s3)
|
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 {
|
|
|
|
require.NoError(t, Put(e, children[i]))
|
|
|
|
}
|
|
|
|
require.NoError(t, Put(e, link))
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
_, err := e.Delete(deletePrm)
|
|
|
|
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)
|
|
|
|
|
|
|
|
_, err := e.Get(getPrm)
|
|
|
|
if expected != nil {
|
|
|
|
require.ErrorAs(t, err, expected)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|