[#619] node: Fix object put when copies numbers contains only zeros
All checks were successful
DCO action / DCO (pull_request) Successful in 3m59s
Build / Build Components (1.21) (pull_request) Successful in 4m53s
Vulncheck / Vulncheck (pull_request) Successful in 4m43s
Build / Build Components (1.20) (pull_request) Successful in 5m57s
Tests and linters / Staticcheck (pull_request) Successful in 8m18s
Tests and linters / Tests (1.21) (pull_request) Successful in 8m33s
Tests and linters / Tests with -race (pull_request) Successful in 8m41s
Tests and linters / Lint (pull_request) Successful in 8m58s
Tests and linters / Tests (1.20) (pull_request) Successful in 8m53s

In this case object should placement according to replicas.

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2023-08-17 11:27:20 +03:00
parent 5335e7089e
commit 6407bb5bd1
2 changed files with 22 additions and 6 deletions

View file

@ -97,16 +97,22 @@ func NewTraverser(opts ...Option) (*Traverser, error) {
} else { } else {
rem = defaultCopiesVector(cfg.policy) rem = defaultCopiesVector(cfg.policy)
// compatibleZeroVector is a bool flag which is set when cfg.copyNumbers // Bool flag which is set when cfg.copyNumbers contains not only zeros.
// is [0]. In this case we should not modify `rem` slice unless track // In this case we should not modify `rem` slice unless track
// copies are ignored, because [0] means that all copies should be // copies are ignored, because [0, ...] means that all copies should be
// stored before returning OK to the client. // 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 { for i := range rem {
if !cfg.trackCopies { if !cfg.trackCopies {
rem[i] = -1 rem[i] = -1
} else if len(cfg.copyNumbers) > i && !compatibleZeroVector { } else if considerCopiesNumber && len(cfg.copyNumbers) > i {
rem[i] = int(cfg.copyNumbers[i]) rem[i] = int(cfg.copyNumbers[i])
} }
} }

View file

@ -227,10 +227,20 @@ func TestTraverserRemValues(t *testing.T) {
expectedRem: replicas, expectedRem: replicas,
}, },
{ {
name: "compatible zero copy numbers", name: "compatible zero copy numbers, len 1",
copyNumbers: []uint32{0}, copyNumbers: []uint32{0},
expectedRem: replicas, 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", name: "copy numbers for all replicas",
copyNumbers: []uint32{1, 1, 1}, copyNumbers: []uint32{1, 1, 1},