From 58033a3adc334e5a5de30930033fa6735ba93de4 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 23 Dec 2020 12:53:11 +0300 Subject: [PATCH] [#271] placement: Add BuildObjectPlacement function This function allows to shuffle prepared container nodes according to HRW weights from network map. Signed-off-by: Alex Vanin --- pkg/services/object_manager/placement/netmap.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/services/object_manager/placement/netmap.go b/pkg/services/object_manager/placement/netmap.go index d08724ed..fcea1f47 100644 --- a/pkg/services/object_manager/placement/netmap.go +++ b/pkg/services/object_manager/placement/netmap.go @@ -37,19 +37,21 @@ func (b *netMapBuilder) BuildPlacement(a *object.Address, p *netmapSDK.Placement return nil, errors.Wrap(err, "could not get network map") } - aV2 := a.ToV2() - - cn, err := nm.GetContainerNodes(p, aV2.GetContainerID().GetValue()) + cn, err := nm.GetContainerNodes(p, a.ContainerID().ToV2().GetValue()) if err != nil { return nil, errors.Wrap(err, "could not get container nodes") } - oid := aV2.GetObjectID() - if oid == nil { - return cn.Replicas(), nil + return BuildObjectPlacement(nm, cn, a.ObjectID()) +} + +func BuildObjectPlacement(nm *netmapSDK.Netmap, cnrNodes netmapSDK.ContainerNodes, id *object.ID) ([]netmapSDK.Nodes, error) { + objectID := id.ToV2() + if objectID == nil { + return cnrNodes.Replicas(), nil } - on, err := nm.GetPlacementVectors(cn, oid.GetValue()) + on, err := nm.GetPlacementVectors(cnrNodes, objectID.GetValue()) if err != nil { return nil, errors.Wrap(err, "could not get placement vectors for object") }