2020-11-23 13:30:56 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2020-11-23 13:30:56 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-12-01 10:48:28 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2022-02-15 22:16:07 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
|
|
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test"
|
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
|
|
oidtest "github.com/nspcc-dev/neofs-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")
|
|
|
|
|
|
|
|
tombstoneID := generateAddress()
|
|
|
|
|
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-03-03 14:19:05 +00:00
|
|
|
err = meta.Inhume(db, object.AddressOf(raw), tombstoneID)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
_, err = meta.Exists(db, object.AddressOf(raw))
|
2020-12-01 10:48:28 +00:00
|
|
|
require.EqualError(t, err, object.ErrAlreadyRemoved.Error())
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
_, err = meta.Get(db, object.AddressOf(raw))
|
2020-12-01 10:48:28 +00:00
|
|
|
require.EqualError(t, err, object.ErrAlreadyRemoved.Error())
|
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
|
|
|
|
|
|
|
|
addr1 = generateAddress()
|
|
|
|
addr2 = generateAddress()
|
|
|
|
addr3 = generateAddress()
|
|
|
|
inhumePrm = new(meta.InhumePrm)
|
|
|
|
existsPrm = new(meta.ExistsPrm)
|
|
|
|
)
|
|
|
|
|
|
|
|
// inhume addr1 via addr2
|
|
|
|
_, err = db.Inhume(inhumePrm.
|
|
|
|
WithAddresses(addr1).
|
|
|
|
WithTombstoneAddress(addr2),
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// addr1 should become inhumed {addr1:addr2}
|
|
|
|
_, err = db.Exists(existsPrm.WithAddress(addr1))
|
|
|
|
require.True(t, errors.Is(err, object.ErrAlreadyRemoved))
|
|
|
|
|
|
|
|
// try to inhume addr3 via addr1
|
|
|
|
_, err = db.Inhume(inhumePrm.
|
|
|
|
WithAddresses(addr3).
|
|
|
|
WithTombstoneAddress(addr1),
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// record with {addr1:addr2} should be removed from graveyard
|
|
|
|
// as a tomb-on-tomb
|
|
|
|
res, err := db.Exists(existsPrm.WithAddress(addr1))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, res.Exists())
|
|
|
|
|
|
|
|
// addr3 should be inhumed {addr3: addr1}
|
|
|
|
_, err = db.Exists(existsPrm.WithAddress(addr3))
|
|
|
|
require.True(t, errors.Is(err, object.ErrAlreadyRemoved))
|
|
|
|
|
|
|
|
// try to inhume addr1 (which is already a tombstone in graveyard)
|
|
|
|
_, err = db.Inhume(inhumePrm.
|
|
|
|
WithAddresses(addr1).
|
|
|
|
WithTombstoneAddress(generateAddress()),
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// record with addr1 key should not appear in graveyard
|
|
|
|
// (tomb can not be inhumed)
|
|
|
|
res, err = db.Exists(existsPrm.WithAddress(addr1))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, res.Exists())
|
|
|
|
}
|
2022-02-15 22:16:07 +00:00
|
|
|
|
|
|
|
func TestInhumeLocked(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
|
|
|
locked := *objecttest.Address()
|
|
|
|
|
|
|
|
err := db.Lock(*locked.ContainerID(), *oidtest.ID(), []oid.ID{*locked.ObjectID()})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var prm meta.InhumePrm
|
|
|
|
prm.WithAddresses(&locked)
|
|
|
|
|
|
|
|
_, err = db.Inhume(&prm)
|
|
|
|
|
|
|
|
var e apistatus.ObjectLocked
|
|
|
|
require.ErrorAs(t, err, &e)
|
|
|
|
}
|