You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ho...@apache.org on 2024/03/27 20:20:21 UTC

(solr) branch branch_9x updated: SOLR-17200: Fix false positive race condition in during core loading

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

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


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 4a7b931a652 SOLR-17200: Fix false positive race condition in  during core loading
4a7b931a652 is described below

commit 4a7b931a652a6ddc71a1975c366137ae1d0ec5f0
Author: Chris Hostetter <ho...@apache.org>
AuthorDate: Wed Mar 27 14:44:51 2024 -0500

    SOLR-17200: Fix false positive race condition in  during core loading
    
    (cherry picked from commit 2def20abfe85d77f1fcd42a24d01c77b9ee07b82)
---
 solr/CHANGES.txt                                             |  2 ++
 solr/core/src/java/org/apache/solr/core/CoreContainer.java   |  4 ++++
 .../org/apache/solr/handler/admin/HealthCheckHandler.java    | 12 ++++++++++--
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b14878942ef..523baa44509 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -72,6 +72,8 @@ Bug Fixes
 
 * SOLR-17113: Correct how `/replication?command=details` describes errors in backup operations.  (Przemyslaw Ciezkowski via Christine Poerschke and Jason Gerlowski)
 
+* SOLR-17200: Fix false positive race condition in `/health?requireHealthyCores=true` during core loading (hossman)
+
 Dependency Upgrades
 ---------------------
 
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index 86cb52f0710..7e4046b814e 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -2460,6 +2460,10 @@ public class CoreContainer {
     return status;
   }
 
+  public boolean isStatusLoadComplete() {
+    return LOAD_COMPLETE == (getStatus() & LOAD_COMPLETE);
+  }
+
   public boolean hideStackTrace() {
     return cfg.hideStackTraces();
   }
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/HealthCheckHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/HealthCheckHandler.java
index 3f5c8442b47..a3724aa626c 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/HealthCheckHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/HealthCheckHandler.java
@@ -149,9 +149,17 @@ public class HealthCheckHandler extends RequestHandlerBase {
 
     // Optionally require that all cores on this node are active if param 'requireHealthyCores=true'
     if (req.getParams().getBool(PARAM_REQUIRE_HEALTHY_CORES, false)) {
+      if (!coreContainer.isStatusLoadComplete()) {
+        rsp.add(STATUS, FAILURE);
+        rsp.setException(
+            new SolrException(
+                SolrException.ErrorCode.SERVICE_UNAVAILABLE,
+                "Host Unavailable: Core Loading not complete"));
+        return;
+      }
       Collection<CloudDescriptor> coreDescriptors =
-          coreContainer.getCores().stream()
-              .map(c -> c.getCoreDescriptor().getCloudDescriptor())
+          coreContainer.getCoreDescriptors().stream()
+              .map(cd -> cd.getCloudDescriptor())
               .collect(Collectors.toList());
       long unhealthyCores = findUnhealthyCores(coreDescriptors, clusterState);
       if (unhealthyCores > 0) {