[#73] pool/tree: Fix index in retry loop

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2023-06-28 13:06:23 +03:00
parent c243b443bc
commit 91e80ba743
2 changed files with 11 additions and 4 deletions

View file

@ -725,7 +725,7 @@ func (p *Pool) requestWithRetry(fn func(client grpcService.TreeServiceClient) er
groupsLen := len(p.innerPools) groupsLen := len(p.innerPools)
for i := startI; i < startI+groupsLen; i++ { for i := startI; i < startI+groupsLen; i++ {
indexI := i % groupsLen indexI := i % groupsLen
clientsLen := len(p.innerPools[i].clients) clientsLen := len(p.innerPools[indexI].clients)
for j := startJ; j < startJ+clientsLen; j++ { for j := startJ; j < startJ+clientsLen; j++ {
indexJ := j % clientsLen indexJ := j % clientsLen
if cl, err = p.innerPools[indexI].clients[indexJ].serviceClient(); err == nil { if cl, err = p.innerPools[indexI].clients[indexJ].serviceClient(); err == nil {

View file

@ -3,10 +3,10 @@ package tree
import ( import (
"context" "context"
"errors" "errors"
grpcService "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool/tree/service"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
grpcService "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool/tree/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
) )
@ -148,6 +148,14 @@ func TestRetry(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
checkIndicesAndReset(t, p, 1, 0) checkIndicesAndReset(t, p, 1, 0)
}) })
t.Run("no panic group switch", func(t *testing.T) {
setErrors(p, nodes[1]...)
p.setStartIndices(1, 0)
err := p.requestWithRetry(makeFn)
require.NoError(t, err)
checkIndicesAndReset(t, p, 0, 0)
})
} }
func TestRebalance(t *testing.T) { func TestRebalance(t *testing.T) {
@ -246,8 +254,7 @@ func checkIndicesAndReset(t *testing.T, p *Pool, iExp, jExp int) {
func checkIndices(t *testing.T, p *Pool, iExp, jExp int) { func checkIndices(t *testing.T, p *Pool, iExp, jExp int) {
i, j := p.getStartIndices() i, j := p.getStartIndices()
require.Equal(t, iExp, i) require.Equal(t, [2]int{iExp, jExp}, [2]int{i, j})
require.Equal(t, jExp, j)
} }
func resetClients(p *Pool) { func resetClients(p *Pool) {