2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-28 14:49:30 +00:00
|
|
|
|
|
|
|
import (
|
2023-08-31 16:26:47 +00:00
|
|
|
"context"
|
2023-08-14 11:01:39 +00:00
|
|
|
"path/filepath"
|
2022-07-27 18:38:28 +00:00
|
|
|
"strconv"
|
2020-10-28 14:49:30 +00:00
|
|
|
"testing"
|
|
|
|
|
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
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2024-02-09 06:17:17 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2024-11-07 14:32:10 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-10-28 14:49:30 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-07-27 18:38:28 +00:00
|
|
|
type epochState struct{ e uint64 }
|
2022-07-27 18:34:25 +00:00
|
|
|
|
|
|
|
func (s epochState) CurrentEpoch() uint64 {
|
2022-07-27 18:38:28 +00:00
|
|
|
if s.e != 0 {
|
|
|
|
return s.e
|
|
|
|
}
|
|
|
|
|
2022-09-09 10:27:15 +00:00
|
|
|
return 0
|
2022-07-27 18:34:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
// saves "big" object in DB.
|
2023-04-03 13:11:56 +00:00
|
|
|
func putBig(db *meta.DB, obj *objectSDK.Object) error {
|
2022-07-12 14:42:55 +00:00
|
|
|
return metaPut(db, obj, nil)
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 13:11:56 +00:00
|
|
|
func testSelect(t *testing.T, db *meta.DB, cnr cid.ID, fs objectSDK.SearchFilters, exp ...oid.Address) {
|
2024-10-02 10:04:29 +00:00
|
|
|
res, err := metaSelect(db, cnr, fs, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, res, len(exp))
|
|
|
|
|
|
|
|
for i := range exp {
|
|
|
|
require.Contains(t, res, exp[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSelect2(t *testing.T, db *meta.DB, cnr cid.ID, fs objectSDK.SearchFilters, useAttrIndex bool, exp ...oid.Address) {
|
|
|
|
res, err := metaSelect(db, cnr, fs, useAttrIndex)
|
2020-10-28 14:49:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, res, len(exp))
|
|
|
|
|
|
|
|
for i := range exp {
|
|
|
|
require.Contains(t, res, exp[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 13:34:31 +00:00
|
|
|
func newDB(t testing.TB, opts ...meta.Option) *meta.DB {
|
2022-07-27 18:34:25 +00:00
|
|
|
bdb := meta.New(
|
|
|
|
append([]meta.Option{
|
2023-08-14 11:01:39 +00:00
|
|
|
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
|
2023-10-31 11:56:55 +00:00
|
|
|
meta.WithPermissions(0o600),
|
2022-07-27 18:34:25 +00:00
|
|
|
meta.WithEpochState(epochState{}),
|
|
|
|
}, opts...)...,
|
|
|
|
)
|
2020-10-29 12:03:55 +00:00
|
|
|
|
2024-02-09 06:17:17 +00:00
|
|
|
require.NoError(t, bdb.Open(context.Background(), mode.ReadWrite))
|
2022-04-26 19:49:59 +00:00
|
|
|
require.NoError(t, bdb.Init())
|
2020-10-29 12:03:55 +00:00
|
|
|
|
2021-10-27 10:56:30 +00:00
|
|
|
return bdb
|
2020-10-29 16:12:38 +00:00
|
|
|
}
|
2020-11-02 07:37:16 +00:00
|
|
|
|
2022-07-27 18:38:28 +00:00
|
|
|
func checkExpiredObjects(t *testing.T, db *meta.DB, f func(exp, nonExp *objectSDK.Object)) {
|
2023-03-20 14:10:26 +00:00
|
|
|
expObj := testutil.GenerateObject()
|
2022-09-05 05:48:42 +00:00
|
|
|
setExpiration(expObj, currEpoch-1)
|
2022-07-27 18:38:28 +00:00
|
|
|
|
|
|
|
require.NoError(t, metaPut(db, expObj, nil))
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
nonExpObj := testutil.GenerateObject()
|
2022-09-05 05:48:42 +00:00
|
|
|
setExpiration(nonExpObj, currEpoch)
|
2022-07-27 18:38:28 +00:00
|
|
|
|
|
|
|
require.NoError(t, metaPut(db, nonExpObj, nil))
|
|
|
|
|
|
|
|
f(expObj, nonExpObj)
|
|
|
|
}
|
|
|
|
|
|
|
|
func setExpiration(o *objectSDK.Object, epoch uint64) {
|
|
|
|
var attr objectSDK.Attribute
|
|
|
|
|
|
|
|
attr.SetKey(objectV2.SysAttributeExpEpoch)
|
|
|
|
attr.SetValue(strconv.FormatUint(epoch, 10))
|
|
|
|
|
|
|
|
o.SetAttributes(append(o.Attributes(), attr)...)
|
|
|
|
}
|