[#157] netmap: Fallback to using minimal backup factor

Use CBF=1 when strict policy can't be satisfied.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2020-11-27 11:46:25 +03:00 committed by Leonard Lyubich
parent c01024b553
commit ea6b6adfe0
2 changed files with 45 additions and 9 deletions

View file

@ -36,14 +36,14 @@ func (c *Context) processSelectors(p *PlacementPolicy) error {
return nil
}
// GetNodesCount returns amount of buckets and nodes in every bucket
// for a given placement policy.
func GetNodesCount(p *PlacementPolicy, s *Selector) (int, int) {
// GetNodesCount returns amount of buckets and minimum number of nodes in every bucket
// for the given selector.
func GetNodesCount(_ *PlacementPolicy, s *Selector) (int, int) {
switch s.Clause() {
case ClauseSame:
return 1, int(p.ContainerBackupFactor() * s.Count())
return 1, int(s.Count())
default:
return int(s.Count()), int(p.ContainerBackupFactor())
return int(s.Count()), 1
}
}
@ -69,17 +69,25 @@ func (c *Context) getSelection(p *PlacementPolicy, s *Selector) ([]Nodes, error)
}
}
maxNodesInBucket := nodesInBucket * int(p.ContainerBackupFactor())
nodes := make([]Nodes, 0, len(buckets))
fallback := make([]Nodes, 0, len(buckets))
for i := range buckets {
ns := buckets[i].nodes
if len(ns) >= nodesInBucket {
nodes = append(nodes, ns[:nodesInBucket])
if len(ns) >= maxNodesInBucket {
nodes = append(nodes, ns[:maxNodesInBucket])
} else if len(ns) >= nodesInBucket {
fallback = append(fallback, ns)
}
}
if len(nodes) < bucketCount {
return nil, fmt.Errorf("%w: '%s'", ErrNotEnoughNodes, s.Name())
// Fallback to using minimum allowed backup factor (1).
nodes = append(nodes, fallback...)
if len(nodes) < bucketCount {
return nil, fmt.Errorf("%w: '%s'", ErrNotEnoughNodes, s.Name())
}
}
if len(c.pivot) != 0 {