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
|
|
|
"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"
|
2024-01-10 08:56:24 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
2023-03-07 13:38:26 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDeleteBigObject(t *testing.T) {
|
2023-05-05 13:17:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-10-04 14:59:18 +00:00
|
|
|
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...)
|
|
|
|
|
2024-11-13 10:30:16 +00:00
|
|
|
e := testNewEngine(t).setShardsNum(t, 3).prepare(t).engine
|
|
|
|
defer func() { require.NoError(t, e.Close(context.Background())) }()
|
2022-10-04 14:59:18 +00:00
|
|
|
|
|
|
|
for i := range children {
|
2024-10-01 12:27:06 +00:00
|
|
|
require.NoError(t, Put(context.Background(), e, children[i], false))
|
2022-10-04 14:59:18 +00:00
|
|
|
}
|
2024-10-01 12:27:06 +00:00
|
|
|
require.NoError(t, Put(context.Background(), e, link, false))
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-10 08:56:24 +00:00
|
|
|
func TestDeleteBigObjectWithoutGC(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cnr := cidtest.ID()
|
|
|
|
parentID := oidtest.ID()
|
|
|
|
splitID := objectSDK.NewSplitID()
|
|
|
|
|
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
parent.SetID(parentID)
|
|
|
|
parent.SetPayload(nil)
|
|
|
|
|
|
|
|
const childCount = 3
|
|
|
|
children := make([]*objectSDK.Object, childCount)
|
|
|
|
childIDs := make([]oid.ID, childCount)
|
|
|
|
for i := range children {
|
|
|
|
children[i] = testutil.GenerateObjectWithCID(cnr)
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
|
|
|
link := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
link.SetParent(parent)
|
|
|
|
link.SetParentID(parentID)
|
|
|
|
link.SetSplitID(splitID)
|
|
|
|
link.SetChildren(childIDs...)
|
|
|
|
|
2024-11-13 10:30:16 +00:00
|
|
|
te := testNewEngine(t).setShardsNumAdditionalOpts(t, 1, func(_ int) []shard.Option {
|
|
|
|
return []shard.Option{shard.WithDisabledGC()}
|
|
|
|
}).prepare(t)
|
|
|
|
e := te.engine
|
|
|
|
defer func() { require.NoError(t, e.Close(context.Background())) }()
|
2024-01-10 08:56:24 +00:00
|
|
|
|
2024-11-13 10:30:16 +00:00
|
|
|
s1 := te.shards[0]
|
2024-01-10 08:56:24 +00:00
|
|
|
|
|
|
|
for i := range children {
|
2024-10-01 12:27:06 +00:00
|
|
|
require.NoError(t, Put(context.Background(), e, children[i], false))
|
2024-01-10 08:56:24 +00:00
|
|
|
}
|
2024-10-01 12:27:06 +00:00
|
|
|
require.NoError(t, Put(context.Background(), e, link, false))
|
2024-01-10 08:56:24 +00:00
|
|
|
|
|
|
|
addrParent := object.AddressOf(parent)
|
|
|
|
checkGetError[*objectSDK.SplitInfoError](t, e, addrParent, true)
|
|
|
|
|
|
|
|
addrLink := object.AddressOf(link)
|
|
|
|
checkGetError[error](t, e, addrLink, false)
|
|
|
|
|
|
|
|
for i := range children {
|
|
|
|
checkGetError[error](t, e, object.AddressOf(children[i]), false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete logical
|
|
|
|
var deletePrm DeletePrm
|
|
|
|
deletePrm.WithForceRemoval()
|
|
|
|
deletePrm.WithAddress(addrParent)
|
|
|
|
|
|
|
|
_, err := e.Delete(context.Background(), deletePrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
checkGetError[*apistatus.ObjectNotFound](t, e, addrParent, true)
|
|
|
|
checkGetError[*apistatus.ObjectNotFound](t, e, addrLink, true)
|
|
|
|
for i := range children {
|
|
|
|
checkGetError[*apistatus.ObjectNotFound](t, e, object.AddressOf(children[i]), true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete physical
|
|
|
|
var delPrm shard.DeletePrm
|
|
|
|
delPrm.SetAddresses(addrParent)
|
|
|
|
_, err = s1.Delete(context.Background(), delPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
delPrm.SetAddresses(addrLink)
|
|
|
|
_, err = s1.Delete(context.Background(), delPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for i := range children {
|
|
|
|
delPrm.SetAddresses(object.AddressOf(children[i]))
|
|
|
|
_, err = s1.Delete(context.Background(), delPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
checkGetError[*apistatus.ObjectNotFound](t, e, addrParent, true)
|
|
|
|
checkGetError[*apistatus.ObjectNotFound](t, e, addrLink, true)
|
|
|
|
for i := range children {
|
|
|
|
checkGetError[*apistatus.ObjectNotFound](t, e, object.AddressOf(children[i]), true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|