[#156] netmap: Use default value for CBF if unset

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2020-11-27 12:41:56 +03:00 committed by Leonard Lyubich
parent 4e65fa41b8
commit 4e0a11b71a
2 changed files with 29 additions and 0 deletions

View file

@ -6,6 +6,8 @@ import (
"github.com/nspcc-dev/hrw" "github.com/nspcc-dev/hrw"
) )
const defaultCBF = 3
// Netmap represents netmap which contains preprocessed nodes. // Netmap represents netmap which contains preprocessed nodes.
type Netmap struct { type Netmap struct {
Nodes Nodes Nodes Nodes
@ -49,6 +51,10 @@ func (m *Netmap) GetContainerNodes(p *PlacementPolicy, pivot []byte) (ContainerN
c := NewContext(m) c := NewContext(m)
c.setPivot(pivot) c.setPivot(pivot)
if p.ContainerBackupFactor() == 0 {
p.SetContainerBackupFactor(defaultCBF)
}
if err := c.processFilters(p); err != nil { if err := c.processFilters(p); err != nil {
return nil, err return nil, err
} }

View file

@ -31,6 +31,29 @@ func TestPlacementPolicy_UnspecifiedClause(t *testing.T) {
require.Equal(t, 4, len(v.Flatten())) require.Equal(t, 4, len(v.Flatten()))
} }
func TestPlacementPolicy_DefaultCBF(t *testing.T) {
p := newPlacementPolicy(0,
[]*Replica{
newReplica(1, "EU"),
},
[]*Selector{
newSelector("EU", "Location", ClauseSame, 1, "*"),
},
nil)
nodes := []NodeInfo{
nodeInfoFromAttributes("Location", "Europe", "Country", "RU", "City", "St.Petersburg"),
nodeInfoFromAttributes("Location", "Europe", "Country", "RU", "City", "Moscow"),
nodeInfoFromAttributes("Location", "Europe", "Country", "DE", "City", "Berlin"),
nodeInfoFromAttributes("Location", "Europe", "Country", "FR", "City", "Paris"),
}
nm, err := NewNetmap(NodesFromInfo(nodes))
require.NoError(t, err)
v, err := nm.GetContainerNodes(p, nil)
require.NoError(t, err)
require.Equal(t, defaultCBF, len(v.Flatten()))
}
func TestPlacementPolicy_GetPlacementVectors(t *testing.T) { func TestPlacementPolicy_GetPlacementVectors(t *testing.T) {
p := newPlacementPolicy(2, p := newPlacementPolicy(2,
[]*Replica{ []*Replica{