frostfs-node/pkg/local_object_storage/metabase/control_test.go
Leonard Lyubich 55c94a0152 [#789] metabase: Implement Reset method
In the previous implementation of the metabase, there was no possibility of
reinitializing the metabase: clearing information about existing objects and
bringing it back to its initial state. This operation can be useful in
cases when the stored metadata about objects has lost (or possibly lost)
relevance, and you need to generate data from scratch. Also at the
initialization stage, static resources of the base were not created -
container-independent buckets.

Make `Metabase.Init` method to allocate graveyard, container-size and
to-move-it buckets in underlying BoltDB instance. Implement `Metabase.Reset`
method: it works like `Init` but clean up all static buckets and removes
other ones. Due to the logical similarity, the methods share a single piece
of code.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-09-15 18:22:09 +03:00

47 lines
1.1 KiB
Go

package meta_test
import (
"testing"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
"github.com/stretchr/testify/require"
)
func TestReset(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
err := db.Reset()
require.NoError(t, err)
obj := generateRawObject(t).Object()
addr := obj.Address()
addrToInhume := generateAddress()
assertExists := func(addr *objectSDK.Address, expExists bool, expErr error) {
exists, err := meta.Exists(db, addr)
require.ErrorIs(t, err, expErr)
require.Equal(t, expExists, exists)
}
assertExists(addr, false, nil)
assertExists(addrToInhume, false, nil)
err = putBig(db, obj)
require.NoError(t, err)
err = meta.Inhume(db, addrToInhume, generateAddress())
require.NoError(t, err)
assertExists(addr, true, nil)
assertExists(addrToInhume, false, object.ErrAlreadyRemoved)
err = db.Reset()
require.NoError(t, err)
assertExists(addr, false, nil)
assertExists(addr, false, nil)
}