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