2023-05-23 12:02:38 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
2023-08-23 07:53:42 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
2023-08-04 11:14:07 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-05-23 12:02:38 +00:00
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-05-23 12:02:38 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"github.com/panjf2000/ants/v2"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_ObjectNotFoundIfNotDeletedFromMetabase(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
rootPath := t.TempDir()
|
|
|
|
|
|
|
|
var sh *Shard
|
2024-01-09 08:37:41 +00:00
|
|
|
l := test.NewLogger(t)
|
2023-05-23 12:02:38 +00:00
|
|
|
blobOpts := []blobstor.Option{
|
2024-01-09 08:37:41 +00:00
|
|
|
blobstor.WithLogger(test.NewLogger(t)),
|
2023-05-23 12:02:38 +00:00
|
|
|
blobstor.WithStorages([]blobstor.SubStorage{
|
|
|
|
{
|
|
|
|
Storage: blobovniczatree.NewBlobovniczaTree(
|
2024-03-01 11:43:26 +00:00
|
|
|
context.Background(),
|
2024-01-09 08:37:41 +00:00
|
|
|
blobovniczatree.WithLogger(test.NewLogger(t)),
|
2023-05-23 12:02:38 +00:00
|
|
|
blobovniczatree.WithRootPath(filepath.Join(rootPath, "blob", "blobovnicza")),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowDepth(1),
|
|
|
|
blobovniczatree.WithBlobovniczaShallowWidth(1)),
|
2023-07-06 12:36:41 +00:00
|
|
|
Policy: func(_ *objectSDK.Object, data []byte) bool {
|
2023-05-23 12:02:38 +00:00
|
|
|
return len(data) <= 1<<20
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Storage: fstree.New(
|
|
|
|
fstree.WithPath(filepath.Join(rootPath, "blob"))),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
|
|
|
opts := []Option{
|
|
|
|
WithID(NewIDFromBytes([]byte{})),
|
|
|
|
WithLogger(l),
|
|
|
|
WithBlobStorOptions(blobOpts...),
|
|
|
|
WithMetaBaseOptions(
|
|
|
|
meta.WithPath(filepath.Join(rootPath, "meta")),
|
|
|
|
meta.WithEpochState(epochState{}),
|
|
|
|
),
|
|
|
|
WithPiloramaOptions(pilorama.WithPath(filepath.Join(rootPath, "pilorama"))),
|
2024-10-21 13:27:28 +00:00
|
|
|
WithDeletedLockCallback(func(ctx context.Context, addresses []oid.Address) {
|
|
|
|
sh.HandleDeletedLocks(ctx, addresses)
|
2023-05-23 12:02:38 +00:00
|
|
|
}),
|
|
|
|
WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
|
|
|
|
sh.HandleExpiredLocks(ctx, epoch, a)
|
|
|
|
}),
|
|
|
|
WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
|
|
|
|
pool, err := ants.NewPool(sz)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return pool
|
|
|
|
}),
|
|
|
|
WithGCRemoverSleepInterval(1 * time.Second),
|
2024-10-17 11:16:03 +00:00
|
|
|
WithDisabledGC(),
|
2023-05-23 12:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sh = New(opts...)
|
2023-08-31 16:26:47 +00:00
|
|
|
require.NoError(t, sh.Open(context.Background()))
|
2023-05-23 12:02:38 +00:00
|
|
|
require.NoError(t, sh.Init(context.Background()))
|
2024-10-21 08:56:38 +00:00
|
|
|
defer func() { require.NoError(t, sh.Close(context.Background())) }()
|
2023-05-23 12:02:38 +00:00
|
|
|
|
|
|
|
cnr := cidtest.ID()
|
|
|
|
obj := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
objID, _ := obj.ID()
|
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(cnr)
|
|
|
|
addr.SetObject(objID)
|
|
|
|
|
|
|
|
var putPrm PutPrm
|
|
|
|
putPrm.SetObject(obj)
|
|
|
|
|
|
|
|
_, err := sh.Put(context.Background(), putPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var getPrm GetPrm
|
|
|
|
getPrm.SetAddress(objectCore.AddressOf(obj))
|
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
|
|
|
require.NoError(t, err, "failed to get")
|
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
// inhume
|
2023-05-23 12:02:38 +00:00
|
|
|
var inhumePrm InhumePrm
|
|
|
|
inhumePrm.MarkAsGarbage(addr)
|
|
|
|
_, err = sh.Inhume(context.Background(), inhumePrm)
|
|
|
|
require.NoError(t, err, "failed to inhume")
|
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
|
|
|
require.Error(t, err, "get returned error")
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, client.IsErrObjectNotFound(err), "invalid error type")
|
2023-05-23 12:02:38 +00:00
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
// storageID
|
2023-05-23 12:02:38 +00:00
|
|
|
var metaStIDPrm meta.StorageIDPrm
|
|
|
|
metaStIDPrm.SetAddress(addr)
|
|
|
|
storageID, err := sh.metaBase.StorageID(context.Background(), metaStIDPrm)
|
|
|
|
require.NoError(t, err, "failed to get storage ID")
|
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
// check existence in blobstore
|
2023-05-23 12:02:38 +00:00
|
|
|
var bsExisted common.ExistsPrm
|
|
|
|
bsExisted.Address = addr
|
|
|
|
bsExisted.StorageID = storageID.StorageID()
|
|
|
|
exRes, err := sh.blobStor.Exists(context.Background(), bsExisted)
|
2023-08-30 14:10:21 +00:00
|
|
|
require.NoError(t, err, "failed to check blobstore existence")
|
|
|
|
require.True(t, exRes.Exists, "invalid blobstore existence result")
|
2023-05-23 12:02:38 +00:00
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
// drop from blobstor
|
2023-05-23 12:02:38 +00:00
|
|
|
var bsDeletePrm common.DeletePrm
|
|
|
|
bsDeletePrm.Address = addr
|
|
|
|
bsDeletePrm.StorageID = storageID.StorageID()
|
|
|
|
_, err = sh.blobStor.Delete(context.Background(), bsDeletePrm)
|
|
|
|
require.NoError(t, err, "failed to delete from blobstore")
|
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
// check existence in blobstore
|
2023-05-23 12:02:38 +00:00
|
|
|
exRes, err = sh.blobStor.Exists(context.Background(), bsExisted)
|
2023-08-30 14:10:21 +00:00
|
|
|
require.NoError(t, err, "failed to check blobstore existence")
|
|
|
|
require.False(t, exRes.Exists, "invalid blobstore existence result")
|
2023-05-23 12:02:38 +00:00
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
// get should return object not found
|
2023-05-23 12:02:38 +00:00
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
|
|
|
require.Error(t, err, "get returned no error")
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, client.IsErrObjectNotFound(err), "invalid error type")
|
2023-05-23 12:02:38 +00:00
|
|
|
}
|