From b3dd9a3254372a850687b6a1fa4ac316a2734ce4 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 22 Jun 2021 18:22:40 +0300 Subject: [PATCH] [#607] placement: Make traverser to return list of address groups Make placement `Traverser.Next` method to return ``[]network.AddressGroup` in order to support multiple addresses of the storeage nodes. Signed-off-by: Leonard Lyubich --- pkg/services/object/get/container.go | 3 +-- pkg/services/object/put/distributed.go | 2 +- pkg/services/object/search/container.go | 3 +-- pkg/services/object/util/log.go | 4 ++-- pkg/services/object_manager/placement/traverser.go | 6 +++--- .../object_manager/placement/traverser_test.go | 14 +++++++------- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/pkg/services/object/get/container.go b/pkg/services/object/get/container.go index f56e72069..62e070c40 100644 --- a/pkg/services/object/get/container.go +++ b/pkg/services/object/get/container.go @@ -3,7 +3,6 @@ package getsvc import ( "context" - "github.com/nspcc-dev/neofs-node/pkg/network" "go.uber.org/zap" ) @@ -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 } diff --git a/pkg/services/object/put/distributed.go b/pkg/services/object/put/distributed.go index 903c175ee..9b48b1572 100644 --- a/pkg/services/object/put/distributed.go +++ b/pkg/services/object/put/distributed.go @@ -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 } diff --git a/pkg/services/object/search/container.go b/pkg/services/object/search/container.go index d287897ce..25e3a4d2c 100644 --- a/pkg/services/object/search/container.go +++ b/pkg/services/object/search/container.go @@ -3,7 +3,6 @@ package searchsvc import ( "context" - "github.com/nspcc-dev/neofs-node/pkg/network" "go.uber.org/zap" ) @@ -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]) } } diff --git a/pkg/services/object/util/log.go b/pkg/services/object/util/log.go index 7f90e3be4..c111c2b8d 100644 --- a/pkg/services/object/util/log.go +++ b/pkg/services/object/util/log.go @@ -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()), ) diff --git a/pkg/services/object_manager/placement/traverser.go b/pkg/services/object_manager/placement/traverser.go index 23511e892..381353bba 100644 --- a/pkg/services/object_manager/placement/traverser.go +++ b/pkg/services/object_manager/placement/traverser.go @@ -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() @@ -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 diff --git a/pkg/services/object_manager/placement/traverser_test.go b/pkg/services/object_manager/placement/traverser_test.go index 182062962..ed25d0667 100644 --- a/pkg/services/object_manager/placement/traverser_test.go +++ b/pkg/services/object_manager/placement/traverser_test.go @@ -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) { @@ -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) {