[#220] netmap: process REP X policies correctly

For `REP X` select X nodes from the default filter
and fail if it cannot be done.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2020-12-03 13:52:36 +03:00 committed by Alex Vanin
parent 576841e0e0
commit 707a0bcb35
2 changed files with 50 additions and 0 deletions

View file

@ -71,6 +71,19 @@ func (m *Netmap) GetContainerNodes(p *PlacementPolicy, pivot []byte) (ContainerN
} }
if r.Selector() == "" { if r.Selector() == "" {
if len(p.Selectors()) == 0 {
s := new(Selector)
s.SetCount(r.Count())
s.SetFilter(MainFilterName)
nodes, err := c.getSelection(p, s)
if err != nil {
return nil, err
}
result[i] = flattenNodes(nodes)
}
for _, s := range p.Selectors() { for _, s := range p.Selectors() {
result[i] = append(result[i], flattenNodes(c.Selections[s.Name()])...) result[i] = append(result[i], flattenNodes(c.Selections[s.Name()])...)
} }

View file

@ -31,6 +31,43 @@ func TestPlacementPolicy_UnspecifiedClause(t *testing.T) {
require.Equal(t, 4, len(v.Flatten())) require.Equal(t, 4, len(v.Flatten()))
} }
func TestPlacementPolicy_Minimal(t *testing.T) {
nodes := []NodeInfo{
nodeInfoFromAttributes("City", "Saint-Petersburg"),
nodeInfoFromAttributes("City", "Moscow"),
nodeInfoFromAttributes("City", "Berlin"),
nodeInfoFromAttributes("City", "Paris"),
}
nm, err := NewNetmap(NodesFromInfo(nodes))
require.NoError(t, err)
runTest := func(t *testing.T, rep uint32, expectError bool) {
p := newPlacementPolicy(0,
[]*Replica{newReplica(rep, "")},
nil, nil)
v, err := nm.GetContainerNodes(p, nil)
if expectError {
require.Error(t, err)
return
}
require.NoError(t, err)
require.EqualValues(t, rep, len(v.Flatten()))
}
t.Run("REP 1", func(t *testing.T) {
runTest(t, 1, false)
})
t.Run("REP 3", func(t *testing.T) {
runTest(t, 3, false)
})
t.Run("REP 5", func(t *testing.T) {
runTest(t, 5, true)
})
}
// Issue #215. // Issue #215.
func TestPlacementPolicy_MultipleREP(t *testing.T) { func TestPlacementPolicy_MultipleREP(t *testing.T) {
p := newPlacementPolicy(1, p := newPlacementPolicy(1,