2021-02-16 15:56:59 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2021-02-16 15:56:59 +00:00
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
object2 "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"
|
2024-11-07 14:32:10 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
2024-09-20 10:28:21 +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-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"
|
2021-02-16 15:56:59 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB_IterateExpired(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2021-02-16 15:56:59 +00:00
|
|
|
|
|
|
|
const epoch = 13
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
mAlive := map[objectSDK.Type]oid.Address{}
|
|
|
|
mExpired := map[objectSDK.Type]oid.Address{}
|
2021-02-16 15:56:59 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
for _, typ := range []objectSDK.Type{
|
|
|
|
objectSDK.TypeRegular,
|
|
|
|
objectSDK.TypeTombstone,
|
|
|
|
objectSDK.TypeLock,
|
2021-02-16 15:56:59 +00:00
|
|
|
} {
|
|
|
|
mAlive[typ] = putWithExpiration(t, db, typ, epoch)
|
|
|
|
mExpired[typ] = putWithExpiration(t, db, typ, epoch-1)
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
expiredLocked := putWithExpiration(t, db, objectSDK.TypeRegular, epoch-1)
|
2022-02-15 18:22:06 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
require.NoError(t, db.Lock(context.Background(), expiredLocked.Container(), oidtest.ID(), []oid.ID{expiredLocked.Object()}))
|
2022-02-15 18:22:06 +00:00
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err := db.IterateExpired(context.Background(), epoch, func(exp *meta.ExpiredObject) error {
|
2021-02-16 15:56:59 +00:00
|
|
|
if addr, ok := mAlive[exp.Type()]; ok {
|
|
|
|
require.NotEqual(t, addr, exp.Address())
|
|
|
|
}
|
|
|
|
|
2022-02-15 18:22:06 +00:00
|
|
|
require.NotEqual(t, expiredLocked, exp.Address())
|
|
|
|
|
2021-02-16 15:56:59 +00:00
|
|
|
addr, ok := mExpired[exp.Type()]
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, addr, exp.Address())
|
|
|
|
|
|
|
|
delete(mExpired, exp.Type())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Empty(t, mExpired)
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func putWithExpiration(t *testing.T, db *meta.DB, typ objectSDK.Type, expiresAt uint64) oid.Address {
|
2023-03-20 14:10:26 +00:00
|
|
|
obj := testutil.GenerateObject()
|
2022-03-03 14:19:05 +00:00
|
|
|
obj.SetType(typ)
|
2023-03-20 14:10:26 +00:00
|
|
|
testutil.AddAttribute(obj, objectV2.SysAttributeExpEpoch, strconv.FormatUint(expiresAt, 10))
|
2021-02-16 15:56:59 +00:00
|
|
|
|
|
|
|
require.NoError(t, putBig(db, obj))
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
return object2.AddressOf(obj)
|
2021-02-16 15:56:59 +00:00
|
|
|
}
|
2021-02-17 12:22:13 +00:00
|
|
|
|
|
|
|
func TestDB_IterateCoveredByTombstones(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2021-02-17 12:22:13 +00:00
|
|
|
|
2024-09-20 10:28:21 +00:00
|
|
|
cnr := cidtest.ID()
|
2022-05-31 17:00:41 +00:00
|
|
|
ts := oidtest.Address()
|
|
|
|
protected1 := oidtest.Address()
|
|
|
|
protected2 := oidtest.Address()
|
|
|
|
protectedLocked := oidtest.Address()
|
|
|
|
garbage := oidtest.Address()
|
2024-09-20 10:28:21 +00:00
|
|
|
ts.SetContainer(cnr)
|
|
|
|
protected1.SetContainer(cnr)
|
|
|
|
protected2.SetContainer(cnr)
|
|
|
|
protectedLocked.SetContainer(cnr)
|
2021-02-17 12:22:13 +00:00
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var prm meta.InhumePrm
|
2021-02-17 12:22:13 +00:00
|
|
|
var err error
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
prm.SetAddresses(protected1, protected2, protectedLocked)
|
|
|
|
prm.SetTombstoneAddress(ts)
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = db.Inhume(context.Background(), prm)
|
2021-02-17 12:22:13 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
prm.SetAddresses(garbage)
|
|
|
|
prm.SetGCMark()
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = db.Inhume(context.Background(), prm)
|
2022-02-15 18:24:12 +00:00
|
|
|
require.NoError(t, err)
|
2021-02-17 12:22:13 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var handled []oid.Address
|
2021-02-17 12:22:13 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
tss := map[string]oid.Address{
|
|
|
|
ts.EncodeToString(): ts,
|
2021-02-17 12:22:13 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateCoveredByTombstones(context.Background(), tss, func(addr oid.Address) error {
|
2021-02-17 12:22:13 +00:00
|
|
|
handled = append(handled, addr)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-02-15 18:24:12 +00:00
|
|
|
require.Len(t, handled, 3)
|
2021-02-17 12:22:13 +00:00
|
|
|
require.Contains(t, handled, protected1)
|
|
|
|
require.Contains(t, handled, protected2)
|
2022-02-15 18:24:12 +00:00
|
|
|
require.Contains(t, handled, protectedLocked)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
err = db.Lock(context.Background(), protectedLocked.Container(), oidtest.ID(), []oid.ID{protectedLocked.Object()})
|
2022-02-15 18:24:12 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
handled = handled[:0]
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateCoveredByTombstones(context.Background(), tss, func(addr oid.Address) error {
|
2022-02-15 18:24:12 +00:00
|
|
|
handled = append(handled, addr)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, handled, 2)
|
|
|
|
require.NotContains(t, handled, protectedLocked)
|
2021-02-17 12:22:13 +00:00
|
|
|
}
|