[#645] placement: Overload result of Traverser.Next method

In previous implementation `placement.Traverser.Next` method returned slice
of `network.AddressGroup` elements. There is a need to process keys of
storage nodes besides network addresses for intra-container communication.

Wrap `network.AddressGroup` in a new type `placement.Node` that summarizes
the storage node information required for communication. Return slice of
`Node` instances from `Traverser.Next` method. Fix compilation breaks in
dependent packages.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-09-06 14:35:06 +03:00 committed by Alex Vanin
parent 3c848b2cad
commit fe90456dcc
6 changed files with 29 additions and 17 deletions

View file

@ -119,10 +119,20 @@ func flatNodes(ns []netmap.Nodes) []netmap.Nodes {
return []netmap.Nodes{flat}
}
// Node is a descriptor of storage node with information required for intra-container communication.
type Node struct {
addresses network.AddressGroup
}
// Addresses returns group of network addresses.
func (x Node) Addresses() network.AddressGroup {
return x.addresses
}
// Next returns next unprocessed address of the object placement.
//
// Returns nil if no nodes left or traversal operation succeeded.
func (t *Traverser) Next() []network.AddressGroup {
func (t *Traverser) Next() []Node {
t.mtx.Lock()
defer t.mtx.Unlock()
@ -139,10 +149,10 @@ func (t *Traverser) Next() []network.AddressGroup {
count = len(t.vectors[0])
}
addrs := make([]network.AddressGroup, count)
nodes := make([]Node, count)
for i := 0; i < count; i++ {
err := addrs[i].FromIterator(t.vectors[0][i])
err := nodes[i].addresses.FromIterator(t.vectors[0][i])
if err != nil {
// TODO: log error
return nil
@ -151,7 +161,7 @@ func (t *Traverser) Next() []network.AddressGroup {
t.vectors[0] = t.vectors[0][count:]
return addrs
return nodes
}
func (t *Traverser) skipEmptyVectors() {