You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/10/28 21:02:56 UTC

[lucene-solr] 03/03: @1059 Harden.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch reference_impl
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 3bcb6f7d270b8fbd6695ea1d7161d153b57f17e6
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Wed Oct 28 16:02:24 2020 -0500

    @1059 Harden.
---
 .../solr/cloud/api/collections/SplitShardCmd.java  | 25 +++++++++++++++++++++-
 .../apache/solr/cloud/CollectionsAPISolrJTest.java |  2 +-
 .../cloud/api/collections/SplitByPrefixTest.java   |  5 +----
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java
index edb51df..4b5d65b 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
@@ -773,7 +774,7 @@ public class SplitShardCmd implements OverseerCollectionMessageHandler.Cmd {
         Collection<Slice> searchSlices = router.getSearchSlicesSingle(splitKey, new ModifiableSolrParams(), collection);
 
         int tryCnt = 0;
-        while (searchSlices.isEmpty() && tryCnt < 50) {
+        while (searchSlices.isEmpty() && tryCnt < 500) {
           tryCnt++;
           clusterState = zkStateReader.getClusterState();
           collection = clusterState.getCollection(collectionName);
@@ -784,6 +785,13 @@ public class SplitShardCmd implements OverseerCollectionMessageHandler.Cmd {
             ParWork.propagateInterrupt(e);
           }
           searchSlices = router.getSearchSlicesSingle(splitKey, new ModifiableSolrParams(), collection);
+          Iterator<Slice> it = searchSlices.iterator();
+          while (it.hasNext()) {
+            if (it.next().getState() != Slice.State.ACTIVE) {
+              searchSlices.clear();
+              break;
+            }
+          }
         }
 
         if (searchSlices.isEmpty()) {
@@ -803,6 +811,21 @@ public class SplitShardCmd implements OverseerCollectionMessageHandler.Cmd {
       }
     } else {
       parentSlice = collection.getSlice(slice.get());
+      int tryCnt = 0;
+      // TODO use zkStateReader#waitFor
+      while (parentSlice.getState() != Slice.State.ACTIVE && tryCnt < 500) {
+        tryCnt++;
+        try {
+          Thread.sleep(100);
+        } catch (InterruptedException e) {
+          ParWork.propagateInterrupt(e);
+        }
+        clusterState = zkStateReader.getClusterState();
+        collection = clusterState.getCollection(collectionName);
+
+        parentSlice = collection.getSlice(slice.get());
+      }
+
     }
 
     if (parentSlice == null) {
diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
index f4c851b..67f89a1 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
@@ -362,7 +362,7 @@ public class CollectionsAPISolrJTest extends SolrCloudTestCase {
     assertTrue(response.isSuccess());
 
     // wait for 5 active shards
-    cluster.waitForActiveCollection(collectionName, 5, 5);
+    cluster.waitForActiveCollection(collectionName, 4, 4);
 
   }
 
diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/SplitByPrefixTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/SplitByPrefixTest.java
index f16336a..ad7352b 100644
--- a/solr/core/src/test/org/apache/solr/cloud/api/collections/SplitByPrefixTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/SplitByPrefixTest.java
@@ -75,7 +75,6 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
   @Override
   public void tearDown() throws Exception {
     super.tearDown();
-    cluster.deleteAllCollections();
   }
 
   public static class Prefix implements Comparable<Prefix> {
@@ -174,7 +173,7 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
     }
     splitShard.process(client);
     cluster.waitForActiveCollection(COLLECTION_NAME, 2, 2);
-    cluster.getZkClient().printLayout();
+
     List<Prefix> prefixes = findPrefixes(20, 0, 0x00ffffff);
     List<Prefix> uniquePrefixes = removeDups(prefixes);
     if (uniquePrefixes.size() % 2 == 1) {  // make it an even sized list so we can split it exactly in two
@@ -198,8 +197,6 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
     splitShard.process(client);
     cluster.waitForActiveCollection(COLLECTION_NAME, 3, 3);
 
-    cluster.getZkClient().printLayout();
-
     // OK, now let's check that the correct split point was chosen
     // We can use the router to find the shards for the middle prefixes and they should be different.