From 6407bb5bd1ef138501ece8dcac80f2ba8d884181 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 17 Aug 2023 11:27:20 +0300 Subject: [PATCH] [#619] node: Fix object put when copies numbers contains only zeros In this case object should placement according to replicas. Signed-off-by: Anton Nikiforov --- .../object_manager/placement/traverser.go | 16 +++++++++++----- .../object_manager/placement/traverser_test.go | 12 +++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/pkg/services/object_manager/placement/traverser.go b/pkg/services/object_manager/placement/traverser.go index c59146e2b..ad1077047 100644 --- a/pkg/services/object_manager/placement/traverser.go +++ b/pkg/services/object_manager/placement/traverser.go @@ -97,16 +97,22 @@ func NewTraverser(opts ...Option) (*Traverser, error) { } else { rem = defaultCopiesVector(cfg.policy) - // compatibleZeroVector is a bool flag which is set when cfg.copyNumbers - // is [0]. In this case we should not modify `rem` slice unless track - // copies are ignored, because [0] means that all copies should be + // Bool flag which is set when cfg.copyNumbers contains not only zeros. + // In this case we should not modify `rem` slice unless track + // copies are ignored, because [0, ...] means that all copies should be // stored before returning OK to the client. - compatibleZeroVector := len(cfg.copyNumbers) == 1 && cfg.copyNumbers[0] == 0 + var considerCopiesNumber bool + for _, val := range cfg.copyNumbers { + if val != 0 { + considerCopiesNumber = true + break + } + } for i := range rem { if !cfg.trackCopies { rem[i] = -1 - } else if len(cfg.copyNumbers) > i && !compatibleZeroVector { + } else if considerCopiesNumber && len(cfg.copyNumbers) > i { rem[i] = int(cfg.copyNumbers[i]) } } diff --git a/pkg/services/object_manager/placement/traverser_test.go b/pkg/services/object_manager/placement/traverser_test.go index 1b307da6f..e16f33759 100644 --- a/pkg/services/object_manager/placement/traverser_test.go +++ b/pkg/services/object_manager/placement/traverser_test.go @@ -227,10 +227,20 @@ func TestTraverserRemValues(t *testing.T) { expectedRem: replicas, }, { - name: "compatible zero copy numbers", + name: "compatible zero copy numbers, len 1", copyNumbers: []uint32{0}, expectedRem: replicas, }, + { + name: "compatible zero copy numbers, len 2", + copyNumbers: []uint32{0, 0}, + expectedRem: replicas, + }, + { + name: "compatible zero copy numbers, len 3", + copyNumbers: []uint32{0, 0, 0}, + expectedRem: replicas, + }, { name: "copy numbers for all replicas", copyNumbers: []uint32{1, 1, 1},