@@ -412,13 +412,6 @@ public void analyzedPlan(
412412 listener .<PreAnalysisResult >andThen ((l , result ) -> {
413413 // resolve the main indices
414414 preAnalyzeMainIndices (preAnalysis , executionInfo , result , requestFilter , l );
415- }).<PreAnalysisResult >andThen ((l , result ) -> {
416- // TODO in follow-PR (for skip_unavailable handling of missing concrete indexes) add some tests for
417- // invalid index resolution to updateExecutionInfo
418- // If we run out of clusters to search due to unavailability we can stop the analysis right here
419- if (result .indices .isValid () && allCCSClustersSkipped (executionInfo , result , logicalPlanListener )) return ;
420- // whatever tuple we have here (from CCS-special handling or from the original pre-analysis), pass it on to the next step
421- l .onResponse (result );
422415 }).<PreAnalysisResult >andThen ((l , result ) -> {
423416 // first attempt (maybe the only one) at analyzing the plan
424417 analyzeWithRetry (analyzeAction , requestFilter , result , executionInfo , logicalPlanListener , l );
@@ -711,30 +704,6 @@ private void preAnalyzeMainIndices(
711704 }
712705 }
713706
714- /**
715- * Check if there are any clusters to search.
716- *
717- * @return true if there are no clusters to search, false otherwise
718- */
719- private boolean allCCSClustersSkipped (
720- EsqlExecutionInfo executionInfo ,
721- PreAnalysisResult result ,
722- ActionListener <LogicalPlan > logicalPlanListener
723- ) {
724- IndexResolution indexResolution = result .indices ;
725- EsqlCCSUtils .updateExecutionInfoWithUnavailableClusters (executionInfo , indexResolution .failures ());
726- if (executionInfo .isCrossClusterSearch ()
727- && executionInfo .getClusterStates (EsqlExecutionInfo .Cluster .Status .RUNNING ).findAny ().isEmpty ()) {
728- // for a CCS, if all clusters have been marked as SKIPPED, nothing to search so send a sentinel Exception
729- // to let the LogicalPlanActionListener decide how to proceed
730- LOGGER .debug ("No more clusters to search, ending analysis stage" );
731- logicalPlanListener .onFailure (new NoClustersToSearchException ());
732- return true ;
733- }
734-
735- return false ;
736- }
737-
738707 private static void analyzeWithRetry (
739708 CheckedFunction <PreAnalysisResult , LogicalPlan , Exception > analyzeAction ,
740709 QueryBuilder requestFilter ,
@@ -743,6 +712,18 @@ private static void analyzeWithRetry(
743712 ActionListener <LogicalPlan > logicalPlanListener ,
744713 ActionListener <PreAnalysisResult > stepListener
745714 ) {
715+ if (result .indices .isValid ()) {
716+ EsqlCCSUtils .updateExecutionInfoWithUnavailableClusters (executionInfo , result .indices .failures ());
717+ if (executionInfo .isCrossClusterSearch ()
718+ && executionInfo .getClusterStates (EsqlExecutionInfo .Cluster .Status .RUNNING ).findAny ().isEmpty ()) {
719+ // for a CCS, if all clusters have been marked as SKIPPED, nothing to search so send a sentinel Exception
720+ // to let the LogicalPlanActionListener decide how to proceed
721+ LOGGER .debug ("No more clusters to search, ending analysis stage" );
722+ logicalPlanListener .onFailure (new NoClustersToSearchException ());
723+ return ;
724+ }
725+ }
726+
746727 var description = requestFilter == null ? "the only attempt without filter" : "first attempt with filter" ;
747728 LOGGER .debug ("Analyzing the plan ({})" , description );
748729
0 commit comments