node: Fix object put when copies numbers contains only zeros #619

Merged
fyrchik merged 1 commit from acid-ant/frostfs-node:bugfix/copiesnum-contains-only-zeros into master 2023-08-17 11:31:45 +00:00
2 changed files with 22 additions and 6 deletions

View file

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

View file

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