2021-02-16 07:57:43 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2021-02-16 07:57:43 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"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-09-20 10:28:21 +00:00
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
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 07:57:43 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-04-15 10:58:10 +00:00
|
|
|
func TestDB_IterateDeletedObjects_EmptyDB(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(t, db.Close(context.Background())) }()
|
2021-04-15 10:58:10 +00:00
|
|
|
|
|
|
|
var counter int
|
2022-05-20 16:48:14 +00:00
|
|
|
var iterGravePRM meta.GraveyardIterationPrm
|
2021-04-15 10:58:10 +00:00
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
iterGravePRM.SetHandler(func(garbage meta.TombstonedObject) error {
|
2021-04-15 10:58:10 +00:00
|
|
|
counter++
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err := db.IterateOverGraveyard(context.Background(), iterGravePRM)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Zero(t, counter)
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var iterGCPRM meta.GarbageIterationPrm
|
|
|
|
iterGCPRM.SetHandler(func(garbage meta.GarbageObject) error {
|
2021-04-15 10:58:10 +00:00
|
|
|
counter++
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGarbage(context.Background(), iterGCPRM)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Zero(t, counter)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDB_Iterate_OffsetNotFound(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(t, db.Close(context.Background())) }()
|
2021-04-15 10:58:10 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
obj1 := testutil.GenerateObject()
|
|
|
|
obj2 := testutil.GenerateObject()
|
2021-04-15 10:58:10 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var addr1 oid.Address
|
|
|
|
err := addr1.DecodeString("AUSF6rhReoAdPVKYUZWW9o2LbtTvekn54B3JXi7pdzmn/2daLhLB7yVXbjBaKkckkuvjX22BxRYuSHy9RPxuH9PZS")
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var addr2 oid.Address
|
|
|
|
err = addr2.DecodeString("CwYYr6sFLU1zK6DeBTVd8SReADUoxYobUhSrxgXYxCVn/ANYbnJoQqdjmU5Dhk3LkxYj5E9nJHQFf8LjTEcap9TxM")
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var addr3 oid.Address
|
|
|
|
err = addr3.DecodeString("6ay4GfhR9RgN28d5ufg63toPetkYHGcpcW7G3b7QWSek/ANYbnJoQqdjmU5Dhk3LkxYj5E9nJHQFf8LjTEcap9TxM")
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
obj1.SetContainerID(addr1.Container())
|
|
|
|
obj1.SetID(addr1.Object())
|
2022-05-12 16:37:46 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
obj2.SetContainerID(addr2.Container())
|
|
|
|
obj2.SetID(addr2.Object())
|
2021-04-15 10:58:10 +00:00
|
|
|
|
|
|
|
err = putBig(db, obj1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var inhumePrm meta.InhumePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(object.AddressOf(obj1))
|
|
|
|
inhumePrm.SetGCMark()
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = db.Inhume(context.Background(), inhumePrm)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var counter int
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var iterGCPRM meta.GarbageIterationPrm
|
|
|
|
iterGCPRM.SetOffset(object.AddressOf(obj2))
|
|
|
|
iterGCPRM.SetHandler(func(garbage meta.GarbageObject) error {
|
2022-05-31 17:00:41 +00:00
|
|
|
require.Equal(t, garbage.Address(), addr1)
|
2021-04-15 10:58:10 +00:00
|
|
|
counter++
|
|
|
|
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGarbage(context.Background(), iterGCPRM)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// the second object would be put after the
|
|
|
|
// first, so it is expected that iteration
|
|
|
|
// will not receive the first object
|
|
|
|
require.Equal(t, 0, counter)
|
|
|
|
|
|
|
|
iterGCPRM.SetOffset(addr3)
|
2022-05-20 16:48:14 +00:00
|
|
|
iterGCPRM.SetHandler(func(garbage meta.GarbageObject) error {
|
2022-05-31 17:00:41 +00:00
|
|
|
require.Equal(t, garbage.Address(), addr1)
|
2021-04-15 10:58:10 +00:00
|
|
|
counter++
|
|
|
|
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGarbage(context.Background(), iterGCPRM)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// the third object would be put before the
|
|
|
|
// first, so it is expected that iteration
|
|
|
|
// will receive the first object
|
|
|
|
require.Equal(t, 1, counter)
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:19:31 +00:00
|
|
|
func TestDB_IterateDeletedObjects(t *testing.T) {
|
2021-02-16 07:57:43 +00:00
|
|
|
db := newDB(t)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(t, db.Close(context.Background())) }()
|
2021-02-16 07:57:43 +00:00
|
|
|
|
2024-09-20 10:28:21 +00:00
|
|
|
cnr := cidtest.ID()
|
2021-04-15 10:58:10 +00:00
|
|
|
// generate and put 4 objects
|
2024-09-20 10:28:21 +00:00
|
|
|
obj1 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
obj2 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
obj3 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
obj4 := testutil.GenerateObjectWithCID(cnr)
|
2021-02-16 07:57:43 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, obj1)
|
2021-02-16 07:57:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, obj2)
|
2021-02-16 07:57:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-08 14:19:31 +00:00
|
|
|
err = putBig(db, obj3)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = putBig(db, obj4)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var inhumePrm meta.InhumePrm
|
2021-02-16 07:57:43 +00:00
|
|
|
|
|
|
|
// inhume with tombstone
|
2022-05-31 17:00:41 +00:00
|
|
|
addrTombstone := oidtest.Address()
|
2024-09-20 10:28:21 +00:00
|
|
|
addrTombstone.SetContainer(cnr)
|
2021-02-16 07:57:43 +00:00
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(object.AddressOf(obj1), object.AddressOf(obj2))
|
|
|
|
inhumePrm.SetTombstoneAddress(addrTombstone)
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = db.Inhume(context.Background(), inhumePrm)
|
2021-02-16 07:57:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(object.AddressOf(obj3), object.AddressOf(obj4))
|
|
|
|
inhumePrm.SetGCMark()
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2021-02-16 07:57:43 +00:00
|
|
|
// inhume with GC mark
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = db.Inhume(context.Background(), inhumePrm)
|
2022-04-26 15:23:24 +00:00
|
|
|
require.NoError(t, err)
|
2021-02-16 07:57:43 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
counterAll int
|
2022-05-31 17:00:41 +00:00
|
|
|
buriedTS, buriedGC []oid.Address
|
2021-02-16 07:57:43 +00:00
|
|
|
)
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var iterGravePRM meta.GraveyardIterationPrm
|
|
|
|
iterGravePRM.SetHandler(func(tomstoned meta.TombstonedObject) error {
|
2022-05-31 17:00:41 +00:00
|
|
|
require.Equal(t, addrTombstone, tomstoned.Tombstone())
|
2021-04-15 10:58:10 +00:00
|
|
|
|
|
|
|
buriedTS = append(buriedTS, tomstoned.Address())
|
2021-04-08 14:19:31 +00:00
|
|
|
counterAll++
|
|
|
|
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
2021-04-15 10:58:10 +00:00
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGraveyard(context.Background(), iterGravePRM)
|
2022-05-20 16:48:14 +00:00
|
|
|
require.NoError(t, err)
|
2021-02-16 07:57:43 +00:00
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var iterGCPRM meta.GarbageIterationPrm
|
|
|
|
iterGCPRM.SetHandler(func(garbage meta.GarbageObject) error {
|
2021-04-15 10:58:10 +00:00
|
|
|
buriedGC = append(buriedGC, garbage.Address())
|
2021-02-16 07:57:43 +00:00
|
|
|
counterAll++
|
|
|
|
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGarbage(context.Background(), iterGCPRM)
|
2021-02-16 07:57:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-08 17:06:13 +00:00
|
|
|
// objects covered with a tombstone
|
|
|
|
// also receive GS mark
|
2022-05-31 17:00:41 +00:00
|
|
|
garbageExpected := []oid.Address{
|
2021-04-08 17:06:13 +00:00
|
|
|
object.AddressOf(obj1), object.AddressOf(obj2),
|
|
|
|
object.AddressOf(obj3), object.AddressOf(obj4),
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
graveyardExpected := []oid.Address{
|
2021-04-08 17:06:13 +00:00
|
|
|
object.AddressOf(obj1), object.AddressOf(obj2),
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, len(garbageExpected)+len(graveyardExpected), counterAll)
|
2022-04-26 15:27:22 +00:00
|
|
|
require.ElementsMatch(t, graveyardExpected, buriedTS)
|
|
|
|
require.ElementsMatch(t, garbageExpected, buriedGC)
|
2021-04-08 14:19:31 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 10:58:10 +00:00
|
|
|
func TestDB_IterateOverGraveyard_Offset(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(t, db.Close(context.Background())) }()
|
2021-04-15 10:58:10 +00:00
|
|
|
|
2024-09-20 10:28:21 +00:00
|
|
|
cnr := cidtest.ID()
|
2021-04-15 10:58:10 +00:00
|
|
|
// generate and put 4 objects
|
2024-09-20 10:28:21 +00:00
|
|
|
obj1 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
obj2 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
obj3 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
obj4 := testutil.GenerateObjectWithCID(cnr)
|
2021-04-15 10:58:10 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
err = putBig(db, obj1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = putBig(db, obj2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = putBig(db, obj3)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = putBig(db, obj4)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// inhume with tombstone
|
2022-05-31 17:00:41 +00:00
|
|
|
addrTombstone := oidtest.Address()
|
2024-09-20 10:28:21 +00:00
|
|
|
addrTombstone.SetContainer(cnr)
|
2021-04-15 10:58:10 +00:00
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var inhumePrm meta.InhumePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(
|
2022-05-20 16:48:14 +00:00
|
|
|
object.AddressOf(obj1), object.AddressOf(obj2),
|
|
|
|
object.AddressOf(obj3), object.AddressOf(obj4))
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetTombstoneAddress(addrTombstone)
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = db.Inhume(context.Background(), inhumePrm)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
expectedGraveyard := []oid.Address{
|
2021-04-15 10:58:10 +00:00
|
|
|
object.AddressOf(obj1), object.AddressOf(obj2),
|
|
|
|
object.AddressOf(obj3), object.AddressOf(obj4),
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
counter int
|
|
|
|
firstIterationSize = len(expectedGraveyard) / 2
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
gotGraveyard []oid.Address
|
2021-04-15 10:58:10 +00:00
|
|
|
)
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var iterGraveyardPrm meta.GraveyardIterationPrm
|
|
|
|
iterGraveyardPrm.SetHandler(func(tombstoned meta.TombstonedObject) error {
|
2022-05-31 17:00:41 +00:00
|
|
|
require.Equal(t, addrTombstone, tombstoned.Tombstone())
|
2021-04-15 10:58:10 +00:00
|
|
|
|
|
|
|
gotGraveyard = append(gotGraveyard, tombstoned.Address())
|
|
|
|
|
|
|
|
counter++
|
|
|
|
if counter == firstIterationSize {
|
|
|
|
return meta.ErrInterruptIterator
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGraveyard(context.Background(), iterGraveyardPrm)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, firstIterationSize, counter)
|
|
|
|
require.Equal(t, firstIterationSize, len(gotGraveyard))
|
|
|
|
|
|
|
|
// last received address is an offset
|
|
|
|
offset := gotGraveyard[len(gotGraveyard)-1]
|
|
|
|
iterGraveyardPrm.SetOffset(offset)
|
2022-05-20 16:48:14 +00:00
|
|
|
iterGraveyardPrm.SetHandler(func(tombstoned meta.TombstonedObject) error {
|
2022-05-31 17:00:41 +00:00
|
|
|
require.Equal(t, addrTombstone, tombstoned.Tombstone())
|
2021-04-15 10:58:10 +00:00
|
|
|
|
|
|
|
gotGraveyard = append(gotGraveyard, tombstoned.Address())
|
|
|
|
counter++
|
|
|
|
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGraveyard(context.Background(), iterGraveyardPrm)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, len(expectedGraveyard), counter)
|
2022-04-26 15:27:22 +00:00
|
|
|
require.ElementsMatch(t, gotGraveyard, expectedGraveyard)
|
2021-04-15 10:58:10 +00:00
|
|
|
|
|
|
|
// last received object (last in db) as offset
|
|
|
|
// should lead to no iteration at all
|
|
|
|
offset = gotGraveyard[len(gotGraveyard)-1]
|
|
|
|
iterGraveyardPrm.SetOffset(offset)
|
|
|
|
iWasCalled := false
|
2022-05-20 16:48:14 +00:00
|
|
|
iterGraveyardPrm.SetHandler(func(tombstoned meta.TombstonedObject) error {
|
2021-04-15 10:58:10 +00:00
|
|
|
iWasCalled = true
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGraveyard(context.Background(), iterGraveyardPrm)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, iWasCalled)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDB_IterateOverGarbage_Offset(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(t, db.Close(context.Background())) }()
|
2021-04-15 10:58:10 +00:00
|
|
|
|
|
|
|
// generate and put 4 objects
|
2023-03-20 14:10:26 +00:00
|
|
|
obj1 := testutil.GenerateObject()
|
|
|
|
obj2 := testutil.GenerateObject()
|
|
|
|
obj3 := testutil.GenerateObject()
|
|
|
|
obj4 := testutil.GenerateObject()
|
2021-04-15 10:58:10 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
err = putBig(db, obj1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = putBig(db, obj2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = putBig(db, obj3)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = putBig(db, obj4)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var inhumePrm meta.InhumePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(
|
2022-05-20 16:48:14 +00:00
|
|
|
object.AddressOf(obj1), object.AddressOf(obj2),
|
|
|
|
object.AddressOf(obj3), object.AddressOf(obj4))
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetGCMark()
|
2021-04-15 10:58:10 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = db.Inhume(context.Background(), inhumePrm)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
expectedGarbage := []oid.Address{
|
2021-04-15 10:58:10 +00:00
|
|
|
object.AddressOf(obj1), object.AddressOf(obj2),
|
|
|
|
object.AddressOf(obj3), object.AddressOf(obj4),
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
counter int
|
|
|
|
firstIterationSize = len(expectedGarbage) / 2
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
gotGarbage []oid.Address
|
2021-04-15 10:58:10 +00:00
|
|
|
)
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var iterGarbagePrm meta.GarbageIterationPrm
|
|
|
|
iterGarbagePrm.SetHandler(func(garbage meta.GarbageObject) error {
|
2021-04-15 10:58:10 +00:00
|
|
|
gotGarbage = append(gotGarbage, garbage.Address())
|
|
|
|
|
|
|
|
counter++
|
|
|
|
if counter == firstIterationSize {
|
|
|
|
return meta.ErrInterruptIterator
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGarbage(context.Background(), iterGarbagePrm)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, firstIterationSize, counter)
|
|
|
|
require.Equal(t, firstIterationSize, len(gotGarbage))
|
|
|
|
|
|
|
|
// last received address is an offset
|
|
|
|
offset := gotGarbage[len(gotGarbage)-1]
|
|
|
|
iterGarbagePrm.SetOffset(offset)
|
2022-05-20 16:48:14 +00:00
|
|
|
iterGarbagePrm.SetHandler(func(garbage meta.GarbageObject) error {
|
2021-04-15 10:58:10 +00:00
|
|
|
gotGarbage = append(gotGarbage, garbage.Address())
|
|
|
|
counter++
|
|
|
|
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGarbage(context.Background(), iterGarbagePrm)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, len(expectedGarbage), counter)
|
2022-04-26 15:27:22 +00:00
|
|
|
require.ElementsMatch(t, gotGarbage, expectedGarbage)
|
2021-04-15 10:58:10 +00:00
|
|
|
|
|
|
|
// last received object (last in db) as offset
|
|
|
|
// should lead to no iteration at all
|
|
|
|
offset = gotGarbage[len(gotGarbage)-1]
|
|
|
|
iterGarbagePrm.SetOffset(offset)
|
|
|
|
iWasCalled := false
|
2022-05-20 16:48:14 +00:00
|
|
|
iterGarbagePrm.SetHandler(func(garbage meta.GarbageObject) error {
|
2021-04-15 10:58:10 +00:00
|
|
|
iWasCalled = true
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGarbage(context.Background(), iterGarbagePrm)
|
2021-04-15 10:58:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, iWasCalled)
|
|
|
|
}
|
|
|
|
|
2022-04-18 18:13:35 +00:00
|
|
|
func TestDB_DropGraves(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2024-10-21 13:27:28 +00:00
|
|
|
defer func() { require.NoError(t, db.Close(context.Background())) }()
|
2022-04-18 18:13:35 +00:00
|
|
|
|
2024-09-20 10:28:21 +00:00
|
|
|
cnr := cidtest.ID()
|
2022-04-18 18:13:35 +00:00
|
|
|
// generate and put 2 objects
|
2024-09-20 10:28:21 +00:00
|
|
|
obj1 := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
obj2 := testutil.GenerateObjectWithCID(cnr)
|
2022-04-18 18:13:35 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
err = putBig(db, obj1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = putBig(db, obj2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// inhume with tombstone
|
2022-05-31 17:00:41 +00:00
|
|
|
addrTombstone := oidtest.Address()
|
2024-09-20 10:28:21 +00:00
|
|
|
addrTombstone.SetContainer(cnr)
|
2022-04-18 18:13:35 +00:00
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var inhumePrm meta.InhumePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(object.AddressOf(obj1), object.AddressOf(obj2))
|
|
|
|
inhumePrm.SetTombstoneAddress(addrTombstone)
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = db.Inhume(context.Background(), inhumePrm)
|
2022-04-18 18:13:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
buriedTS := make([]meta.TombstonedObject, 0)
|
2022-05-20 16:48:14 +00:00
|
|
|
var iterGravePRM meta.GraveyardIterationPrm
|
2022-04-18 18:13:35 +00:00
|
|
|
var counter int
|
2022-05-20 16:48:14 +00:00
|
|
|
iterGravePRM.SetHandler(func(tomstoned meta.TombstonedObject) error {
|
2022-04-18 18:13:35 +00:00
|
|
|
buriedTS = append(buriedTS, tomstoned)
|
|
|
|
counter++
|
|
|
|
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGraveyard(context.Background(), iterGravePRM)
|
2022-04-18 18:13:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, counter)
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.DropGraves(context.Background(), buriedTS)
|
2022-04-18 18:13:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
counter = 0
|
2022-05-20 16:48:14 +00:00
|
|
|
iterGravePRM.SetHandler(func(_ meta.TombstonedObject) error {
|
2022-04-18 18:13:35 +00:00
|
|
|
counter++
|
|
|
|
return nil
|
2022-05-20 16:48:14 +00:00
|
|
|
})
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
err = db.IterateOverGraveyard(context.Background(), iterGravePRM)
|
2022-04-18 18:13:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Zero(t, counter)
|
|
|
|
}
|