You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by il...@apache.org on 2023/11/07 08:51:12 UTC

(solr) branch main updated: SOLR-17067 SolrCloudTestCase activeClusterShape() only counts active replicas of active shards (#2063)

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

ilan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 0e91b7c82ee SOLR-17067 SolrCloudTestCase activeClusterShape() only counts active replicas of active shards (#2063)
0e91b7c82ee is described below

commit 0e91b7c82ee4e97df8ed4bed575646de7981d2c1
Author: Ilan Ginzburg <il...@murblanc.org>
AuthorDate: Tue Nov 7 09:51:06 2023 +0100

    SOLR-17067 SolrCloudTestCase activeClusterShape() only counts active replicas of active shards (#2063)
---
 .../test/org/apache/solr/cloud/SplitShardTest.java |  7 +++----
 .../solr/cloud/SplitShardWithNodeRoleTest.java     |  8 ++++++--
 .../cloud/api/collections/SplitByPrefixTest.java   | 13 ++++++------
 .../org/apache/solr/cloud/SolrCloudTestCase.java   | 24 ++++++++++++++++------
 4 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
index 1e93dade6bc..31788138430 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
@@ -99,7 +99,7 @@ public class SplitShardTest extends SolrCloudTestCase {
                 .getActiveSlices()
                 .size(),
         COLLECTION_NAME,
-        activeClusterShape(6, 7));
+        activeClusterShape(6, 6));
 
     try {
       splitShard =
@@ -163,7 +163,7 @@ public class SplitShardTest extends SolrCloudTestCase {
                 .getActiveSlices()
                 .size(),
         collectionName,
-        activeClusterShape(3, 4));
+        activeClusterShape(3, 3));
     DocCollection coll = cluster.getSolrClient().getClusterState().getCollection(collectionName);
     Slice s1_0 = coll.getSlice("shard1_0");
     Slice s1_1 = coll.getSlice("shard1_1");
@@ -277,8 +277,7 @@ public class SplitShardTest extends SolrCloudTestCase {
           "Timed out waiting for sub shards to be active.",
           collectionName,
           activeClusterShape(
-              2,
-              3 * repFactor)); // 2 repFactor for the new split shards, 1 repFactor for old replicas
+              2, 2 * repFactor)); // parent shard replicas are ignored by activeClusterShape
 
       // make sure that docs were indexed during the split
       assertTrue(model.size() > docCount);
diff --git a/solr/core/src/test/org/apache/solr/cloud/SplitShardWithNodeRoleTest.java b/solr/core/src/test/org/apache/solr/cloud/SplitShardWithNodeRoleTest.java
index d698758cd06..eb15bd44420 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SplitShardWithNodeRoleTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SplitShardWithNodeRoleTest.java
@@ -84,9 +84,13 @@ public class SplitShardWithNodeRoleTest extends SolrCloudTestCase {
 
     ur.commit(client, collName);
 
+    final int numSubShards = 2;
     CollectionAdminRequest.SplitShard splitShard =
-        CollectionAdminRequest.splitShard(collName).setShardName("shard1");
+        CollectionAdminRequest.splitShard(collName)
+            .setShardName("shard1")
+            .setNumSubShards(numSubShards);
     splitShard.process(cluster.getSolrClient());
+    int totalShards = shard + (numSubShards - 1);
     waitForState(
         "Timed out waiting for sub shards to be active. Number of active shards="
             + cluster
@@ -96,6 +100,6 @@ public class SplitShardWithNodeRoleTest extends SolrCloudTestCase {
                 .getActiveSlices()
                 .size(),
         collName,
-        activeClusterShape(shard + 1, 3 * (nrtReplica + pullReplica)));
+        activeClusterShape(totalShards, totalShards * (nrtReplica + pullReplica)));
   }
 }
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 a09b350ecd1..77947d017df 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
@@ -164,11 +164,12 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
       splitShard.setAsyncId("SPLIT1");
     }
     splitShard.process(client);
