Skip to content

Commit

Permalink
[#607] placement: Make traverser to return list of address groups
Browse files Browse the repository at this point in the history
Make placement `Traverser.Next` method to return ``[]network.AddressGroup`
in order to support multiple addresses of the storeage nodes.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
  • Loading branch information
Leonard Lyubich authored and cthulhu-rider committed Jun 28, 2021
1 parent 8ac3c62 commit b3dd9a3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
3 changes: 1 addition & 2 deletions pkg/services/object/get/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package getsvc
import (
"context"

"github.com/nspcc-dev/neofs-node/pkg/network"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -79,7 +78,7 @@ func (exec *execCtx) processCurrentEpoch() bool {
// TODO: consider parallel execution
// TODO: consider optimization: if status == SPLIT we can continue until
// we reach the best result - split info with linking object ID.
if exec.processNode(ctx, network.GroupFromAddress(addrs[i])) {
if exec.processNode(ctx, addrs[i]) {
exec.log.Debug("completing the operation")
return true
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/object/put/distributed.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ loop:
if err := t.workerPool.Submit(func() {
defer wg.Done()

if err := f(network.GroupFromAddress(addr)); err != nil {
if err := f(addr); err != nil {
svcutil.LogServiceError(t.log, "PUT", addr, err)
return
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/services/object/search/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package searchsvc
import (
"context"

"github.com/nspcc-dev/neofs-node/pkg/network"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -77,7 +76,7 @@ func (exec *execCtx) processCurrentEpoch() bool {
}

// TODO: consider parallel execution
exec.processNode(ctx, network.GroupFromAddress(addrs[i]))
exec.processNode(ctx, addrs[i])
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/services/object/util/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
)

// LogServiceError writes debug error message of object service to provided logger.
func LogServiceError(l *logger.Logger, req string, node network.Address, err error) {
func LogServiceError(l *logger.Logger, req string, node network.AddressGroup, err error) {
l.Debug("object service error",
zap.Stringer("node", node),
zap.String("node", network.StringifyGroup(node)),
zap.String("request", req),
zap.String("error", err.Error()),
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/services/object_manager/placement/traverser.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func flatNodes(ns []netmap.Nodes) []netmap.Nodes {
// Next returns next unprocessed address of the object placement.
//
// Returns nil if no nodes left or traversal operation succeeded.
func (t *Traverser) Next() []network.Address {
func (t *Traverser) Next() []network.AddressGroup {
t.mtx.Lock()
defer t.mtx.Unlock()

Expand All @@ -139,10 +139,10 @@ func (t *Traverser) Next() []network.Address {
count = len(t.vectors[0])
}

addrs := make([]network.Address, count)
addrs := make([]network.AddressGroup, count)

for i := 0; i < count; i++ {
err := addrs[i].FromString(t.vectors[0][i].Address())
err := addrs[i].FromIterator(t.vectors[0][i])
if err != nil {
// TODO: log error
return nil
Expand Down
14 changes: 7 additions & 7 deletions pkg/services/object_manager/placement/traverser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func testPlacement(t *testing.T, ss, rs []int) ([]netmap.Nodes, *container.Conta
return nodes, container.New(container.WithPolicy(policy))
}

func assertSameAddress(t *testing.T, ni *netmap.NodeInfo, addr network.Address) {
var netAddr network.Address
func assertSameAddress(t *testing.T, ni *netmap.NodeInfo, addr network.AddressGroup) {
var netAddr network.AddressGroup

err := netAddr.FromString(ni.Address())
err := netAddr.FromIterator(ni)
require.NoError(t, err)
require.True(t, netAddr.Equal(addr))
require.True(t, netAddr.Intersects(addr))
}

func TestTraverserObjectScenarios(t *testing.T) {
Expand Down Expand Up @@ -124,12 +124,12 @@ func TestTraverserObjectScenarios(t *testing.T) {
require.NotNil(t, tr.Next())
}

var n network.Address
var n network.AddressGroup

err = n.FromString(nodes[1][0].Address())
err = n.FromIterator(nodes[1][0])
require.NoError(t, err)

require.Equal(t, []network.Address{n}, tr.Next())
require.Equal(t, []network.AddressGroup{n}, tr.Next())
})

t.Run("put scenario", func(t *testing.T) {
Expand Down

0 comments on commit b3dd9a3

Please sign in to comment.