This is an automated email from the ASF dual-hosted git repository.
dsmiley 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 425a2dbd6c4 Tests: MiniSolrCloudCluster.waitForActiveCollection
considers slice state (#4936)
425a2dbd6c4 is described below
commit 425a2dbd6c4d816ab6f41c5951f634616405d39c
Author: David Smiley <[email protected]>
AuthorDate: Wed Sep 23 22:24:33 2026 -0400
Tests: MiniSolrCloudCluster.waitForActiveCollection considers slice state
(#4936)
MiniSolrCloudCluster.waitForActiveCollection() only checked replica state,
never the owning slice's state — so it could report a collection "active" while
a slice was still mid-restore/mid-split, causing an intermittent 510 on the
very next query.
Co-authored-by: Claude Sonnet 5 <[email protected]>
---
.../apache/solr/cloud/MiniSolrCloudCluster.java | 24 ++++++++++++++++++++--
.../org/apache/solr/cloud/SolrCloudTestCase.java | 13 +-----------
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git
a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
index 7aba36a9188..1338cf6c94b 100644
---
a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
+++
b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
@@ -895,16 +895,23 @@ public class MiniSolrCloudCluster implements SolrBackend {
}
}
+ /**
+ * Matches when the collection has exactly {@code expectedShards} {@link
+ * org.apache.solr.common.cloud.Slice.State#ACTIVE} slices, and exactly
{@code expectedReplicas}
+ * active replicas across them. Slices in any other state (e.g. a split
parent, or a slice under
+ * construction during a restore) and their replicas are not counted.
+ */
public static CollectionStatePredicate expectedShardsAndActiveReplicas(
int expectedShards, int expectedReplicas) {
return (liveNodes, collectionState) -> {
if (collectionState == null) return false;
- if (collectionState.getSlices().size() != expectedShards) {
+ Collection<Slice> activeSlices = collectionState.getActiveSlices();
+ if (activeSlices.size() != expectedShards) {
return false;
}
int activeReplicas = 0;
- for (Slice slice : collectionState) {
+ for (Slice slice : activeSlices) {
for (Replica replica : slice) {
if (replica.isActive(liveNodes)) {
activeReplicas++;
@@ -915,11 +922,24 @@ public class MiniSolrCloudCluster implements SolrBackend {
};
}
+ /**
+ * Matches when every slice is either {@link
org.apache.solr.common.cloud.Slice.State#ACTIVE} or
+ * {@link org.apache.solr.common.cloud.Slice.State#INACTIVE} (none are
mid-split or mid-restore),
+ * and every replica of the active slices is active.
+ */
public static CollectionStatePredicate expectedActive() {
return (liveNodes, collectionState) -> {
if (collectionState == null) return false;
for (Slice slice : collectionState) {
+ switch (slice.getState()) {
+ case INACTIVE:
+ continue;
+ case ACTIVE:
+ break;
+ default:
+ return false;
+ }
for (Replica replica : slice) {
if (!replica.isActive(liveNodes)) {
return false;
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 dbca1f97ef4..ecd14bef337 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
@@ -318,18 +318,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
*/
public static CollectionStatePredicate activeClusterShape(
int expectedShards, int expectedReplicas) {
- return (liveNodes, collectionState) -> {
- if (collectionState == null) return false;
- if (log.isInfoEnabled()) {
- log.info(
- "active slice count: {} expected: {}",
- collectionState.getActiveSlices().size(),
- expectedShards);
- }
- if (collectionState.getActiveSlices().size() != expectedShards) return
false;
- return compareActiveReplicaCountsForShards(
- expectedReplicas, liveNodes, collectionState.getActiveSlices());
- };
+ return
MiniSolrCloudCluster.expectedShardsAndActiveReplicas(expectedShards,
expectedReplicas);
}
public static LiveNodesPredicate containsLiveNode(String node) {