2023-08-31 12:47:06 +00:00
|
|
|
package shard
|
2023-03-17 07:56:37 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-05-15 08:43:44 +00:00
|
|
|
"errors"
|
2023-03-17 07:56:37 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
2024-03-06 09:33:30 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
2023-03-23 09:42:58 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2023-03-17 07:56:37 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2024-03-06 09:33:30 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
2023-09-06 15:03:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
2024-11-07 14:32:10 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
2023-08-04 11:14:07 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2024-03-06 09:33:30 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2023-03-17 07:56:37 +00:00
|
|
|
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"
|
2023-05-15 08:43:44 +00:00
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
2023-03-17 07:56:37 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-05-15 08:43:44 +00:00
|
|
|
func Test_GCDropsLockedExpiredSimpleObject(t *testing.T) {
|
2023-05-05 11:08:10 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2023-03-17 07:56:37 +00:00
|
|
|
epoch := &epochState{
|
|
|
|
Value: 100,
|
|
|
|
}
|
|
|
|
|
2023-09-06 15:03:04 +00:00
|
|
|
sh := newCustomShard(t, false, shardOptions{
|
|
|
|
metaOptions: []meta.Option{meta.WithEpochState(epoch)},
|
|
|
|
additionalShardOptions: []Option{WithGCWorkerPoolInitializer(func(int) util.WorkerPool {
|
|
|
|
return util.NewPseudoWorkerPool() // synchronous event processing
|
|
|
|
})},
|
|
|
|
})
|
2024-10-21 08:56:38 +00:00
|
|
|
defer func() { require.NoError(t, sh.Close(context.Background())) }()
|
2023-03-17 07:56:37 +00:00
|
|
|
|
|
|
|
cnr := cidtest.ID()
|
|
|
|
|
|
|
|
var objExpirationAttr objectSDK.Attribute
|
|
|
|
objExpirationAttr.SetKey(objectV2.SysAttributeExpEpoch)
|
|
|
|
objExpirationAttr.SetValue("101")
|
|
|
|
|
2023-03-23 09:42:58 +00:00
|
|
|
obj := testutil.GenerateObjectWithCID(cnr)
|
2023-03-17 07:56:37 +00:00
|
|
|
obj.SetAttributes(objExpirationAttr)
|
|
|
|
objID, _ := obj.ID()
|
|
|
|
|
|
|
|
var lockExpirationAttr objectSDK.Attribute
|
|
|
|
lockExpirationAttr.SetKey(objectV2.SysAttributeExpEpoch)
|
|
|
|
lockExpirationAttr.SetValue("103")
|
|
|
|
|
2023-03-23 09:42:58 +00:00
|
|
|
lock := testutil.GenerateObjectWithCID(cnr)
|
2023-04-03 13:11:56 +00:00
|
|
|
lock.SetType(objectSDK.TypeLock)
|
2023-03-17 07:56:37 +00:00
|
|
|
lock.SetAttributes(lockExpirationAttr)
|
|
|
|
lockID, _ := lock.ID()
|
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var putPrm PutPrm
|
2023-03-17 07:56:37 +00:00
|
|
|
putPrm.SetObject(obj)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := sh.Put(context.Background(), putPrm)
|
2023-03-17 07:56:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
err = sh.Lock(context.Background(), cnr, lockID, []oid.ID{objID})
|
2023-03-17 07:56:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
putPrm.SetObject(lock)
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = sh.Put(context.Background(), putPrm)
|
2023-03-17 07:56:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
epoch.Value = 105
|
2023-09-06 15:03:04 +00:00
|
|
|
sh.gc.handleEvent(context.Background(), EventNewEpoch(epoch.Value))
|
2023-03-17 07:56:37 +00:00
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var getPrm GetPrm
|
2023-03-17 07:56:37 +00:00
|
|
|
getPrm.SetAddress(objectCore.AddressOf(obj))
|
2023-09-06 15:03:04 +00:00
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
2024-08-20 08:59:42 +00:00
|
|
|
require.True(t, client.IsErrObjectNotFound(err) || IsErrObjectExpired(err), "expired object must be deleted")
|
2023-03-17 07:56:37 +00:00
|
|
|
}
|
2023-05-15 08:43:44 +00:00
|
|
|
|
|
|
|
func Test_GCDropsLockedExpiredComplexObject(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
epoch := &epochState{
|
|
|
|
Value: 100,
|
|
|
|
}
|
|
|
|
|
|
|
|
cnr := cidtest.ID()
|
|
|
|
parentID := oidtest.ID()
|
|
|
|
splitID := objectSDK.NewSplitID()
|
|
|
|
|
|
|
|
var objExpirationAttr objectSDK.Attribute
|
|
|
|
objExpirationAttr.SetKey(objectV2.SysAttributeExpEpoch)
|
|
|
|
objExpirationAttr.SetValue("101")
|
|
|
|
|
|
|
|
var lockExpirationAttr objectSDK.Attribute
|
|
|
|
lockExpirationAttr.SetKey(objectV2.SysAttributeExpEpoch)
|
|
|
|
lockExpirationAttr.SetValue("103")
|
|
|
|
|
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
parent.SetID(parentID)
|
|
|
|
parent.SetPayload(nil)
|
|
|
|
parent.SetAttributes(objExpirationAttr)
|
|
|
|
|
|
|
|
const childCount = 10
|
|
|
|
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...)
|
|
|
|
|
|
|
|
linkID, _ := link.ID()
|
|
|
|
|
2023-09-06 15:03:04 +00:00
|
|
|
sh := newCustomShard(t, false, shardOptions{
|
|
|
|
metaOptions: []meta.Option{meta.WithEpochState(epoch)},
|
|
|
|
additionalShardOptions: []Option{WithGCWorkerPoolInitializer(func(int) util.WorkerPool {
|
|
|
|
return util.NewPseudoWorkerPool() // synchronous event processing
|
|
|
|
})},
|
|
|
|
})
|
2024-10-21 08:56:38 +00:00
|
|
|
defer func() { require.NoError(t, sh.Close(context.Background())) }()
|
2023-05-15 08:43:44 +00:00
|
|
|
|
|
|
|
lock := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
lock.SetAttributes(lockExpirationAttr)
|
|
|
|
lockID, _ := lock.ID()
|
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var putPrm PutPrm
|
2023-05-15 08:43:44 +00:00
|
|
|
|
|
|
|
for _, child := range children {
|
|
|
|
putPrm.SetObject(child)
|
|
|
|
_, err := sh.Put(context.Background(), putPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
putPrm.SetObject(link)
|
|
|
|
_, err := sh.Put(context.Background(), putPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = sh.Lock(context.Background(), cnr, lockID, append(childIDs, parentID, linkID))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
putPrm.SetObject(lock)
|
|
|
|
_, err = sh.Put(context.Background(), putPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var getPrm GetPrm
|
2023-05-15 08:43:44 +00:00
|
|
|
getPrm.SetAddress(objectCore.AddressOf(parent))
|
|
|
|
|
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
|
|
|
var splitInfoError *objectSDK.SplitInfoError
|
|
|
|
require.True(t, errors.As(err, &splitInfoError), "split info must be provided")
|
|
|
|
|
|
|
|
epoch.Value = 105
|
2023-09-06 15:03:04 +00:00
|
|
|
sh.gc.handleEvent(context.Background(), EventNewEpoch(epoch.Value))
|
2023-05-15 08:43:44 +00:00
|
|
|
|
2023-09-06 15:03:04 +00:00
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
2024-08-20 08:59:42 +00:00
|
|
|
require.True(t, client.IsErrObjectNotFound(err) || IsErrObjectExpired(err), "expired complex object must be deleted on epoch after lock expires")
|
2023-05-15 08:43:44 +00:00
|
|
|
}
|
2024-03-06 09:33:30 +00:00
|
|
|
|
|
|
|
func TestGCDropsObjectInhumedFromWritecache(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
t.Run("flush write-cache before inhume", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
testGCDropsObjectInhumedFromWritecache(t, true)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("don't flush write-cache before inhume", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
testGCDropsObjectInhumedFromWritecache(t, false)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testGCDropsObjectInhumedFromWritecache(t *testing.T, flushbeforeInhume bool) {
|
|
|
|
sh := newCustomShard(t, true, shardOptions{
|
2024-09-04 06:30:56 +00:00
|
|
|
additionalShardOptions: []Option{WithDisabledGC()},
|
2024-03-06 09:33:30 +00:00
|
|
|
wcOpts: []writecache.Option{writecache.WithDisableBackgroundFlush()},
|
|
|
|
})
|
2024-10-21 08:56:38 +00:00
|
|
|
defer func() { require.NoError(t, sh.Close(context.Background())) }()
|
2024-03-06 09:33:30 +00:00
|
|
|
|
|
|
|
obj := testutil.GenerateObjectWithSize(1024)
|
|
|
|
|
|
|
|
var putPrm PutPrm
|
|
|
|
putPrm.SetObject(obj)
|
|
|
|
_, err := sh.Put(context.Background(), putPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// writecache stores object
|
|
|
|
wcObj, err := sh.writeCache.Head(context.Background(), objectCore.AddressOf(obj))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, objectCore.AddressOf(obj), objectCore.AddressOf(wcObj))
|
|
|
|
|
|
|
|
// blobstore doesn't store object
|
|
|
|
bsRes, err := sh.blobStor.Get(context.Background(), common.GetPrm{
|
|
|
|
Address: objectCore.AddressOf(obj),
|
|
|
|
})
|
|
|
|
require.ErrorAs(t, err, new(*apistatus.ObjectNotFound))
|
|
|
|
require.Nil(t, bsRes.Object)
|
|
|
|
require.Nil(t, bsRes.RawData)
|
|
|
|
|
|
|
|
if flushbeforeInhume {
|
|
|
|
sh.writeCache.Flush(context.Background(), false, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
var inhumePrm InhumePrm
|
|
|
|
inhumePrm.MarkAsGarbage(objectCore.AddressOf(obj))
|
|
|
|
_, err = sh.Inhume(context.Background(), inhumePrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// writecache doesn't store object
|
|
|
|
wcObj, err = sh.writeCache.Head(context.Background(), objectCore.AddressOf(obj))
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, wcObj)
|
|
|
|
|
|
|
|
if flushbeforeInhume {
|
|
|
|
// blobstore store object
|
|
|
|
bsRes, err = sh.blobStor.Get(context.Background(), common.GetPrm{
|
|
|
|
Address: objectCore.AddressOf(obj),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, objectCore.AddressOf(obj), objectCore.AddressOf(bsRes.Object))
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// blobstore doesn't store object
|
|
|
|
bsRes, err = sh.blobStor.Get(context.Background(), common.GetPrm{
|
|
|
|
Address: objectCore.AddressOf(obj),
|
|
|
|
})
|
|
|
|
require.ErrorAs(t, err, new(*apistatus.ObjectNotFound))
|
|
|
|
require.Nil(t, bsRes.Object)
|
|
|
|
require.Nil(t, bsRes.RawData)
|
|
|
|
}
|
|
|
|
|
|
|
|
gcRes := sh.removeGarbage(context.Background())
|
|
|
|
require.True(t, gcRes.success)
|
|
|
|
require.Equal(t, uint64(1), gcRes.deleted)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGCDontDeleteObjectFromWritecache(t *testing.T) {
|
|
|
|
sh := newCustomShard(t, true, shardOptions{
|
|
|
|
additionalShardOptions: []Option{WithDisabledGC()},
|
|
|
|
wcOpts: []writecache.Option{writecache.WithDisableBackgroundFlush()},
|
|
|
|
})
|
2024-10-21 08:56:38 +00:00
|
|
|
defer func() { require.NoError(t, sh.Close(context.Background())) }()
|
2024-03-06 09:33:30 +00:00
|
|
|
|
|
|
|
obj := testutil.GenerateObjectWithSize(1024)
|
|
|
|
|
|
|
|
var putPrm PutPrm
|
|
|
|
putPrm.SetObject(obj)
|
|
|
|
_, err := sh.Put(context.Background(), putPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// writecache stores object
|
|
|
|
wcObj, err := sh.writeCache.Head(context.Background(), objectCore.AddressOf(obj))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, objectCore.AddressOf(obj), objectCore.AddressOf(wcObj))
|
|
|
|
|
|
|
|
// blobstore doesn't store object
|
|
|
|
bsRes, err := sh.blobStor.Get(context.Background(), common.GetPrm{
|
|
|
|
Address: objectCore.AddressOf(obj),
|
|
|
|
})
|
|
|
|
require.ErrorAs(t, err, new(*apistatus.ObjectNotFound))
|
|
|
|
require.Nil(t, bsRes.Object)
|
|
|
|
require.Nil(t, bsRes.RawData)
|
|
|
|
|
|
|
|
var metaInhumePrm meta.InhumePrm
|
|
|
|
metaInhumePrm.SetAddresses(objectCore.AddressOf(obj))
|
|
|
|
metaInhumePrm.SetLockObjectHandling()
|
|
|
|
metaInhumePrm.SetGCMark()
|
|
|
|
_, err = sh.metaBase.Inhume(context.Background(), metaInhumePrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// logs: WARN shard/delete.go:98 can't remove object: object must be flushed from writecache
|
|
|
|
gcRes := sh.removeGarbage(context.Background())
|
|
|
|
require.True(t, gcRes.success)
|
|
|
|
require.Equal(t, uint64(0), gcRes.deleted)
|
|
|
|
|
|
|
|
// writecache stores object
|
|
|
|
wcObj, err = sh.writeCache.Head(context.Background(), objectCore.AddressOf(obj))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, objectCore.AddressOf(obj), objectCore.AddressOf(wcObj))
|
|
|
|
}
|