[#xx] traverser: Check for placement vector out of range
Some checks failed
Tests and linters / Run gofumpt (pull_request) Successful in 2m39s
DCO action / DCO (pull_request) Failing after 2m58s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m13s
Vulncheck / Vulncheck (pull_request) Successful in 3m7s
Tests and linters / gopls check (pull_request) Successful in 4m38s
Tests and linters / Staticcheck (pull_request) Successful in 4m44s
Build / Build Components (pull_request) Successful in 6m3s
Tests and linters / Lint (pull_request) Successful in 6m26s
Tests and linters / Tests (pull_request) Successful in 8m49s
Tests and linters / Tests with -race (pull_request) Successful in 8m55s
Some checks failed
Tests and linters / Run gofumpt (pull_request) Successful in 2m39s
DCO action / DCO (pull_request) Failing after 2m58s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m13s
Vulncheck / Vulncheck (pull_request) Successful in 3m7s
Tests and linters / gopls check (pull_request) Successful in 4m38s
Tests and linters / Staticcheck (pull_request) Successful in 4m44s
Build / Build Components (pull_request) Successful in 6m3s
Tests and linters / Lint (pull_request) Successful in 6m26s
Tests and linters / Tests (pull_request) Successful in 8m49s
Tests and linters / Tests with -race (pull_request) Successful in 8m55s
Placement vector may contain fewer nodes count than it required by policy due to the outage of the one of the node. Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
6ae8667fb4
commit
afacc86f35
2 changed files with 55 additions and 5 deletions
|
@ -111,14 +111,18 @@ func NewTraverser(opts ...Option) (*Traverser, error) {
|
||||||
var rem []int
|
var rem []int
|
||||||
if len(cfg.metrics) > 0 && cfg.nodeState != nil {
|
if len(cfg.metrics) > 0 && cfg.nodeState != nil {
|
||||||
rem = defaultCopiesVector(cfg.policy)
|
rem = defaultCopiesVector(cfg.policy)
|
||||||
var unsortedVector []netmap.NodeInfo
|
var unsortedVector, regularVector []netmap.NodeInfo
|
||||||
var regularVector []netmap.NodeInfo
|
|
||||||
for i := range rem {
|
for i := range rem {
|
||||||
unsortedVector = append(unsortedVector, ns[i][:rem[i]]...)
|
if len(ns[i]) < rem[i] {
|
||||||
regularVector = append(regularVector, ns[i][rem[i]:]...)
|
unsortedVector = append(unsortedVector, ns[i]...)
|
||||||
|
} else {
|
||||||
|
unsortedVector = append(unsortedVector, ns[i][:rem[i]]...)
|
||||||
|
if len(ns[i]) > rem[i] {
|
||||||
|
regularVector = append(regularVector, ns[i][rem[i]:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rem = []int{-1, -1}
|
rem = []int{-1, -1}
|
||||||
|
|
||||||
sortedVector, err := sortVector(cfg, unsortedVector)
|
sortedVector, err := sortVector(cfg, unsortedVector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -356,6 +356,52 @@ func TestTraverserPriorityMetrics(t *testing.T) {
|
||||||
require.Nil(t, next)
|
require.Nil(t, next)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("one rep one metric fewer nodes", func(t *testing.T) {
|
||||||
|
selectors := []int{2}
|
||||||
|
replicas := []int{3}
|
||||||
|
|
||||||
|
nodes, cnr := testPlacement(selectors, replicas)
|
||||||
|
|
||||||
|
// Node_0, PK - ip4/0.0.0.0/tcp/0
|
||||||
|
nodes[0][0].SetAttribute("ClusterName", "A")
|
||||||
|
// Node_1, PK - ip4/0.0.0.0/tcp/1
|
||||||
|
nodes[0][1].SetAttribute("ClusterName", "B")
|
||||||
|
|
||||||
|
sdkNode := testNode(5)
|
||||||
|
sdkNode.SetAttribute("ClusterName", "B")
|
||||||
|
|
||||||
|
nodesCopy := copyVectors(nodes)
|
||||||
|
|
||||||
|
m := []Metric{NewAttributeMetric("ClusterName")}
|
||||||
|
|
||||||
|
tr, err := NewTraverser(
|
||||||
|
ForContainer(cnr),
|
||||||
|
UseBuilder(&testBuilder{
|
||||||
|
vectors: nodesCopy,
|
||||||
|
}),
|
||||||
|
WithoutSuccessTracking(),
|
||||||
|
WithPriorityMetrics(m),
|
||||||
|
WithNodeState(&nodeState{
|
||||||
|
node: &sdkNode,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Without priority metric `ClusterName` the order will be:
|
||||||
|
// [ {Node_0 A}, {Node_1 A} ]
|
||||||
|
// With priority metric `ClusterName` and current node in cluster B
|
||||||
|
// the order should be:
|
||||||
|
// [ {Node_1 B}, {Node_0 A} ]
|
||||||
|
next := tr.Next()
|
||||||
|
require.NotNil(t, next)
|
||||||
|
require.Equal(t, 2, len(next))
|
||||||
|
require.Equal(t, "/ip4/0.0.0.0/tcp/1", string(next[0].PublicKey()))
|
||||||
|
require.Equal(t, "/ip4/0.0.0.0/tcp/0", string(next[1].PublicKey()))
|
||||||
|
|
||||||
|
next = tr.Next()
|
||||||
|
require.Nil(t, next)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("two reps two metrics", func(t *testing.T) {
|
t.Run("two reps two metrics", func(t *testing.T) {
|
||||||
selectors := []int{3, 3}
|
selectors := []int{3, 3}
|
||||||
replicas := []int{2, 2}
|
replicas := []int{2, 2}
|
||||||
|
|
Loading…
Reference in a new issue