Skip to content

Commit ef36c2e

Browse files
committed
Retry the entire index resolution without filter
1 parent adaa593 commit ef36c2e

File tree

1 file changed

+19
-17
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session

1 file changed

+19
-17
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,20 @@ public void analyzedPlan(
439439

440440
var preAnalysis = preAnalyzer.preAnalyze(parsed);
441441
var result = FieldNameUtils.resolveFieldNames(parsed, preAnalysis.enriches().isEmpty() == false);
442+
var description = requestFilter == null ? "the only attempt without filter" : "first attempt with filter";
443+
444+
resolveIndices(parsed, executionInfo, description, requestFilter, preAnalysis, result, logicalPlanListener);
445+
}
442446

447+
private void resolveIndices(
448+
LogicalPlan parsed,
449+
EsqlExecutionInfo executionInfo,
450+
String description,
451+
QueryBuilder requestFilter,
452+
PreAnalyzer.PreAnalysis preAnalysis,
453+
PreAnalysisResult result,
454+
ActionListener<LogicalPlan> logicalPlanListener
455+
) {
443456
EsqlCCSUtils.initCrossClusterState(indicesExpressionGrouper, verifier.licenseState(), preAnalysis.indexPattern(), executionInfo);
444457

445458
SubscribableListener.<PreAnalysisResult>newForked(l -> preAnalyzeMainIndices(preAnalysis, executionInfo, result, requestFilter, l))
@@ -459,7 +472,7 @@ public void analyzedPlan(
459472
.<PreAnalysisResult>andThen((l, r) -> {
460473
inferenceService.inferenceResolver(functionRegistry).resolveInferenceIds(parsed, l.map(r::withInferenceResolution));
461474
})
462-
.<LogicalPlan>andThen((l, r) -> analyzeWithRetry(parsed, requestFilter, preAnalysis, executionInfo, r, l))
475+
.<LogicalPlan>andThen((l, r) -> analyzeWithRetry(parsed, executionInfo, description, requestFilter, preAnalysis, r, l))
463476
.addListener(logicalPlanListener);
464477
}
465478

@@ -731,13 +744,13 @@ private void preAnalyzeMainIndices(
731744

732745
private void analyzeWithRetry(
733746
LogicalPlan parsed,
747+
EsqlExecutionInfo executionInfo,
748+
String description,
734749
QueryBuilder requestFilter,
735750
PreAnalyzer.PreAnalysis preAnalysis,
736-
EsqlExecutionInfo executionInfo,
737751
PreAnalysisResult result,
738752
ActionListener<LogicalPlan> listener
739753
) {
740-
var description = requestFilter == null ? "the only attempt without filter" : "first attempt with filter";
741754
LOGGER.debug("Analyzing the plan ({})", description);
742755
try {
743756
if (result.indices.isValid() || requestFilter != null) {
@@ -755,20 +768,9 @@ private void analyzeWithRetry(
755768
// if the initial request didn't have a filter, then just pass the exception back to the user
756769
listener.onFailure(ve);
757770
} else {
758-
// retrying and make the index resolution work without any index filtering.
759-
preAnalyzeMainIndices(preAnalysis, executionInfo, result, null, listener.delegateFailure((l, r) -> {
760-
LOGGER.debug("Analyzing the plan (second attempt, without filter)");
761-
try {
762-
// the order here is tricky - if the cluster has been filtered and later became unavailable,
763-
// do we want to declare it successful or skipped? For now, unavailability takes precedence.
764-
EsqlCCSUtils.updateExecutionInfoWithClustersWithNoMatchingIndices(executionInfo, r.indices, false);
765-
LogicalPlan plan = analyzedPlan(parsed, r, executionInfo);
766-
LOGGER.debug("Analyzed plan (second attempt without filter):\n{}", plan);
767-
l.onResponse(plan);
768-
} catch (Exception e) {
769-
l.onFailure(e);
770-
}
771-
}));
771+
// retrying the index resolution without index filtering.
772+
executionInfo.clusterInfo.clear();
773+
resolveIndices(parsed, executionInfo, "second attempt, without filter", null, preAnalysis, result, listener);
772774
}
773775
} catch (Exception e) {
774776
listener.onFailure(e);

0 commit comments

Comments
 (0)