netmap: sort buckets by HRW value
If weights for some buckets are equal, result depends on the initial positions of buckets in slice. Thus we sort buckets by value using hash of the first node as a have for the whole bucket. This is ok, because buckets are already sorted by HRW. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
f7582399ed
commit
3edaf9ecb6
3 changed files with 192 additions and 2 deletions
|
@ -58,8 +58,11 @@ func (c *Context) getSelection(p *PlacementPolicy, s *Selector) ([]Nodes, error)
|
|||
return nil, fmt.Errorf("%w: '%s'", ErrNotEnoughNodes, s.Name())
|
||||
}
|
||||
|
||||
// We need deterministic output in case there is no pivot.
|
||||
// If pivot is set, buckets are sorted by HRW.
|
||||
// However, because initial order influences HRW order for buckets with equal weights,
|
||||
// we also need to have deterministic input to HRW sorting routine.
|
||||
if len(c.pivot) == 0 {
|
||||
// Deterministic order in case of zero seed.
|
||||
if s.Attribute() == "" {
|
||||
sort.Slice(buckets, func(i, j int) bool {
|
||||
return buckets[i].nodes[0].ID < buckets[j].nodes[0].ID
|
||||
|
@ -98,7 +101,7 @@ func (c *Context) getSelection(p *PlacementPolicy, s *Selector) ([]Nodes, error)
|
|||
weights[i] = GetBucketWeight(nodes[i], c.aggregator(), c.weightFunc)
|
||||
}
|
||||
|
||||
hrw.SortSliceByWeightIndex(nodes, weights, c.pivotHash)
|
||||
hrw.SortSliceByWeightValue(nodes, weights, c.pivotHash)
|
||||
}
|
||||
|
||||
if s.Attribute() == "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue