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"
|
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-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(t, db.Close(context.Background())) }()
|
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
|
|
|
}
|