diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-06-30 11:59:15 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2021-06-30 11:59:15 +0200 |
commit | bbb2fd3495f7af472820be15f446ac76e4cde63e (patch) | |
tree | ec7731be4e307df3467ef554033ea1562282b265 /container-search/src | |
parent | eca1f49029248d736bdd28a12466e218c9d91d47 (diff) |
Allow deviation of at least 1 document
Let content be well-balanced when there are few docs in a cluster
Diffstat (limited to 'container-search/src')
2 files changed, 23 insertions, 1 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/Group.java b/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/Group.java index dca5892e0e7..7faad9d51cc 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/Group.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/Group.java @@ -68,7 +68,7 @@ public class Group { if (numWorkingNodes > 0) { long average = activeDocs / numWorkingNodes; long deviation = nodes.stream().filter(node -> node.isWorking() == Boolean.TRUE).mapToLong(node -> Math.abs(node.getActiveDocuments() - average)).sum(); - boolean isDeviationSmall = deviation <= (activeDocs * MAX_UNBALANCE); + boolean isDeviationSmall = deviation <= maxUnbalance(activeDocs); if ((!isContentWellBalanced.get() || isDeviationSmall != isContentWellBalanced.get()) && (activeDocs > 0)) { log.info("Content is " + (isDeviationSmall ? "" : "not ") + "well balanced. Current deviation = " + deviation*100/activeDocs + " %" + ". activeDocs = " + activeDocs + ", deviation = " + deviation + ", average = " + average); @@ -79,6 +79,10 @@ public class Group { } } + double maxUnbalance(long activeDocs) { + return Math.max(1, activeDocs * MAX_UNBALANCE); + } + /** Returns the active documents on this group. If unknown, 0 is returned. */ long getActiveDocuments() { return activeDocuments.get(); } diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterCoverageTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterCoverageTest.java index 65e7173c4ee..c9f7469acbb 100644 --- a/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterCoverageTest.java +++ b/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterCoverageTest.java @@ -100,4 +100,22 @@ public class SearchClusterCoverageTest { assertTrue(tester.group(2).hasSufficientCoverage()); } + @Test + public void one_group_few_docs_has_well_balanced_content() { + var tester = new SearchClusterTester(1, 2); + + Node node0 = tester.group(0).nodes().get(0); + Node node1 = tester.group(0).nodes().get(1); + + // 1 document + node0.setWorking(true); + node1.setWorking(true); + + node0.setActiveDocuments(1); + node1.setActiveDocuments(0); + + tester.pingIterationCompleted(); + assertTrue(tester.group(0).isContentWellBalanced()); + } + } |