[#31] placement: Fix confused selectors and replicas
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
f7c685f682
commit
73ee5105ff
2 changed files with 31 additions and 31 deletions
|
@ -77,14 +77,14 @@ func NewTraverser(opts ...Option) (*Traverser, error) {
|
||||||
return nil, errors.Wrap(err, "could not build placement")
|
return nil, errors.Wrap(err, "could not build placement")
|
||||||
}
|
}
|
||||||
|
|
||||||
ss := cfg.policy.GetSelectors()
|
rs := cfg.policy.GetReplicas()
|
||||||
rem := make([]int, 0, len(ss))
|
rem := make([]int, 0, len(rs))
|
||||||
|
|
||||||
for i := range ss {
|
for i := range rs {
|
||||||
cnt := cfg.rem
|
cnt := cfg.rem
|
||||||
|
|
||||||
if cnt == 0 {
|
if cnt == 0 {
|
||||||
cnt = int(ss[i].GetCount())
|
cnt = int(rs[i].GetCount())
|
||||||
}
|
}
|
||||||
|
|
||||||
rem = append(rem, cnt)
|
rem = append(rem, cnt)
|
||||||
|
|
|
@ -49,39 +49,39 @@ func copyVectors(v []netmap.Nodes) []netmap.Nodes {
|
||||||
return vc
|
return vc
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPlacement(t *testing.T, rs, ss []int) ([]netmap.Nodes, *container.Container) {
|
func testPlacement(t *testing.T, ss, rs []int) ([]netmap.Nodes, *container.Container) {
|
||||||
nodes := make([]netmap.Nodes, 0, len(rs))
|
nodes := make([]netmap.Nodes, 0, len(rs))
|
||||||
selectors := make([]*netmap.Selector, 0, len(rs))
|
replicas := make([]*netmap.Replica, 0, len(rs))
|
||||||
num := uint32(0)
|
num := uint32(0)
|
||||||
|
|
||||||
for i := range rs {
|
for i := range ss {
|
||||||
ns := make([]netmapV2.NodeInfo, 0, rs[i])
|
ns := make([]netmapV2.NodeInfo, 0, ss[i])
|
||||||
|
|
||||||
for j := 0; j < rs[i]; j++ {
|
for j := 0; j < ss[i]; j++ {
|
||||||
ns = append(ns, testNode(num))
|
ns = append(ns, testNode(num))
|
||||||
num++
|
num++
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes = append(nodes, netmap.NodesFromV2(ns))
|
nodes = append(nodes, netmap.NodesFromV2(ns))
|
||||||
|
|
||||||
s := new(netmap.Selector)
|
s := new(netmap.Replica)
|
||||||
s.SetCount(uint32(ss[i]))
|
s.SetCount(uint32(rs[i]))
|
||||||
|
|
||||||
selectors = append(selectors, s)
|
replicas = append(replicas, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
policy := new(netmap.PlacementPolicy)
|
policy := new(netmap.PlacementPolicy)
|
||||||
policy.SetSelectors(selectors)
|
policy.SetReplicas(replicas)
|
||||||
|
|
||||||
return nodes, container.New(container.WithPolicy(policy))
|
return nodes, container.New(container.WithPolicy(policy))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTraverserObjectScenarios(t *testing.T) {
|
func TestTraverserObjectScenarios(t *testing.T) {
|
||||||
t.Run("search scenario", func(t *testing.T) {
|
t.Run("search scenario", func(t *testing.T) {
|
||||||
replicas := []int{2, 3}
|
selectors := []int{2, 3}
|
||||||
selectors := []int{1, 2}
|
replicas := []int{1, 2}
|
||||||
|
|
||||||
nodes, cnr := testPlacement(t, replicas, selectors)
|
nodes, cnr := testPlacement(t, selectors, replicas)
|
||||||
|
|
||||||
nodesCopy := copyVectors(nodes)
|
nodesCopy := copyVectors(nodes)
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for i := range replicas {
|
for i := range selectors {
|
||||||
addrs := tr.Next()
|
addrs := tr.Next()
|
||||||
|
|
||||||
require.Len(t, addrs, len(nodes[i]))
|
require.Len(t, addrs, len(nodes[i]))
|
||||||
|
@ -107,10 +107,10 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("read scenario", func(t *testing.T) {
|
t.Run("read scenario", func(t *testing.T) {
|
||||||
replicas := []int{5, 3}
|
selectors := []int{5, 3}
|
||||||
selectors := []int{2, 2}
|
replicas := []int{2, 2}
|
||||||
|
|
||||||
nodes, cnr := testPlacement(t, replicas, selectors)
|
nodes, cnr := testPlacement(t, selectors, replicas)
|
||||||
|
|
||||||
nodesCopy := copyVectors(nodes)
|
nodesCopy := copyVectors(nodes)
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fn := func(curVector int) {
|
fn := func(curVector int) {
|
||||||
for i := 0; i < replicas[curVector]; i++ {
|
for i := 0; i < selectors[curVector]; i++ {
|
||||||
addrs := tr.Next()
|
addrs := tr.Next()
|
||||||
require.Len(t, addrs, 1)
|
require.Len(t, addrs, 1)
|
||||||
|
|
||||||
|
@ -135,10 +135,10 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
||||||
tr.SubmitSuccess()
|
tr.SubmitSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range replicas {
|
for i := range selectors {
|
||||||
fn(i)
|
fn(i)
|
||||||
|
|
||||||
if i < len(replicas)-1 {
|
if i < len(selectors)-1 {
|
||||||
require.False(t, tr.Success())
|
require.False(t, tr.Success())
|
||||||
} else {
|
} else {
|
||||||
require.True(t, tr.Success())
|
require.True(t, tr.Success())
|
||||||
|
@ -147,10 +147,10 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("put scenario", func(t *testing.T) {
|
t.Run("put scenario", func(t *testing.T) {
|
||||||
replicas := []int{5, 3}
|
selectors := []int{5, 3}
|
||||||
selectors := []int{2, 2}
|
replicas := []int{2, 2}
|
||||||
|
|
||||||
nodes, cnr := testPlacement(t, replicas, selectors)
|
nodes, cnr := testPlacement(t, selectors, replicas)
|
||||||
|
|
||||||
nodesCopy := copyVectors(nodes)
|
nodesCopy := copyVectors(nodes)
|
||||||
|
|
||||||
|
@ -161,9 +161,9 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fn := func(curVector int) {
|
fn := func(curVector int) {
|
||||||
for i := 0; i+selectors[curVector] < replicas[curVector]; i += selectors[curVector] {
|
for i := 0; i+replicas[curVector] < selectors[curVector]; i += replicas[curVector] {
|
||||||
addrs := tr.Next()
|
addrs := tr.Next()
|
||||||
require.Len(t, addrs, selectors[curVector])
|
require.Len(t, addrs, replicas[curVector])
|
||||||
|
|
||||||
for j := range addrs {
|
for j := range addrs {
|
||||||
require.Equal(t, nodes[curVector][i+j].NetworkAddress(), addrs[j].String())
|
require.Equal(t, nodes[curVector][i+j].NetworkAddress(), addrs[j].String())
|
||||||
|
@ -173,15 +173,15 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
||||||
require.Empty(t, tr.Next())
|
require.Empty(t, tr.Next())
|
||||||
require.False(t, tr.Success())
|
require.False(t, tr.Success())
|
||||||
|
|
||||||
for i := 0; i < selectors[curVector]; i++ {
|
for i := 0; i < replicas[curVector]; i++ {
|
||||||
tr.SubmitSuccess()
|
tr.SubmitSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range replicas {
|
for i := range selectors {
|
||||||
fn(i)
|
fn(i)
|
||||||
|
|
||||||
if i < len(replicas)-1 {
|
if i < len(selectors)-1 {
|
||||||
require.False(t, tr.Success())
|
require.False(t, tr.Success())
|
||||||
} else {
|
} else {
|
||||||
require.True(t, tr.Success())
|
require.True(t, tr.Success())
|
||||||
|
|
Loading…
Reference in a new issue