2021-02-16 07:57:43 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2021-02-16 07:57:43 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2021-02-16 07:57:43 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
// generate and put 2 objects
|
2022-03-03 14:19:05 +00:00
|
|
|
obj1 := generateObject(t)
|
|
|
|
obj2 := generateObject(t)
|
2021-04-08 14:19:31 +00:00
|
|
|
obj3 := generateObject(t)
|
|
|
|
obj4 := generateObject(t)
|
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)
|
|
|
|
|
2021-02-16 07:57:43 +00:00
|
|
|
inhumePrm := new(meta.InhumePrm)
|
|
|
|
|
|
|
|
// inhume with tombstone
|
|
|
|
addrTombstone := generateAddress()
|
|
|
|
|
|
|
|
_, err = db.Inhume(inhumePrm.
|
2021-04-08 14:19:31 +00:00
|
|
|
WithAddresses(object.AddressOf(obj1), object.AddressOf(obj2)).
|
2021-02-16 07:57:43 +00:00
|
|
|
WithTombstoneAddress(addrTombstone),
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// inhume with GC mark
|
|
|
|
_, err = db.Inhume(inhumePrm.
|
2021-04-08 14:19:31 +00:00
|
|
|
WithAddresses(object.AddressOf(obj3), object.AddressOf(obj4)).
|
2021-02-16 07:57:43 +00:00
|
|
|
WithGCMark(),
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
counterAll int
|
2022-01-26 12:11:13 +00:00
|
|
|
buriedTS, buriedGC []*addressSDK.Address
|
2021-02-16 07:57:43 +00:00
|
|
|
)
|
|
|
|
|
2021-04-08 14:19:31 +00:00
|
|
|
err = db.IterateOverGraveyard(func(deletedObject *meta.DeletedObject) error {
|
|
|
|
buriedTS = append(buriedTS, deletedObject.Address())
|
|
|
|
counterAll++
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2021-02-16 07:57:43 +00:00
|
|
|
|
2021-04-08 14:19:31 +00:00
|
|
|
err = db.IterateOverGarbage(func(deletedObject *meta.DeletedObject) error {
|
|
|
|
buriedGC = append(buriedGC, deletedObject.Address())
|
2021-02-16 07:57:43 +00:00
|
|
|
counterAll++
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-08 17:06:13 +00:00
|
|
|
// objects covered with a tombstone
|
|
|
|
// also receive GS mark
|
|
|
|
garbageExpected := []*addressSDK.Address{
|
|
|
|
object.AddressOf(obj1), object.AddressOf(obj2),
|
|
|
|
object.AddressOf(obj3), object.AddressOf(obj4),
|
|
|
|
}
|
|
|
|
|
|
|
|
graveyardExpected := []*addressSDK.Address{
|
|
|
|
object.AddressOf(obj1), object.AddressOf(obj2),
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, len(garbageExpected)+len(graveyardExpected), counterAll)
|
|
|
|
require.True(t, equalAddresses(graveyardExpected, buriedTS))
|
|
|
|
require.True(t, equalAddresses(garbageExpected, buriedGC))
|
2021-04-08 14:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func equalAddresses(aa1 []*addressSDK.Address, aa2 []*addressSDK.Address) bool {
|
|
|
|
if len(aa1) != len(aa2) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, a1 := range aa1 {
|
|
|
|
found := false
|
|
|
|
|
|
|
|
for _, a2 := range aa2 {
|
|
|
|
if a1.String() == a2.String() {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
2021-02-16 07:57:43 +00:00
|
|
|
}
|