From df5d7bf729e5b75bb41cc331d40ac8490a856b00 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 7 Oct 2022 13:26:08 +0400 Subject: [PATCH] [#1680] replicator: Work with `netmap.NodeInfo` in `TaskResult` Make `replicator.TaskResult` to accept `netmap.NodeInfo` type instead of uint64 in order to clarify the meaning and prevent passing the random numbers. Signed-off-by: Leonard Lyubich --- pkg/services/control/server/evacuate.go | 3 ++- pkg/services/policer/check.go | 16 ++++++++++++---- pkg/services/policer/check_test.go | 2 +- pkg/services/replicator/process.go | 10 +++++----- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pkg/services/control/server/evacuate.go b/pkg/services/control/server/evacuate.go index f10bb764..aac99667 100644 --- a/pkg/services/control/server/evacuate.go +++ b/pkg/services/control/server/evacuate.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/control" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/services/replicator" + "github.com/nspcc-dev/neofs-sdk-go/netmap" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "google.golang.org/grpc/codes" @@ -104,6 +105,6 @@ type replicatorResult struct { } // SubmitSuccessfulReplication implements the replicator.TaskResult interface. -func (r *replicatorResult) SubmitSuccessfulReplication(_ uint64) { +func (r *replicatorResult) SubmitSuccessfulReplication(_ netmap.NodeInfo) { r.count++ } diff --git a/pkg/services/policer/check.go b/pkg/services/policer/check.go index 569d49c5..e303219a 100644 --- a/pkg/services/policer/check.go +++ b/pkg/services/policer/check.go @@ -21,15 +21,19 @@ func newNodeCache() *nodeCache { return (*nodeCache)(&m) } +func (n *nodeCache) set(node netmap.NodeInfo, val bool) { + (*n)[node.Hash()] = val +} + // submits storage node as a candidate to store the object replica in case of // shortage. func (n *nodeCache) submitReplicaCandidate(node netmap.NodeInfo) { - (*n)[node.Hash()] = false + n.set(node, false) } // submits storage node as a current object replica holder. func (n *nodeCache) submitReplicaHolder(node netmap.NodeInfo) { - (*n)[node.Hash()] = true + n.set(node, true) } // processStatus returns current processing status of the storage node @@ -50,8 +54,12 @@ func (n *nodeCache) processStatus(node netmap.NodeInfo) int8 { return 1 } -func (n *nodeCache) SubmitSuccessfulReplication(id uint64) { - (*n)[id] = true +// SubmitSuccessfulReplication marks given storage node as a current object +// replica holder. +// +// SubmitSuccessfulReplication implements replicator.TaskResult. +func (n *nodeCache) SubmitSuccessfulReplication(node netmap.NodeInfo) { + n.submitReplicaHolder(node) } func (p *Policer) processObject(ctx context.Context, addr oid.Address) { diff --git a/pkg/services/policer/check_test.go b/pkg/services/policer/check_test.go index d04c6250..39b2c015 100644 --- a/pkg/services/policer/check_test.go +++ b/pkg/services/policer/check_test.go @@ -13,7 +13,7 @@ func TestNodeCache(t *testing.T) { require.Negative(t, cache.processStatus(node)) - cache.SubmitSuccessfulReplication(node.Hash()) + cache.SubmitSuccessfulReplication(node) require.Zero(t, cache.processStatus(node)) cache.submitReplicaCandidate(node) diff --git a/pkg/services/replicator/process.go b/pkg/services/replicator/process.go index 90bb8510..9b4ad8f1 100644 --- a/pkg/services/replicator/process.go +++ b/pkg/services/replicator/process.go @@ -6,15 +6,15 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" + "github.com/nspcc-dev/neofs-sdk-go/netmap" "go.uber.org/zap" ) // TaskResult is a replication result interface. type TaskResult interface { - // SubmitSuccessfulReplication must save successful - // replication result. ID is a netmap identification - // of a node that accepted the replica. - SubmitSuccessfulReplication(id uint64) + // SubmitSuccessfulReplication submits the successful object replication + // to the given node. + SubmitSuccessfulReplication(netmap.NodeInfo) } // HandleTask executes replication task inside invoking goroutine. @@ -68,7 +68,7 @@ func (p *Replicator) HandleTask(ctx context.Context, task Task, res TaskResult) task.quantity-- - res.SubmitSuccessfulReplication(task.nodes[i].Hash()) + res.SubmitSuccessfulReplication(task.nodes[i]) } } }