diff --git a/pkg/netmap/netmap.go b/pkg/netmap/netmap.go index e8ea6478..4e63e15c 100644 --- a/pkg/netmap/netmap.go +++ b/pkg/netmap/netmap.go @@ -6,6 +6,8 @@ import ( "github.com/nspcc-dev/hrw" ) +const defaultCBF = 3 + // Netmap represents netmap which contains preprocessed nodes. type Netmap struct { Nodes Nodes @@ -49,6 +51,10 @@ func (m *Netmap) GetContainerNodes(p *PlacementPolicy, pivot []byte) (ContainerN c := NewContext(m) c.setPivot(pivot) + if p.ContainerBackupFactor() == 0 { + p.SetContainerBackupFactor(defaultCBF) + } + if err := c.processFilters(p); err != nil { return nil, err } diff --git a/pkg/netmap/selector_test.go b/pkg/netmap/selector_test.go index 20f5bebe..8ba44656 100644 --- a/pkg/netmap/selector_test.go +++ b/pkg/netmap/selector_test.go @@ -31,6 +31,29 @@ func TestPlacementPolicy_UnspecifiedClause(t *testing.T) { 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) { p := newPlacementPolicy(2, []*Replica{