2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-28 14:49:30 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2022-07-27 18:38:28 +00:00
|
|
|
"strconv"
|
2020-10-28 14:49:30 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum"
|
|
|
|
checksumtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum/test"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
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"
|
|
|
|
usertest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user/test"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
|
|
|
|
"git.frostfs.info/TrueCloudLab/tzhash/tz"
|
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.
|
|
|
|
func putBig(db *meta.DB, obj *object.Object) error {
|
2022-07-12 14:42:55 +00:00
|
|
|
return metaPut(db, obj, nil)
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func testSelect(t *testing.T, db *meta.DB, cnr cid.ID, fs object.SearchFilters, exp ...oid.Address) {
|
2022-07-12 14:42:55 +00:00
|
|
|
res, err := metaSelect(db, cnr, fs)
|
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 {
|
2020-12-08 07:51:34 +00:00
|
|
|
path := t.Name()
|
2020-10-29 12:03:55 +00:00
|
|
|
|
2022-07-27 18:34:25 +00:00
|
|
|
bdb := meta.New(
|
|
|
|
append([]meta.Option{
|
|
|
|
meta.WithPath(path),
|
|
|
|
meta.WithPermissions(0600),
|
|
|
|
meta.WithEpochState(epochState{}),
|
|
|
|
}, opts...)...,
|
|
|
|
)
|
2020-10-29 12:03:55 +00:00
|
|
|
|
2022-06-28 13:42:50 +00:00
|
|
|
require.NoError(t, bdb.Open(false))
|
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
|
|
|
t.Cleanup(func() {
|
|
|
|
bdb.Close()
|
|
|
|
os.Remove(bdb.DumpInfo().Path)
|
|
|
|
})
|
2020-10-29 16:12:38 +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-03-21 13:34:31 +00:00
|
|
|
func generateObject(t testing.TB) *object.Object {
|
2022-03-03 14:19:05 +00:00
|
|
|
return generateObjectWithCID(t, cidtest.ID())
|
2020-11-02 07:37:16 +00:00
|
|
|
}
|
2020-11-02 07:55:35 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
func generateObjectWithCID(t testing.TB, cnr cid.ID) *object.Object {
|
2022-05-11 14:58:52 +00:00
|
|
|
var ver version.Version
|
|
|
|
ver.SetMajor(2)
|
|
|
|
ver.SetMinor(1)
|
2020-11-02 07:55:35 +00:00
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
csum := checksumtest.Checksum()
|
2020-11-02 08:01:55 +00:00
|
|
|
|
2022-05-11 16:35:01 +00:00
|
|
|
var csumTZ checksum.Checksum
|
|
|
|
csumTZ.SetTillichZemor(tz.Sum(csum.Value()))
|
2020-11-02 08:01:55 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := object.New()
|
2022-05-12 16:37:46 +00:00
|
|
|
obj.SetID(oidtest.ID())
|
2022-05-17 13:59:46 +00:00
|
|
|
obj.SetOwnerID(usertest.ID())
|
2022-05-12 16:37:46 +00:00
|
|
|
obj.SetContainerID(cnr)
|
2022-05-11 14:58:52 +00:00
|
|
|
obj.SetVersion(&ver)
|
2020-12-08 07:51:34 +00:00
|
|
|
obj.SetPayloadChecksum(csum)
|
|
|
|
obj.SetPayloadHomomorphicHash(csumTZ)
|
2021-03-22 16:44:57 +00:00
|
|
|
obj.SetPayload([]byte{1, 2, 3, 4, 5})
|
2020-11-02 08:01:55 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
return obj
|
2020-11-02 08:01:55 +00:00
|
|
|
}
|
2020-11-06 09:41:59 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
func addAttribute(obj *object.Object, key, val string) {
|
2022-03-15 12:11:35 +00:00
|
|
|
var attr object.Attribute
|
2020-12-08 07:51:34 +00:00
|
|
|
attr.SetKey(key)
|
|
|
|
attr.SetValue(val)
|
2020-11-06 09:41:59 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
attrs := obj.Attributes()
|
|
|
|
attrs = append(attrs, attr)
|
|
|
|
obj.SetAttributes(attrs...)
|
2020-11-06 09:41:59 +00:00
|
|
|
}
|
2022-07-27 18:38:28 +00:00
|
|
|
|
|
|
|
func checkExpiredObjects(t *testing.T, db *meta.DB, f func(exp, nonExp *objectSDK.Object)) {
|
|
|
|
expObj := generateObject(t)
|
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))
|
|
|
|
|
|
|
|
nonExpObj := generateObject(t)
|
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)...)
|
|
|
|
}
|