forked from TrueCloudLab/frostfs-node
[#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")
|
||||
}
|
||||
|
||||
ss := cfg.policy.GetSelectors()
|
||||
rem := make([]int, 0, len(ss))
|
||||
rs := cfg.policy.GetReplicas()
|
||||
rem := make([]int, 0, len(rs))
|
||||
|
||||
for i := range ss {
|
||||
for i := range rs {
|
||||
cnt := cfg.rem
|
||||
|
||||
if cnt == 0 {
|
||||
cnt = int(ss[i].GetCount())
|
||||
cnt = int(rs[i].GetCount())
|
||||
}
|
||||
|
||||
rem = append(rem, cnt)
|
||||
|
|
|
@ -49,39 +49,39 @@ func copyVectors(v []netmap.Nodes) []netmap.Nodes {
|
|||
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))
|
||||
selectors := make([]*netmap.Selector, 0, len(rs))
|
||||
replicas := make([]*netmap.Replica, 0, len(rs))
|
||||
num := uint32(0)
|
||||
|
||||
for i := range rs {
|
||||
ns := make([]netmapV2.NodeInfo, 0, rs[i])
|
||||
for i := range ss {
|
||||
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))
|
||||
num++
|
||||
}
|
||||
|
||||
nodes = append(nodes, netmap.NodesFromV2(ns))
|
||||
|
||||
s := new(netmap.Selector)
|
||||
s.SetCount(uint32(ss[i]))
|
||||
s := new(netmap.Replica)
|
||||
s.SetCount(uint32(rs[i]))
|
||||
|
||||
selectors = append(selectors, s)
|
||||
replicas = append(replicas, s)
|
||||
}
|
||||
|
||||
policy := new(netmap.PlacementPolicy)
|
||||
policy.SetSelectors(selectors)
|
||||
policy.SetReplicas(replicas)
|
||||
|
||||
return nodes, container.New(container.WithPolicy(policy))
|
||||
}
|
||||
|
||||
func TestTraverserObjectScenarios(t *testing.T) {
|
||||
t.Run("search scenario", func(t *testing.T) {
|
||||
replicas := []int{2, 3}
|
||||
selectors := []int{1, 2}
|
||||
selectors := []int{2, 3}
|
||||
replicas := []int{1, 2}
|
||||
|
||||
nodes, cnr := testPlacement(t, replicas, selectors)
|
||||
nodes, cnr := testPlacement(t, selectors, replicas)
|
||||
|
||||
nodesCopy := copyVectors(nodes)
|
||||
|
||||
|
@ -92,7 +92,7 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := range replicas {
|
||||
for i := range selectors {
|
||||
addrs := tr.Next()
|
||||
|
||||
require.Len(t, addrs, len(nodes[i]))
|
||||
|
@ -107,10 +107,10 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("read scenario", func(t *testing.T) {
|
||||
replicas := []int{5, 3}
|
||||
selectors := []int{2, 2}
|
||||
selectors := []int{5, 3}
|
||||
replicas := []int{2, 2}
|
||||
|
||||
nodes, cnr := testPlacement(t, replicas, selectors)
|
||||
nodes, cnr := testPlacement(t, selectors, replicas)
|
||||
|
||||
nodesCopy := copyVectors(nodes)
|
||||
|
||||
|
@ -122,7 +122,7 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
fn := func(curVector int) {
|
||||
for i := 0; i < replicas[curVector]; i++ {
|
||||
for i := 0; i < selectors[curVector]; i++ {
|
||||
addrs := tr.Next()
|
||||
require.Len(t, addrs, 1)
|
||||
|
||||
|
@ -135,10 +135,10 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
|||
tr.SubmitSuccess()
|
||||
}
|
||||
|
||||
for i := range replicas {
|
||||
for i := range selectors {
|
||||
fn(i)
|
||||
|
||||
if i < len(replicas)-1 {
|
||||
if i < len(selectors)-1 {
|
||||
require.False(t, tr.Success())
|
||||
} else {
|
||||
require.True(t, tr.Success())
|
||||
|
@ -147,10 +147,10 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("put scenario", func(t *testing.T) {
|
||||
replicas := []int{5, 3}
|
||||
selectors := []int{2, 2}
|
||||
selectors := []int{5, 3}
|
||||
replicas := []int{2, 2}
|
||||
|
||||
nodes, cnr := testPlacement(t, replicas, selectors)
|
||||
nodes, cnr := testPlacement(t, selectors, replicas)
|
||||
|
||||
nodesCopy := copyVectors(nodes)
|
||||
|
||||
|
@ -161,9 +161,9 @@ func TestTraverserObjectScenarios(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
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()
|
||||
require.Len(t, addrs, selectors[curVector])
|
||||
require.Len(t, addrs, replicas[curVector])
|
||||
|
||||
for j := range addrs {
|
||||
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.False(t, tr.Success())
|
||||
|
||||
for i := 0; i < selectors[curVector]; i++ {
|
||||
for i := 0; i < replicas[curVector]; i++ {
|
||||
tr.SubmitSuccess()
|
||||
}
|
||||
}
|
||||
|
||||
for i := range replicas {
|
||||
for i := range selectors {
|
||||
fn(i)
|
||||
|
||||
if i < len(replicas)-1 {
|
||||
if i < len(selectors)-1 {
|
||||
require.False(t, tr.Success())
|
||||
} else {
|
||||
require.True(t, tr.Success())
|
||||
|
|
Loading…
Reference in a new issue