forked from TrueCloudLab/frostfs-node
[#1356] engine: Evacuate object from shards concurrently
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
bdf386366c
commit
34e6a309c6
8 changed files with 533 additions and 111 deletions
|
@ -6,6 +6,8 @@ import (
|
|||
"fmt"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -174,13 +176,13 @@ func TestEvacuateObjectsNetwork(t *testing.T) {
|
|||
errReplication := errors.New("handler error")
|
||||
|
||||
acceptOneOf := func(objects []*objectSDK.Object, max uint64) func(context.Context, oid.Address, *objectSDK.Object) (bool, error) {
|
||||
var n uint64
|
||||
var n atomic.Uint64
|
||||
return func(_ context.Context, addr oid.Address, obj *objectSDK.Object) (bool, error) {
|
||||
if n == max {
|
||||
if n.Load() == max {
|
||||
return false, errReplication
|
||||
}
|
||||
|
||||
n++
|
||||
n.Add(1)
|
||||
for i := range objects {
|
||||
if addr == objectCore.AddressOf(objects[i]) {
|
||||
require.Equal(t, objects[i], obj)
|
||||
|
@ -314,6 +316,36 @@ func TestEvacuateCancellation(t *testing.T) {
|
|||
require.Equal(t, uint64(0), res.ObjectsEvacuated())
|
||||
}
|
||||
|
||||
func TestEvacuateCancellationByError(t *testing.T) {
|
||||
t.Parallel()
|
||||
e, ids, _ := newEngineEvacuate(t, 2, 10)
|
||||
defer func() {
|
||||
require.NoError(t, e.Close(context.Background()))
|
||||
}()
|
||||
|
||||
require.NoError(t, e.shards[ids[0].String()].SetMode(mode.ReadOnly))
|
||||
require.NoError(t, e.shards[ids[1].String()].SetMode(mode.ReadOnly))
|
||||
|
||||
var prm EvacuateShardPrm
|
||||
prm.ShardID = ids[1:2]
|
||||
var once atomic.Bool
|
||||
prm.ObjectsHandler = func(ctx context.Context, a oid.Address, o *objectSDK.Object) (bool, error) {
|
||||
var err error
|
||||
flag := true
|
||||
if once.CompareAndSwap(false, true) {
|
||||
err = errors.New("test error")
|
||||
flag = false
|
||||
}
|
||||
return flag, err
|
||||
}
|
||||
prm.Scope = EvacuateScopeObjects
|
||||
prm.ObjectWorkerCount = 2
|
||||
prm.ContainerWorkerCount = 2
|
||||
|
||||
_, err := e.Evacuate(context.Background(), prm)
|
||||
require.ErrorContains(t, err, "test error")
|
||||
}
|
||||
|
||||
func TestEvacuateSingleProcess(t *testing.T) {
|
||||
e, ids, _ := newEngineEvacuate(t, 2, 3)
|
||||
defer func() {
|
||||
|
@ -531,6 +563,7 @@ func TestEvacuateTreesRemote(t *testing.T) {
|
|||
require.NoError(t, e.shards[ids[0].String()].SetMode(mode.ReadOnly))
|
||||
require.NoError(t, e.shards[ids[1].String()].SetMode(mode.ReadOnly))
|
||||
|
||||
mutex := sync.Mutex{}
|
||||
evacuatedTreeOps := make(map[string][]*pilorama.Move)
|
||||
var prm EvacuateShardPrm
|
||||
prm.ShardID = ids
|
||||
|
@ -545,7 +578,9 @@ func TestEvacuateTreesRemote(t *testing.T) {
|
|||
if op.Time == 0 {
|
||||
return true, "", nil
|
||||
}
|
||||
mutex.Lock()
|
||||
evacuatedTreeOps[key] = append(evacuatedTreeOps[key], &op)
|
||||
mutex.Unlock()
|
||||
height = op.Time + 1
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue