2020-11-23 13:30:56 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2020-11-23 13:30:56 +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"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-11-23 13:30:56 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB_Movable(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
raw1 := testutil.GenerateObject()
|
|
|
|
raw2 := testutil.GenerateObject()
|
2020-11-23 13:30:56 +00:00
|
|
|
|
|
|
|
// put two objects in metabase
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index empty
|
2022-07-12 14:42:55 +00:00
|
|
|
toMoveList, err := metaMovable(db)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 0)
|
|
|
|
|
|
|
|
// mark to move object2
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaToMoveIt(db, object.AddressOf(raw2))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index contains address of object 2
|
2022-07-12 14:42:55 +00:00
|
|
|
toMoveList, err = metaMovable(db)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 1)
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Contains(t, toMoveList, object.AddressOf(raw2))
|
2020-11-23 13:30:56 +00:00
|
|
|
|
|
|
|
// remove from toMoveIt index non existing address
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaDoNotMove(db, object.AddressOf(raw1))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index hasn't changed
|
2022-07-12 14:42:55 +00:00
|
|
|
toMoveList, err = metaMovable(db)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 1)
|
|
|
|
|
|
|
|
// remove from toMoveIt index existing address
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaDoNotMove(db, object.AddressOf(raw2))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index is empty now
|
2022-07-12 14:42:55 +00:00
|
|
|
toMoveList, err = metaMovable(db)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 0)
|
|
|
|
}
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
func metaToMoveIt(db *meta.DB, addr oid.Address) error {
|
|
|
|
var toMovePrm meta.ToMoveItPrm
|
2022-07-12 14:59:37 +00:00
|
|
|
toMovePrm.SetAddress(addr)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := db.ToMoveIt(context.Background(), toMovePrm)
|
2022-07-12 14:42:55 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func metaMovable(db *meta.DB) ([]oid.Address, error) {
|
|
|
|
r, err := db.Movable(meta.MovablePrm{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.AddressList(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func metaDoNotMove(db *meta.DB, addr oid.Address) error {
|
|
|
|
var doNotMovePrm meta.DoNotMovePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
doNotMovePrm.SetAddress(addr)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
_, err := db.DoNotMove(doNotMovePrm)
|
|
|
|
return err
|
|
|
|
}
|