2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-30 13:42:24 +00:00
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2020-12-08 07:51:34 +00:00
|
|
|
"encoding/hex"
|
2024-06-05 08:14:06 +00:00
|
|
|
"math/rand"
|
2022-05-25 12:56:45 +00:00
|
|
|
"strconv"
|
2020-10-30 13:42:24 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
v2object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
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"
|
|
|
|
cidSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2024-06-05 08:14:06 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/erasurecode"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
2024-06-05 08:14:06 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer"
|
|
|
|
usertest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user/test"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
|
2024-06-05 08:14:06 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-10-30 13:42:24 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectUserAttributes(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw1 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(raw1, "foo", "bar")
|
|
|
|
testutil.AddAttribute(raw1, "x", "y")
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw2 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(raw2, "foo", "bar")
|
|
|
|
testutil.AddAttribute(raw2, "x", "z")
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw3 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(raw3, "a", "b")
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw3)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw4 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(raw4, "path", "test/1/2")
|
2021-08-18 07:26:14 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw4)
|
2021-08-18 07:26:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw5 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(raw5, "path", "test/1/3")
|
2021-08-18 07:26:14 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw5)
|
2021-08-18 07:26:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw6 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(raw6, "path", "test/2/3")
|
2021-08-18 07:26:14 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw6)
|
2021-08-18 07:26:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-09-12 06:53:21 +00:00
|
|
|
raw7 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
var attr objectSDK.Attribute
|
|
|
|
attr.SetKey("path")
|
|
|
|
attr.SetValue("test/3/4")
|
|
|
|
attrs := raw7.Attributes()
|
|
|
|
attrs = append(attrs, attr)
|
|
|
|
ech := objectSDK.NewECHeader(objectSDK.ECParentInfo{
|
|
|
|
ID: oidtest.ID(),
|
|
|
|
Attributes: attrs,
|
|
|
|
}, 0, 3, []byte{}, 0)
|
|
|
|
raw7.SetECHeader(ech)
|
|
|
|
require.NoError(t, putBig(db, raw7))
|
|
|
|
var raw7Parent oid.Address
|
|
|
|
raw7Parent.SetContainer(cnr)
|
|
|
|
raw7Parent.SetObject(ech.Parent())
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("foo", "bar", objectSDK.MatchStringEqual)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("x", "y", objectSDK.MatchStringEqual)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2021-02-01 21:00:40 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("x", "y", objectSDK.MatchStringNotEqual)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("a", "b", objectSDK.MatchStringEqual)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw3))
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("c", "d", objectSDK.MatchStringEqual)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter("foo", "", objectSDK.MatchNotPresent)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw3),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2024-09-12 06:53:21 +00:00
|
|
|
object.AddressOf(raw7),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("a", "", objectSDK.MatchNotPresent)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2024-09-12 06:53:21 +00:00
|
|
|
object.AddressOf(raw7),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
|
|
|
object.AddressOf(raw3),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2024-09-12 06:53:21 +00:00
|
|
|
object.AddressOf(raw7),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("key", "", objectSDK.MatchNotPresent)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
|
|
|
object.AddressOf(raw3),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2024-09-12 06:53:21 +00:00
|
|
|
object.AddressOf(raw7),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("path", "test", objectSDK.MatchCommonPrefix)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2024-09-12 06:53:21 +00:00
|
|
|
raw7Parent,
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("path", "test/1", objectSDK.MatchCommonPrefix)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2024-09-12 06:53:21 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("path", "test/3/4", objectSDK.MatchStringEqual)
|
|
|
|
testSelect(t, db, cnr, fs,
|
|
|
|
raw7Parent,
|
|
|
|
)
|
2020-10-30 13:42:24 +00:00
|
|
|
}
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectRootPhyParent(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-11-03 13:12:34 +00:00
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// prepare
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
small := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, small)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
ts := testutil.GenerateObjectWithCID(cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, ts)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
leftChild := testutil.GenerateObjectWithCID(cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
leftChild.InitRelations()
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, leftChild)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
lock := testutil.GenerateObjectWithCID(cnr)
|
2022-02-15 12:51:56 +00:00
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
err = putBig(db, lock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
rightChild := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
rightChild.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
idParent, _ := parent.ID()
|
|
|
|
rightChild.SetParentID(idParent)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, rightChild)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
link := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
link.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
link.SetParentID(idParent)
|
|
|
|
idLeftChild, _ := leftChild.ID()
|
|
|
|
idRightChild, _ := rightChild.ID()
|
|
|
|
link.SetChildren(idLeftChild, idRightChild)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, link)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("root objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddRootFilter()
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(parent),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterPropertyRoot, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("phy objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddPhyFilter()
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterPropertyPhy, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("regular objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
2020-11-03 14:09:59 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringNotEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("tombstone objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(ts))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringNotEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("objects with parent", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
idParent, _ := parent.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderParent,
|
2022-05-12 16:37:46 +00:00
|
|
|
idParent.EncodeToString(),
|
2020-12-08 07:51:34 +00:00
|
|
|
objectSDK.MatchStringEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderParent, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("all objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectInhume(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-11-03 14:09:59 +00:00
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw1 := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw2 := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2024-09-20 10:28:21 +00:00
|
|
|
err = metaInhume(db, object.AddressOf(raw2), oidtest.ID())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-11-03 14:09:59 +00:00
|
|
|
}
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectPayloadHash(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-11-03 14:24:23 +00:00
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw1 := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw2 := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-05-11 16:35:01 +00:00
|
|
|
cs, _ := raw1.PayloadChecksum()
|
2022-05-25 13:05:41 +00:00
|
|
|
payloadHash := hex.EncodeToString(cs.Value())
|
2022-05-11 16:35:01 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
2022-05-25 13:05:41 +00:00
|
|
|
payloadHash,
|
2020-12-08 07:51:34 +00:00
|
|
|
objectSDK.MatchStringEqual)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
2022-05-25 13:05:41 +00:00
|
|
|
payloadHash[:len(payloadHash)-1],
|
|
|
|
objectSDK.MatchCommonPrefix)
|
|
|
|
|
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
|
|
|
payloadHash,
|
2021-02-01 21:00:40 +00:00
|
|
|
objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
|
|
|
"",
|
|
|
|
objectSDK.MatchNotPresent)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2022-05-25 12:39:51 +00:00
|
|
|
|
|
|
|
t.Run("invalid hashes", func(t *testing.T) {
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
|
|
|
payloadHash[:len(payloadHash)-1],
|
|
|
|
objectSDK.MatchStringNotEqual)
|
|
|
|
|
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1), object.AddressOf(raw2))
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
|
|
|
payloadHash[:len(payloadHash)-2]+"x",
|
|
|
|
objectSDK.MatchCommonPrefix)
|
|
|
|
|
|
|
|
testSelect(t, db, cnr, fs)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
|
|
|
payloadHash[:len(payloadHash)-3]+"x0",
|
|
|
|
objectSDK.MatchCommonPrefix)
|
|
|
|
|
|
|
|
testSelect(t, db, cnr, fs)
|
|
|
|
})
|
2020-12-08 07:51:34 +00:00
|
|
|
}
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectWithSlowFilters(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2021-11-10 07:08:33 +00:00
|
|
|
v20 := new(version.Version)
|
2020-12-08 07:51:34 +00:00
|
|
|
v20.SetMajor(2)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var v21 version.Version
|
2020-12-08 07:51:34 +00:00
|
|
|
v21.SetMajor(2)
|
|
|
|
v21.SetMinor(1)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw1 := testutil.GenerateObjectWithCID(cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
raw1.SetPayloadSize(10)
|
|
|
|
raw1.SetCreationEpoch(11)
|
|
|
|
raw1.SetVersion(v20)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw2 := testutil.GenerateObjectWithCID(cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
raw2.SetPayloadSize(20)
|
|
|
|
raw2.SetCreationEpoch(21)
|
2022-05-31 17:00:41 +00:00
|
|
|
raw2.SetVersion(&v21)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("object with TZHash", func(t *testing.T) {
|
2022-05-11 16:35:01 +00:00
|
|
|
cs, _ := raw1.PayloadHomomorphicHash()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
2022-05-11 16:35:01 +00:00
|
|
|
hex.EncodeToString(cs.Value()),
|
2020-12-08 07:51:34 +00:00
|
|
|
objectSDK.MatchStringEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
2022-05-11 16:35:01 +00:00
|
|
|
hex.EncodeToString(cs.Value()),
|
2021-02-01 21:00:40 +00:00
|
|
|
objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
|
|
|
"",
|
|
|
|
objectSDK.MatchNotPresent)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("object with payload length", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "", objectSDK.MatchNotPresent)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("object with creation epoch", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "", objectSDK.MatchNotPresent)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2022-05-25 13:05:41 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "1", objectSDK.MatchCommonPrefix)
|
|
|
|
|
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("object with version", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddObjectVersionFilter(objectSDK.MatchStringEqual, v21)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectVersionFilter(objectSDK.MatchStringNotEqual, v21)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
fs.AddObjectVersionFilter(objectSDK.MatchNotPresent, version.Version{})
|
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDB_SelectObjectID(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-11-05 16:54:24 +00:00
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// prepare
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
regular := testutil.GenerateObjectWithCID(cnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
idParent, _ := parent.ID()
|
|
|
|
regular.SetParentID(idParent)
|
2022-03-03 14:19:05 +00:00
|
|
|
regular.SetParent(parent)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, regular)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
ts := testutil.GenerateObjectWithCID(cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, ts)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
lock := testutil.GenerateObjectWithCID(cnr)
|
2022-02-15 12:51:56 +00:00
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
err = putBig(db, lock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("not found objects", func(t *testing.T) {
|
2023-03-20 14:10:26 +00:00
|
|
|
raw := testutil.GenerateObjectWithCID(cnr)
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := raw.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("regular objects", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := regular.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(regular))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("tombstone objects", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := ts.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(ts))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
2021-02-01 21:00:40 +00:00
|
|
|
t.Run("parent objects", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := parent.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(parent))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("lock objects", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := lock.ID()
|
|
|
|
|
2022-02-15 12:51:56 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(lock))
|
2022-02-15 12:51:56 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(ts),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-05 16:54:24 +00:00
|
|
|
}
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2024-08-19 14:13:39 +00:00
|
|
|
func TestDB_SelectOwnerID(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
db := newDB(t)
|
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
|
|
|
|
|
|
|
cnr := cidtest.ID()
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
|
|
|
|
regular := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
idParent, _ := parent.ID()
|
|
|
|
regular.SetParentID(idParent)
|
|
|
|
regular.SetParent(parent)
|
|
|
|
|
|
|
|
err := putBig(db, regular)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ts := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
|
|
|
err = putBig(db, ts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
lock := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
err = putBig(db, lock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("not found objects", func(t *testing.T) {
|
|
|
|
raw := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectOwnerIDFilter(objectSDK.MatchStringEqual, raw.OwnerID())
|
|
|
|
|
|
|
|
testSelect(t, db, cnr, fs)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectOwnerIDFilter(objectSDK.MatchStringNotEqual, raw.OwnerID())
|
|
|
|
|
|
|
|
testSelect(t, db, cnr, fs,
|
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(lock),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("regular objects", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectOwnerIDFilter(objectSDK.MatchStringEqual, regular.OwnerID())
|
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(regular))
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectOwnerIDFilter(objectSDK.MatchStringNotEqual, regular.OwnerID())
|
|
|
|
testSelect(t, db, cnr, fs,
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(lock),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("tombstone objects", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectOwnerIDFilter(objectSDK.MatchStringEqual, ts.OwnerID())
|
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(ts))
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectOwnerIDFilter(objectSDK.MatchStringNotEqual, ts.OwnerID())
|
|
|
|
testSelect(t, db, cnr, fs,
|
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(lock),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("parent objects", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectOwnerIDFilter(objectSDK.MatchStringEqual, parent.OwnerID())
|
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(parent))
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectOwnerIDFilter(objectSDK.MatchStringNotEqual, parent.OwnerID())
|
|
|
|
testSelect(t, db, cnr, fs,
|
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(lock),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("lock objects", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectOwnerIDFilter(objectSDK.MatchStringEqual, lock.OwnerID())
|
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(lock))
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectOwnerIDFilter(objectSDK.MatchStringNotEqual, lock.OwnerID())
|
|
|
|
testSelect(t, db, cnr, fs,
|
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(ts),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-10-02 08:28:00 +00:00
|
|
|
func TestDB_SelectECWithFastAndSlowFilters(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
db := newDB(t)
|
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
|
|
|
|
|
|
|
cnr := cidtest.ID()
|
|
|
|
ecChunk1 := oidtest.ID()
|
|
|
|
ecChunk2 := oidtest.ID()
|
|
|
|
ecParent := oidtest.ID()
|
|
|
|
var ecParentAddr oid.Address
|
|
|
|
ecParentAddr.SetContainer(cnr)
|
|
|
|
ecParentAddr.SetObject(ecParent)
|
|
|
|
var ecParentAttr []objectSDK.Attribute
|
|
|
|
var attr objectSDK.Attribute
|
|
|
|
attr.SetKey(objectSDK.AttributeFilePath)
|
|
|
|
attr.SetValue("/1/2/3")
|
|
|
|
ecParentAttr = append(ecParentAttr, attr)
|
|
|
|
|
|
|
|
chunkObj := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
chunkObj.SetContainerID(cnr)
|
|
|
|
chunkObj.SetID(ecChunk1)
|
|
|
|
chunkObj.SetPayload([]byte{0, 1, 2, 3, 4})
|
|
|
|
chunkObj.SetPayloadSize(uint64(5))
|
|
|
|
chunkObj.SetECHeader(objectSDK.NewECHeader(objectSDK.ECParentInfo{ID: ecParent, Attributes: ecParentAttr}, 0, 3, []byte{}, 0))
|
|
|
|
|
|
|
|
chunkObj2 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
chunkObj2.SetContainerID(cnr)
|
|
|
|
chunkObj2.SetID(ecChunk2)
|
|
|
|
chunkObj2.SetPayload([]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
|
|
|
|
chunkObj2.SetPayloadSize(uint64(10))
|
|
|
|
chunkObj2.SetECHeader(objectSDK.NewECHeader(objectSDK.ECParentInfo{ID: ecParent, Attributes: ecParentAttr}, 1, 3, []byte{}, 0))
|
|
|
|
|
|
|
|
// put object with EC
|
|
|
|
|
|
|
|
var prm meta.PutPrm
|
|
|
|
prm.SetObject(chunkObj)
|
|
|
|
_, err := db.Put(context.Background(), prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
prm.SetObject(chunkObj2)
|
|
|
|
_, err = db.Put(context.Background(), prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddRootFilter()
|
|
|
|
fs.AddFilter(objectSDK.AttributeFilePath, "/1/2/3", objectSDK.MatchCommonPrefix)
|
|
|
|
testSelect(t, db, cnr, fs, ecParentAddr)
|
|
|
|
}
|
|
|
|
|
2024-06-05 08:14:06 +00:00
|
|
|
type testTarget struct {
|
|
|
|
objects []*objectSDK.Object
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tt *testTarget) WriteObject(_ context.Context, obj *objectSDK.Object) error {
|
|
|
|
tt.objects = append(tt.objects, obj)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-06-06 07:52:17 +00:00
|
|
|
func cutObject(t *testing.T, p transformer.ChunkedObjectWriter, hdr *objectSDK.Object, size int) *transformer.AccessIdentifiers {
|
2024-06-05 08:14:06 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
require.NoError(t, p.WriteHeader(ctx, hdr))
|
|
|
|
|
|
|
|
payload := make([]byte, size)
|
|
|
|
rand.New(rand.NewSource(0)).Read(payload)
|
|
|
|
|
|
|
|
_, err := p.Write(ctx, payload)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-06 07:52:17 +00:00
|
|
|
ids, err := p.Close(ctx)
|
2024-06-05 08:14:06 +00:00
|
|
|
require.NoError(t, err)
|
2024-06-06 07:52:17 +00:00
|
|
|
return ids
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDB_RawHead_SplitInfo(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
const (
|
|
|
|
partSize = 10
|
|
|
|
partCount = 2
|
|
|
|
dataCount = 2
|
|
|
|
parityCount = 1
|
|
|
|
)
|
|
|
|
|
|
|
|
db := newDB(t)
|
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
|
|
|
|
|
|
|
cnr := cidtest.ID()
|
|
|
|
|
|
|
|
pk, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tt := new(testTarget)
|
|
|
|
p := transformer.NewPayloadSizeLimiter(transformer.Params{
|
|
|
|
Key: &pk.PrivateKey,
|
|
|
|
NextTargetInit: func() transformer.ObjectWriter { return tt },
|
|
|
|
NetworkState: epochState{e: 1},
|
|
|
|
MaxSize: partSize,
|
|
|
|
})
|
|
|
|
|
|
|
|
hdr := objectSDK.New()
|
|
|
|
hdr.SetContainerID(cnr)
|
|
|
|
hdr.SetOwnerID(usertest.ID())
|
|
|
|
ids := cutObject(t, p, hdr, partSize*partCount)
|
|
|
|
require.Equal(t, len(tt.objects), partCount+1)
|
|
|
|
|
|
|
|
t.Run("rep", func(t *testing.T) {
|
|
|
|
testGetRawSplitInfo(t, cnr, ids, tt.objects[partCount], tt.objects[partCount-1])
|
|
|
|
})
|
|
|
|
t.Run("with ec", func(t *testing.T) {
|
|
|
|
ec, err := erasurecode.NewConstructor(dataCount, parityCount)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cs, err := ec.Split(tt.objects[partCount-1], &pk.PrivateKey)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
testGetRawSplitInfo(t, cnr, ids, tt.objects[partCount], cs[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testGetRawSplitInfo(t *testing.T, cnr cidSDK.ID, ids *transformer.AccessIdentifiers, linking, lastPart *objectSDK.Object) {
|
|
|
|
expectedLinkID, ok := linking.ID()
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
t.Run("first last, then linking", func(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
|
|
|
|
|
|
|
require.NoError(t, metaPut(db, lastPart, nil))
|
|
|
|
require.NoError(t, metaPut(db, linking, nil))
|
|
|
|
|
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(cnr)
|
|
|
|
addr.SetObject(*ids.ParentID)
|
|
|
|
|
|
|
|
_, err := metaGet(db, addr, true)
|
|
|
|
|
|
|
|
var siErr *objectSDK.SplitInfoError
|
|
|
|
require.ErrorAs(t, err, &siErr)
|
|
|
|
|
|
|
|
lastID, ok := siErr.SplitInfo().LastPart()
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, ids.SelfID, lastID)
|
|
|
|
|
|
|
|
linkID, ok := siErr.SplitInfo().Link()
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, expectedLinkID, linkID)
|
|
|
|
})
|
|
|
|
t.Run("first linking, then last", func(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
|
|
|
|
|
|
|
require.NoError(t, metaPut(db, linking, nil))
|
|
|
|
require.NoError(t, metaPut(db, lastPart, nil))
|
|
|
|
|
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(cnr)
|
|
|
|
addr.SetObject(*ids.ParentID)
|
|
|
|
|
|
|
|
_, err := metaGet(db, addr, true)
|
|
|
|
|
|
|
|
var siErr *objectSDK.SplitInfoError
|
|
|
|
require.ErrorAs(t, err, &siErr)
|
|
|
|
|
|
|
|
lastID, ok := siErr.SplitInfo().LastPart()
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, ids.SelfID, lastID)
|
|
|
|
|
|
|
|
linkID, ok := siErr.SplitInfo().Link()
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, expectedLinkID, linkID)
|
|
|
|
})
|
|
|
|
t.Run("only last part", func(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
|
|
|
|
|
|
|
require.NoError(t, metaPut(db, lastPart, nil))
|
|
|
|
|
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(cnr)
|
|
|
|
addr.SetObject(*ids.ParentID)
|
|
|
|
|
|
|
|
_, err := metaGet(db, addr, true)
|
|
|
|
|
|
|
|
var siErr *objectSDK.SplitInfoError
|
|
|
|
require.ErrorAs(t, err, &siErr)
|
|
|
|
|
|
|
|
lastPart, ok := siErr.SplitInfo().LastPart()
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, ids.SelfID, lastPart)
|
|
|
|
})
|
2024-06-05 08:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDB_SelectSplitID_EC(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
const (
|
|
|
|
partSize = 10
|
|
|
|
partCount = 2
|
|
|
|
dataCount = 2
|
|
|
|
parityCount = 1
|
|
|
|
)
|
|
|
|
|
|
|
|
db := newDB(t)
|
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
|
|
|
|
|
|
|
cnr := cidtest.ID()
|
|
|
|
|
|
|
|
pk, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tt := new(testTarget)
|
|
|
|
p := transformer.NewPayloadSizeLimiter(transformer.Params{
|
|
|
|
Key: &pk.PrivateKey,
|
|
|
|
NextTargetInit: func() transformer.ObjectWriter { return tt },
|
|
|
|
NetworkState: epochState{e: 1},
|
|
|
|
MaxSize: partSize,
|
|
|
|
})
|
|
|
|
|
|
|
|
hdr := objectSDK.New()
|
|
|
|
hdr.SetContainerID(cnr)
|
|
|
|
hdr.SetOwnerID(usertest.ID())
|
|
|
|
cutObject(t, p, hdr, partSize*partCount)
|
|
|
|
require.Equal(t, len(tt.objects), partCount+1)
|
|
|
|
|
|
|
|
split := tt.objects[0].SplitID()
|
|
|
|
require.NotNil(t, split)
|
|
|
|
|
|
|
|
ec, err := erasurecode.NewConstructor(dataCount, parityCount)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range partCount {
|
2024-06-05 08:14:06 +00:00
|
|
|
cs, err := ec.Split(tt.objects[i], &pk.PrivateKey)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NoError(t, putBig(db, cs[0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("not present", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, "", objectSDK.MatchNotPresent)
|
|
|
|
testSelect(t, db, cnr, fs)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("split id", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, split.String(), objectSDK.MatchStringEqual)
|
|
|
|
testSelect(t, db, cnr, fs,
|
|
|
|
object.AddressOf(tt.objects[0]),
|
|
|
|
object.AddressOf(tt.objects[1]),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty split", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, "", objectSDK.MatchStringEqual)
|
|
|
|
testSelect(t, db, cnr, fs)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("unknown split id", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID,
|
|
|
|
objectSDK.NewSplitID().String(),
|
|
|
|
objectSDK.MatchStringEqual)
|
|
|
|
testSelect(t, db, cnr, fs)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectSplitID(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-11-20 07:43:41 +00:00
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
child1 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
child2 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
child3 := testutil.GenerateObjectWithCID(cnr)
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
split1 := objectSDK.NewSplitID()
|
|
|
|
split2 := objectSDK.NewSplitID()
|
|
|
|
|
|
|
|
child1.SetSplitID(split1)
|
|
|
|
child2.SetSplitID(split1)
|
|
|
|
child3.SetSplitID(split2)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
require.NoError(t, putBig(db, child1))
|
|
|
|
require.NoError(t, putBig(db, child2))
|
|
|
|
require.NoError(t, putBig(db, child3))
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2021-02-01 21:00:40 +00:00
|
|
|
t.Run("not present", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2021-02-01 21:00:40 +00:00
|
|
|
})
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("split id", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, split1.String(), objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(child1),
|
|
|
|
object.AddressOf(child2),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, split2.String(), objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(child3))
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty split", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, "", objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("unknown split id", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID,
|
|
|
|
objectSDK.NewSplitID().String(),
|
|
|
|
objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-10 13:17:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDB_SelectContainerID(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2020-12-10 13:17:45 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-12-10 13:17:45 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
obj1 := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, obj1)
|
2020-12-10 13:17:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
obj2 := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, obj2)
|
2020-12-10 13:17:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("same cid", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, cnr)
|
2020-12-10 13:17:45 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(obj1),
|
|
|
|
object.AddressOf(obj2),
|
2020-12-10 13:17:45 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringNotEqual, cnr)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(obj1),
|
|
|
|
object.AddressOf(obj2),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchNotPresent, cnr)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-10 13:17:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not same cid", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
newCnr := cidtest.ID()
|
2020-12-10 13:17:45 +00:00
|
|
|
|
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, newCnr)
|
2020-12-10 13:17:45 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-20 07:43:41 +00:00
|
|
|
}
|
2022-05-25 12:56:45 +00:00
|
|
|
|
|
|
|
func BenchmarkSelect(b *testing.B) {
|
|
|
|
const objCount = 1000
|
|
|
|
db := newDB(b)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(b, db.Close()) }()
|
|
|
|
|
2022-05-25 12:56:45 +00:00
|
|
|
cid := cidtest.ID()
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range objCount {
|
2022-05-25 12:56:45 +00:00
|
|
|
var attr objectSDK.Attribute
|
|
|
|
attr.SetKey("myHeader")
|
|
|
|
attr.SetValue(strconv.Itoa(i))
|
2023-03-20 14:10:26 +00:00
|
|
|
obj := testutil.GenerateObjectWithCID(cid)
|
2022-05-25 12:56:45 +00:00
|
|
|
obj.SetAttributes(attr)
|
2022-07-12 14:42:55 +00:00
|
|
|
require.NoError(b, metaPut(db, obj, nil))
|
2022-05-25 12:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b.Run("string equal", func(b *testing.B) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("myHeader", strconv.Itoa(objCount/2), objectSDK.MatchStringEqual)
|
|
|
|
benchmarkSelect(b, db, cid, fs, 1)
|
|
|
|
})
|
|
|
|
b.Run("string not equal", func(b *testing.B) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("myHeader", strconv.Itoa(objCount/2), objectSDK.MatchStringNotEqual)
|
|
|
|
benchmarkSelect(b, db, cid, fs, objCount-1)
|
|
|
|
})
|
|
|
|
b.Run("common prefix", func(b *testing.B) {
|
|
|
|
prefix := "99"
|
|
|
|
n := 1 /* 99 */ + 10 /* 990..999 */
|
|
|
|
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("myHeader", prefix, objectSDK.MatchCommonPrefix)
|
|
|
|
benchmarkSelect(b, db, cid, fs, n)
|
|
|
|
})
|
|
|
|
b.Run("unknown", func(b *testing.B) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("myHeader", strconv.Itoa(objCount/2), objectSDK.MatchUnknown)
|
|
|
|
benchmarkSelect(b, db, cid, fs, 0)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-27 18:38:28 +00:00
|
|
|
func TestExpiredObjects(t *testing.T) {
|
2023-05-05 14:02:27 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-07-27 18:38:28 +00:00
|
|
|
db := newDB(t, meta.WithEpochState(epochState{currEpoch}))
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2022-07-27 18:38:28 +00:00
|
|
|
|
|
|
|
checkExpiredObjects(t, db, func(exp, nonExp *objectSDK.Object) {
|
|
|
|
cidExp, _ := exp.ContainerID()
|
|
|
|
cidNonExp, _ := nonExp.ContainerID()
|
|
|
|
|
|
|
|
objs, err := metaSelect(db, cidExp, objectSDK.SearchFilters{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, objs) // expired object should not be returned
|
|
|
|
|
|
|
|
objs, err = metaSelect(db, cidNonExp, objectSDK.SearchFilters{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, objs)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-25 12:56:45 +00:00
|
|
|
func benchmarkSelect(b *testing.B, db *meta.DB, cid cidSDK.ID, fs objectSDK.SearchFilters, expected int) {
|
2022-07-12 14:42:55 +00:00
|
|
|
var prm meta.SelectPrm
|
2022-07-12 14:59:37 +00:00
|
|
|
prm.SetContainerID(cid)
|
|
|
|
prm.SetFilters(fs)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for range b.N {
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err := db.Select(context.Background(), prm)
|
2022-05-25 12:56:45 +00:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
2022-07-12 14:42:55 +00:00
|
|
|
if len(res.AddressList()) != expected {
|
|
|
|
b.Fatalf("expected %d items, got %d", expected, len(res.AddressList()))
|
2022-05-25 12:56:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
func metaSelect(db *meta.DB, cnr cidSDK.ID, fs objectSDK.SearchFilters) ([]oid.Address, error) {
|
|
|
|
var prm meta.SelectPrm
|
2022-07-12 14:59:37 +00:00
|
|
|
prm.SetFilters(fs)
|
|
|
|
prm.SetContainerID(cnr)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err := db.Select(context.Background(), prm)
|
2022-07-12 14:42:55 +00:00
|
|
|
return res.AddressList(), err
|
|
|
|
}
|