SOLR-9181: Fix test bug in ZkStateReaderTest

This commit is contained in:
Alan Woodward 2016-06-02 15:15:46 +01:00
parent aed3fc11b1
commit 950fd91335
3 changed files with 17 additions and 34 deletions

View File

@ -140,7 +140,7 @@ New Features
* SOLR-8208: [subquery] document transformer executes separate requests per result document. (Cao Manh Dat via Mikhail Khludnev) * SOLR-8208: [subquery] document transformer executes separate requests per result document. (Cao Manh Dat via Mikhail Khludnev)
* SOLR-8323, SOLR-9113: Add CollectionStateWatcher API (Alan Woodward, Scott Blum) * SOLR-8323, SOLR-9113, SOLR-9181: 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. * 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) (Keith Laban, Dennis Gove)

View File

@ -18,6 +18,7 @@ package org.apache.solr.cloud.overseer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
@ -29,13 +30,14 @@ import org.apache.solr.cloud.ZkTestServer;
import org.apache.solr.common.cloud.ClusterState; import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocRouter; 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.SolrZkClient;
import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.Utils; import org.apache.solr.common.util.Utils;
public class ZkStateReaderTest extends SolrTestCaseJ4 { public class ZkStateReaderTest extends SolrTestCaseJ4 {
private static final long TIMEOUT = 30;
/** Uses explicit refresh to ensure latest changes are visible. */ /** Uses explicit refresh to ensure latest changes are visible. */
public void testStateFormatUpdateWithExplicitRefresh() throws Exception { public void testStateFormatUpdateWithExplicitRefresh() throws Exception {
testStateFormatUpdate(true, true); testStateFormatUpdate(true, true);
@ -84,7 +86,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
{ {
// create new collection with stateFormat = 1 // create new collection with stateFormat = 1
DocCollection stateV1 = new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE); DocCollection stateV1 = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE);
ZkWriteCommand c1 = new ZkWriteCommand("c1", stateV1); ZkWriteCommand c1 = new ZkWriteCommand("c1", stateV1);
writer.enqueueUpdate(reader.getClusterState(), c1, null); writer.enqueueUpdate(reader.getClusterState(), c1, null);
writer.writePendingUpdates(); writer.writePendingUpdates();
@ -97,12 +99,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
if (explicitRefresh) { if (explicitRefresh) {
reader.forceUpdateCollection("c1"); reader.forceUpdateCollection("c1");
} else { } else {
for (int i = 0; i < 1000; ++i) { reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null);
if (reader.getClusterState().hasCollection("c1")) {
break;
}
Thread.sleep(50);
}
} }
DocCollection collection = reader.getClusterState().getCollection("c1"); DocCollection collection = reader.getClusterState().getCollection("c1");
@ -112,7 +109,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
{ {
// Now update the collection to stateFormat = 2 // Now update the collection to stateFormat = 2
DocCollection stateV2 = new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"); DocCollection stateV2 = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json");
ZkWriteCommand c2 = new ZkWriteCommand("c1", stateV2); ZkWriteCommand c2 = new ZkWriteCommand("c1", stateV2);
writer.enqueueUpdate(reader.getClusterState(), c2, null); writer.enqueueUpdate(reader.getClusterState(), c2, null);
writer.writePendingUpdates(); writer.writePendingUpdates();
@ -125,12 +122,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
if (explicitRefresh) { if (explicitRefresh) {
reader.forceUpdateCollection("c1"); reader.forceUpdateCollection("c1");
} else { } else {
for (int i = 0; i < 1000; ++i) { reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null && c.getStateFormat() == 2);
if (reader.getClusterState().getCollection("c1").getStateFormat() == 2) {
break;
}
Thread.sleep(50);
}
} }
DocCollection collection = reader.getClusterState().getCollection("c1"); DocCollection collection = reader.getClusterState().getCollection("c1");
@ -166,7 +158,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
// create new collection with stateFormat = 2 // create new collection with stateFormat = 2
ZkWriteCommand c1 = new ZkWriteCommand("c1", ZkWriteCommand c1 = new ZkWriteCommand("c1",
new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"));
writer.enqueueUpdate(reader.getClusterState(), c1, null); writer.enqueueUpdate(reader.getClusterState(), c1, null);
writer.writePendingUpdates(); writer.writePendingUpdates();
reader.forceUpdateCollection("c1"); reader.forceUpdateCollection("c1");
@ -216,7 +208,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
// create new collection with stateFormat = 2 // create new collection with stateFormat = 2
DocCollection state = new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE + "/c1/state.json"); DocCollection state = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE + "/c1/state.json");
ZkWriteCommand wc = new ZkWriteCommand("c1", state); ZkWriteCommand wc = new ZkWriteCommand("c1", state);
writer.enqueueUpdate(reader.getClusterState(), wc, null); writer.enqueueUpdate(reader.getClusterState(), wc, null);
writer.writePendingUpdates(); writer.writePendingUpdates();
@ -224,14 +216,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true)); assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true));
//reader.forceUpdateCollection("c1"); //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"); ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1");
assertNotNull(ref); assertNotNull(ref);
assertFalse(ref.isLazilyLoaded()); assertFalse(ref.isLazilyLoaded());

View File

@ -515,10 +515,8 @@ public class ZkStateReader implements Closeable {
String coll = watchEntry.getKey(); String coll = watchEntry.getKey();
CollectionWatch collWatch = watchEntry.getValue(); CollectionWatch collWatch = watchEntry.getValue();
ClusterState.CollectionRef ref = this.legacyCollectionStates.get(coll); ClusterState.CollectionRef ref = this.legacyCollectionStates.get(coll);
if (ref == null)
continue;
// legacy collections are always in-memory // legacy collections are always in-memory
DocCollection oldState = ref.get(); DocCollection oldState = ref == null ? null : ref.get();
ClusterState.CollectionRef newRef = loadedData.getCollectionStates().get(coll); ClusterState.CollectionRef newRef = loadedData.getCollectionStates().get(coll);
DocCollection newState = newRef == null ? null : newRef.get(); DocCollection newState = newRef == null ? null : newRef.get();
if (!collWatch.stateWatchers.isEmpty() if (!collWatch.stateWatchers.isEmpty()
@ -1156,17 +1154,17 @@ public class ZkStateReader implements Closeable {
v.stateWatchers.add(stateWatcher); v.stateWatchers.add(stateWatcher);
return v; return v;
}); });
if (watchSet.get()) { if (watchSet.get()) {
new StateWatcher(collection).refreshAndWatch(); new StateWatcher(collection).refreshAndWatch();
synchronized (getUpdateLock()) { synchronized (getUpdateLock()) {
constructState(); constructState();
} }
} }
else {
DocCollection state = clusterState.getCollectionOrNull(collection); DocCollection state = clusterState.getCollectionOrNull(collection);
if (stateWatcher.onStateChanged(liveNodes, state) == true) { if (stateWatcher.onStateChanged(liveNodes, state) == true) {
removeCollectionStateWatcher(collection, stateWatcher); removeCollectionStateWatcher(collection, stateWatcher);
}
} }
} }