Apache Lucene open-source search software
Revert "SOLR-9181: Fix test bug in ZkStateReaderTest"
Alan Woodward1e2ba9fe9be8
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 49b2a9f2f9d..c9f466341e0 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -140,7 +140,7 @@ New Features* SOLR-8208: [subquery] document transformer executes separate requests per result document. (Cao Manh Dat via Mikhail Khludnev)-* SOLR-8323, SOLR-9113, SOLR-9181: Add CollectionStateWatcher API (Alan Woodward, Scott Blum)+* SOLR-8323, SOLR-9113: Add CollectionStateWatcher API (Alan Woodward, Scott Blum)* SOLR-8988: Adds query option facet.distrib.mco which when set to true allows the use of facet.mincount=1 in cloud mode.(Keith Laban, Dennis Gove)diff --git a/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java b/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.javaindex 1e9454a2f70..ad51614b19c 100644--- a/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java@@ -18,7 +18,6 @@ package org.apache.solr.cloud.overseer;import java.util.HashMap;import java.util.Map;-import java.util.concurrent.TimeUnit;import org.apache.lucene.util.IOUtils;import org.apache.solr.SolrTestCaseJ4;@@ -30,14 +29,13 @@ import org.apache.solr.cloud.ZkTestServer;import org.apache.solr.common.cloud.ClusterState;import org.apache.solr.common.cloud.DocCollection;import org.apache.solr.common.cloud.DocRouter;+import org.apache.solr.common.cloud.Slice;import org.apache.solr.common.cloud.SolrZkClient;import org.apache.solr.common.cloud.ZkStateReader;import org.apache.solr.common.util.Utils;public class ZkStateReaderTest extends SolrTestCaseJ4 {- private static final long TIMEOUT = 30;-/** Uses explicit refresh to ensure latest changes are visible. */public void testStateFormatUpdateWithExplicitRefresh() throws Exception {testStateFormatUpdate(true, true);@@ -86,7 +84,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {{// create new collection with stateFormat = 1- DocCollection stateV1 = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE);+ DocCollection stateV1 = new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE);ZkWriteCommand c1 = new ZkWriteCommand("c1", stateV1);writer.enqueueUpdate(reader.getClusterState(), c1, null);writer.writePendingUpdates();@@ -99,7 +97,12 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {if (explicitRefresh) {reader.forceUpdateCollection("c1");} else {- reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null);+ for (int i = 0; i < 1000; ++i) {+ if (reader.getClusterState().hasCollection("c1")) {+ break;+ }+ Thread.sleep(50);+ }}DocCollection collection = reader.getClusterState().getCollection("c1");@@ -109,7 +112,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {{// Now update the collection to stateFormat = 2- DocCollection stateV2 = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json");+ DocCollection stateV2 = new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json");ZkWriteCommand c2 = new ZkWriteCommand("c1", stateV2);writer.enqueueUpdate(reader.getClusterState(), c2, null);writer.writePendingUpdates();@@ -122,7 +125,12 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {if (explicitRefresh) {reader.forceUpdateCollection("c1");} else {- reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null && c.getStateFormat() == 2);+ for (int i = 0; i < 1000; ++i) {+ if (reader.getClusterState().getCollection("c1").getStateFormat() == 2) {+ break;+ }+ Thread.sleep(50);+ }}DocCollection collection = reader.getClusterState().getCollection("c1");@@ -158,7 +166,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {// create new collection with stateFormat = 2ZkWriteCommand c1 = new ZkWriteCommand("c1",- new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"));+ new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"));writer.enqueueUpdate(reader.getClusterState(), c1, null);writer.writePendingUpdates();reader.forceUpdateCollection("c1");@@ -208,7 +216,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {// create new collection with stateFormat = 2- DocCollection state = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE + "/c1/state.json");+ DocCollection state = new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE + "/c1/state.json");ZkWriteCommand wc = new ZkWriteCommand("c1", state);writer.enqueueUpdate(reader.getClusterState(), wc, null);writer.writePendingUpdates();@@ -216,7 +224,14 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true));//reader.forceUpdateCollection("c1");- reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null);++ for (int i = 0; i < 100; ++i) {+ Thread.sleep(50);+ ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1");+ if (ref != null) {+ break;+ }+ }ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1");assertNotNull(ref);assertFalse(ref.isLazilyLoaded());diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.javaindex 3de0a614c5e..aff5bba04a7 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java@@ -515,8 +515,10 @@ public class ZkStateReader implements Closeable {String coll = watchEntry.getKey();CollectionWatch collWatch = watchEntry.getValue();ClusterState.CollectionRef ref = this.legacyCollectionStates.get(coll);+ if (ref == null)+ continue;// legacy collections are always in-memory- DocCollection oldState = ref == null ? null : ref.get();+ DocCollection oldState = ref.get();ClusterState.CollectionRef newRef = loadedData.getCollectionStates().get(coll);DocCollection newState = newRef == null ? null : newRef.get();if (!collWatch.stateWatchers.isEmpty()@@ -1154,17 +1156,17 @@ public class ZkStateReader implements Closeable {v.stateWatchers.add(stateWatcher);return v;});-if (watchSet.get()) {new StateWatcher(collection).refreshAndWatch();synchronized (getUpdateLock()) {constructState();}}-- DocCollection state = clusterState.getCollectionOrNull(collection);- if (stateWatcher.onStateChanged(liveNodes, state) == true) {- removeCollectionStateWatcher(collection, stateWatcher);+ else {+ DocCollection state = clusterState.getCollectionOrNull(collection);+ if (stateWatcher.onStateChanged(liveNodes, state) == true) {+ removeCollectionStateWatcher(collection, stateWatcher);+ }}}