2020-11-23 13:30:56 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
2020-11-23 13:30:56 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB_Inhume(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw := generateObject(t)
|
2020-11-23 13:30:56 +00:00
|
|
|
addAttribute(raw, "foo", "bar")
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
tombstoneID := oidtest.Address()
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaInhume(db, object.AddressOf(raw), tombstoneID)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
_, err = metaExists(db, object.AddressOf(raw))
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
_, err = metaGet(db, object.AddressOf(raw), false)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|
2021-02-19 09:49:23 +00:00
|
|
|
|
|
|
|
func TestInhumeTombOnTomb(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addr1 = oidtest.Address()
|
|
|
|
addr2 = oidtest.Address()
|
|
|
|
addr3 = oidtest.Address()
|
2022-05-20 16:48:14 +00:00
|
|
|
inhumePrm meta.InhumePrm
|
|
|
|
existsPrm meta.ExistsPrm
|
2021-02-19 09:49:23 +00:00
|
|
|
)
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(addr1)
|
|
|
|
inhumePrm.SetTombstoneAddress(addr2)
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2021-02-19 09:49:23 +00:00
|
|
|
// inhume addr1 via addr2
|
2022-05-20 16:48:14 +00:00
|
|
|
_, err = db.Inhume(inhumePrm)
|
2021-02-19 09:49:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
existsPrm.SetAddress(addr1)
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2021-02-19 09:49:23 +00:00
|
|
|
// addr1 should become inhumed {addr1:addr2}
|
2022-05-20 16:48:14 +00:00
|
|
|
_, err = db.Exists(existsPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))
|
2021-02-19 09:49:23 +00:00
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(addr3)
|
|
|
|
inhumePrm.SetTombstoneAddress(addr1)
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2021-02-19 09:49:23 +00:00
|
|
|
// try to inhume addr3 via addr1
|
2022-05-20 16:48:14 +00:00
|
|
|
_, err = db.Inhume(inhumePrm)
|
2021-02-19 09:49:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// record with {addr1:addr2} should be removed from graveyard
|
2021-04-08 17:06:13 +00:00
|
|
|
// as a tomb-on-tomb; metabase should return ObjectNotFound
|
|
|
|
// NOT ObjectAlreadyRemoved since that record has been removed
|
|
|
|
// from graveyard but addr1 is still marked with GC
|
2022-05-20 16:48:14 +00:00
|
|
|
_, err = db.Exists(existsPrm)
|
2021-04-08 17:06:13 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2021-02-19 09:49:23 +00:00
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
existsPrm.SetAddress(addr3)
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2021-02-19 09:49:23 +00:00
|
|
|
// addr3 should be inhumed {addr3: addr1}
|
2022-05-20 16:48:14 +00:00
|
|
|
_, err = db.Exists(existsPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))
|
2021-02-19 09:49:23 +00:00
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(addr1)
|
|
|
|
inhumePrm.SetTombstoneAddress(oidtest.Address())
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2021-02-19 09:49:23 +00:00
|
|
|
// try to inhume addr1 (which is already a tombstone in graveyard)
|
2022-05-20 16:48:14 +00:00
|
|
|
_, err = db.Inhume(inhumePrm)
|
2021-02-19 09:49:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
existsPrm.SetAddress(addr1)
|
2022-05-20 16:48:14 +00:00
|
|
|
|
2021-02-19 09:49:23 +00:00
|
|
|
// record with addr1 key should not appear in graveyard
|
2021-04-08 17:06:13 +00:00
|
|
|
// (tomb can not be inhumed) but should be kept as object
|
|
|
|
// with GC mark
|
2022-05-20 16:48:14 +00:00
|
|
|
_, err = db.Exists(existsPrm)
|
2021-04-08 17:06:13 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2021-02-19 09:49:23 +00:00
|
|
|
}
|
2022-02-15 22:16:07 +00:00
|
|
|
|
|
|
|
func TestInhumeLocked(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
locked := oidtest.Address()
|
2022-02-15 22:16:07 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
err := db.Lock(locked.Container(), oidtest.ID(), []oid.ID{locked.Object()})
|
2022-02-15 22:16:07 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var prm meta.InhumePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
prm.SetAddresses(locked)
|
2022-02-15 22:16:07 +00:00
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
_, err = db.Inhume(prm)
|
2022-02-15 22:16:07 +00:00
|
|
|
|
|
|
|
var e apistatus.ObjectLocked
|
|
|
|
require.ErrorAs(t, err, &e)
|
|
|
|
}
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
func metaInhume(db *meta.DB, target, tomb oid.Address) error {
|
|
|
|
var inhumePrm meta.InhumePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
inhumePrm.SetAddresses(target)
|
|
|
|
inhumePrm.SetTombstoneAddress(tomb)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
_, err := db.Inhume(inhumePrm)
|
|
|
|
return err
|
|
|
|
}
|