[#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 <ctulhurider@gmail.com>
This commit is contained in:
Leonard Lyubich 2022-10-07 13:26:08 +04:00 committed by fyrchik
parent e6f8904040
commit df5d7bf729
4 changed files with 20 additions and 11 deletions

View file

@ -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++
}

View file

@ -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) {

View file

@ -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)

View file

@ -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])
}
}
}