lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romseyg...@apache.org
Subject lucene-solr:master: Revert "SOLR-9181: Fix test bug in ZkStateReaderTest"
Date Sat, 04 Jun 2016 10:05:57 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master d550b1ca4 -> 1e2ba9fe9


Revert "SOLR-9181: Fix test bug in ZkStateReaderTest"

This reverts commit 950fd913354912f9c84a07dcf60258726d6d6f4f.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/1e2ba9fe
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/1e2ba9fe
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/1e2ba9fe

Branch: refs/heads/master
Commit: 1e2ba9fe9be84f0b5defe4965735eae892fabf7b
Parents: d550b1c
Author: Alan Woodward <romseygeek@apache.org>
Authored: Sat Jun 4 11:05:44 2016 +0100
Committer: Alan Woodward <romseygeek@apache.org>
Committed: Sat Jun 4 11:05:44 2016 +0100

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 +-
 .../solr/cloud/overseer/ZkStateReaderTest.java  | 35 ++++++++++++++------
 .../apache/solr/common/cloud/ZkStateReader.java | 14 ++++----
 3 files changed, 34 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1e2ba9fe/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 49b2a9f..c9f4663 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)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1e2ba9fe/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java
----------------------------------------------------------------------
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.java
index 1e9454a..ad51614 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 = 2
       ZkWriteCommand 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());

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1e2ba9fe/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
----------------------------------------------------------------------
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.java
index 3de0a61..aff5bba 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);
+      }
     }
   }
 


Mime
View raw message