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
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
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"
|
|
|
|
"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"
|
2021-02-16 15:56:59 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB_IterateExpired(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
|
|
|
const epoch = 13
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
mAlive := map[object.Type]oid.Address{}
|
|
|
|
mExpired := map[object.Type]oid.Address{}
|
2021-02-16 15:56:59 +00:00
|
|
|
|
|
|
|
for _, typ := range []object.Type{
|
|
|
|
object.TypeRegular,
|
|
|
|
object.TypeTombstone,
|
2022-02-15 12:51:56 +00:00
|
|
|
object.TypeLock,
|
2021-02-16 15:56:59 +00:00
|
|
|
} {
|
|
|
|
mAlive[typ] = putWithExpiration(t, db, typ, epoch)
|
|
|
|
mExpired[typ] = putWithExpiration(t, db, typ, epoch-1)
|
|
|
|
}
|
|
|
|
|
2022-02-15 18:22:06 +00:00
|
|
|
expiredLocked := putWithExpiration(t, db, object.TypeRegular, epoch-1)
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func putWithExpiration(t *testing.T, db *meta.DB, typ object.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)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
ts := oidtest.Address()
|
|
|
|
protected1 := oidtest.Address()
|
|
|
|
protected2 := oidtest.Address()
|
|
|
|
protectedLocked := oidtest.Address()
|
|
|
|
garbage := oidtest.Address()
|
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
|
|
|
}
|