diff options
2 files changed, 25 insertions, 7 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/SearchCluster.java b/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/SearchCluster.java index f7a77ebf963..99c607b489a 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/SearchCluster.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/SearchCluster.java @@ -31,7 +31,8 @@ public class SearchCluster implements NodeManager<Node> { private final String clusterId; private final VipStatus vipStatus; private final PingFactory pingFactory; - private volatile SearchGroupsImpl groups; + private volatile SearchGroupsImpl groups; // Groups in this cluster + private volatile SearchGroupsImpl monitoredGroups; // Same as groups, except during reconfiguration. private volatile long nextLogTime = 0; /** @@ -53,6 +54,7 @@ public class SearchCluster implements NodeManager<Node> { this.clusterId = clusterId; this.vipStatus = vipStatus; this.pingFactory = pingFactory; + this.monitoredGroups = groups; this.groups = groups; this.localCorpusDispatchTarget = findLocalCorpusDispatchTarget(HostName.getLocalhost(), groups); } @@ -72,12 +74,13 @@ public class SearchCluster implements NodeManager<Node> { } SearchGroupsImpl groups = toGroups(currentNodes, minActivedocsPercentage); this.localCorpusDispatchTarget = findLocalCorpusDispatchTarget(HostName.getLocalhost(), groups); + this.monitoredGroups = groups; monitor.reconfigure(groups.nodes()); this.groups = groups; } public void addMonitoring(ClusterMonitor<Node> clusterMonitor) { - for (Node node : groups.nodes()) clusterMonitor.add(node, true); + for (Node node : monitoredGroups.nodes()) clusterMonitor.add(node, true); } private static Node findLocalCorpusDispatchTarget(String selfHostname, SearchGroups groups) { @@ -190,15 +193,15 @@ public class SearchCluster implements NodeManager<Node> { } public boolean hasInformationAboutAllNodes() { - return groups().stream().allMatch(group -> group.nodes().stream().allMatch(node -> node.isWorking() != null)); + return monitoredGroups.nodes().stream().allMatch(node -> node.isWorking() != null); } long nonWorkingNodeCount() { - return groups().stream().flatMap(group -> group.nodes().stream()).filter(node -> node.isWorking() == Boolean.FALSE).count(); + return monitoredGroups.nodes().stream().filter(node -> node.isWorking() == Boolean.FALSE).count(); } private boolean hasWorkingNodes() { - return groups().stream().anyMatch(group -> group.nodes().stream().anyMatch(node -> node.isWorking() != Boolean.FALSE)); + return monitoredGroups.nodes().stream().anyMatch(node -> node.isWorking() != Boolean.FALSE); } private boolean usesLocalCorpusIn(Node node) { @@ -244,7 +247,7 @@ public class SearchCluster implements NodeManager<Node> { */ @Override public void pingIterationCompleted() { - pingIterationCompleted(groups); + pingIterationCompleted(monitoredGroups); } private void pingIterationCompleted(SearchGroupsImpl groups) { diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java index c3ddeac5365..dd0980322c4 100644 --- a/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java +++ b/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java @@ -25,7 +25,10 @@ import java.util.stream.IntStream; import static java.util.function.Function.identity; import static java.util.stream.Collectors.toMap; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author baldersheim @@ -155,6 +158,18 @@ public class SearchClusterTest { } @Test + void requireThatVipStatusWorksWhenReconfiguredFromZeroNodes() { + try (State test = new State("test", 2, "a", "b")) { + test.clusterMonitor.start(); + test.searchCluster.updateNodes(List.of(), test.clusterMonitor, 100.0); + assertEquals(Set.of(), test.searchCluster.groupList().nodes()); + + test.searchCluster.updateNodes(List.of(new Node("test", 0, "a", 0), new Node("test", 1, "b", 0)), test.clusterMonitor, 100.0); + assertTrue(test.vipStatus.isInRotation()); + } + } + + @Test void requireThatVipStatusIsDefaultDownButComesUpAfterPinging() { try (State test = new State("cluster.1", 2, "a", "b")) { assertTrue(test.searchCluster.localCorpusDispatchTarget().isEmpty()); |