-    // expectedReplicas==3 because original replica still exists (just inactive)
+    // expectedReplicas==2 because original replica still exists and active but its shard is
+    // inactive
     waitForState(
         "Timed out waiting for sub shards to be active.",
         COLLECTION_NAME,
-        activeClusterShape(2, 3));
+        activeClusterShape(2, 2));
 
     List<Prefix> prefixes = findPrefixes(20, 0, 0x00ffffff);
     List<Prefix> uniquePrefixes = removeDups(prefixes);
@@ -195,7 +196,7 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
     waitForState(
         "Timed out waiting for sub shards to be active.",
         COLLECTION_NAME,
-        activeClusterShape(3, 5));
+        activeClusterShape(3, 3));
 
     // 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
@@ -238,7 +239,7 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
     waitForState(
         "Timed out waiting for sub shards to be active.",
         COLLECTION_NAME,
-        activeClusterShape(4, 7));
+        activeClusterShape(4, 4));
 
     collection = client.getClusterState().getCollection(COLLECTION_NAME);
     slices1 =
@@ -266,7 +267,7 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
     waitForState(
         "Timed out waiting for sub shards to be active.",
         COLLECTION_NAME,
-        activeClusterShape(5, 9));
+        activeClusterShape(5, 5));
 
     collection = client.getClusterState().getCollection(COLLECTION_NAME);
     slices1 =
@@ -289,7 +290,7 @@ public class SplitByPrefixTest extends SolrCloudTestCase {
     waitForState(
         "Timed out waiting for sub shards to be active.",
         COLLECTION_NAME,
-        activeClusterShape(6, 11));
+        activeClusterShape(6, 6));
 
     collection = client.getClusterState().getCollection(COLLECTION_NAME);
     slices1 =
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
index 7856a5e3a53..85c3477fc03 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.lang.invoke.MethodHandles;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -181,19 +182,20 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
 
   /**
    * Return a {@link CollectionStatePredicate} that returns true if a collection has the expected
-   * number of shards and active replicas
+   * numbers of shards and active replicas
    */
   public static CollectionStatePredicate clusterShape(int expectedShards, int expectedReplicas) {
     return (liveNodes, collectionState) -> {
       if (collectionState == null) return false;
       if (collectionState.getSlices().size() != expectedShards) return false;
-      return compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState);
+      return compareActiveReplicaCountsForShards(
+          expectedReplicas, liveNodes, collectionState.getSlices());
     };
   }
 
   /**
    * Return a {@link CollectionStatePredicate} that returns true if a collection has the expected
-   * number of active shards and active replicas
+   * numbers of active shards and active replicas on these shards
    */
   public static CollectionStatePredicate activeClusterShape(
       int expectedShards, int expectedReplicas) {
@@ -206,7 +208,8 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
             expectedShards);
       }
       if (collectionState.getActiveSlices().size() != expectedShards) return false;
-      return compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState);
+      return compareActiveReplicaCountsForShards(
+          expectedReplicas, liveNodes, collectionState.getActiveSlices());
     };
   }
 
@@ -235,10 +238,19 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
     };
   }
 
+  /**
+   * Checks if the actual count of active replicas on a set of nodes for a collection of shards
+   * matches the expected count
+   *
+   * @param expectedReplicas number of active replicas expected by the test
+   * @param liveNodes nodes on which the active replicas should be counted
+   * @param slices collection of slices whose replicas should be counted
+   * @return true if the actual count of active replicas matches the expected count
+   */
   private static boolean compareActiveReplicaCountsForShards(
-      int expectedReplicas, Set<String> liveNodes, DocCollection collectionState) {
+      int expectedReplicas, Set<String> liveNodes, Collection<Slice> slices) {
     int activeReplicas = 0;
-    for (Slice slice : collectionState) {
+    for (Slice slice : slices) {
       for (Replica replica : slice) {
         if (replica.isActive(liveNodes)) {
           activeReplicas++;