-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Resolve indices using original index pattern and retry the entire resolution #136009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
idegtiarenko
merged 28 commits into
elastic:main
from
idegtiarenko:retry_complete_resolution
Oct 8, 2025
Merged
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e0f5989
resolve original index pattern
idegtiarenko 9e56546
Merge branch 'main' into es-12487
idegtiarenko e172c13
fix csv tests
idegtiarenko 62cb8e9
Merge branch 'main' into es-12487
idegtiarenko d653020
Merge branch 'main' into es-12487
idegtiarenko 21ccd63
returnLocalAll=false
idegtiarenko 24b7a4c
move execution info updates
idegtiarenko b1e75f4
Merge branch 'main' into es-12487
idegtiarenko 3029bfb
resolve using original index pattern
idegtiarenko 58c8230
assert original index expression in error
idegtiarenko ee777a4
[CI] Update transport version definitions
06bfcfa
upd
idegtiarenko 3c9a40b
Merge branch 'main' into es-12487
idegtiarenko cf31115
fix flakiness
idegtiarenko e9a0e29
Merge branch 'main' into es-12487
idegtiarenko 880f169
Merge branch 'main' into es-12487
idegtiarenko 444217d
Merge branch 'main' into es-12487
idegtiarenko e5254ec
update comment
idegtiarenko 685830f
Merge branch 'main' into es-12487
idegtiarenko adaa593
Merge branch 'main' into es-12487
idegtiarenko ef36c2e
Retry the entire index resolution without filter
idegtiarenko 8640d59
add an integration test
idegtiarenko 6561b92
Merge branch 'main' into retry_complete_resolution
idegtiarenko 028469d
Merge branch 'main' into retry_complete_resolution
idegtiarenko fc72d1e
additional test case
idegtiarenko 2e2021c
Merge branch 'main' into retry_complete_resolution
idegtiarenko a996b25
use mutable list
idegtiarenko 2f5dbce
Merge branch 'main' into retry_complete_resolution
idegtiarenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,9 @@ | |
| import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder; | ||
| import org.elasticsearch.client.internal.Client; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.index.IndexMode; | ||
| import org.elasticsearch.index.IndexSettings; | ||
| import org.elasticsearch.index.query.TermQueryBuilder; | ||
| import org.elasticsearch.xpack.core.enrich.EnrichPolicy; | ||
| import org.elasticsearch.xpack.core.enrich.action.ExecuteEnrichPolicyAction; | ||
| import org.elasticsearch.xpack.core.enrich.action.PutEnrichPolicyAction; | ||
|
|
@@ -28,6 +31,7 @@ | |
|
|
||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList; | ||
| import static org.elasticsearch.xpack.esql.action.EsqlQueryRequest.syncEsqlQueryRequest; | ||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.empty; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
@@ -557,6 +561,42 @@ public void testLookupJoinFieldTypes() throws IOException { | |
| } | ||
| } | ||
|
|
||
| public void testLookupJoinRetryAnalysis() throws IOException { | ||
| setupClusters(3); | ||
| setSkipUnavailable(REMOTE_CLUSTER_1, false); | ||
| setSkipUnavailable(REMOTE_CLUSTER_2, false); | ||
|
|
||
| var defaultSettings = Settings.builder(); | ||
| createIndexWithDocument(LOCAL_CLUSTER, "data", defaultSettings, Map.of("key", 1, "f1", 1)); | ||
| createIndexWithDocument(REMOTE_CLUSTER_1, "data", defaultSettings, Map.of("key", 2, "f2", 2)); | ||
| createIndexWithDocument(REMOTE_CLUSTER_2, "data", defaultSettings, Map.of("key", 3, "f3", 3)); | ||
|
|
||
| var lookupSettings = Settings.builder().put(IndexSettings.MODE.getKey(), IndexMode.LOOKUP); | ||
| createIndexWithDocument(LOCAL_CLUSTER, "lookup", lookupSettings, Map.of("key", 1, "location", "local")); | ||
| createIndexWithDocument(REMOTE_CLUSTER_1, "lookup", lookupSettings, Map.of("key", 2, "location", "remote-1")); | ||
| // lookup is intentionally absent on REMOTE_CLUSTER_2 | ||
|
|
||
| // The following query uses filter f2=2 that narrows down execution only to REMOTE_CLUSTER_1 index however, | ||
| // later it uses `WHERE f1 == 1` esql condition that to an attribute present only on the local cluster index. | ||
| // This causes analysis to fail and retry the entire query without a filter. | ||
| // The second analysis executes against all cluster indices and should discover that lookup is absent on REMOTE_CLUSTER_2. | ||
| expectThrows( | ||
| VerificationException.class, | ||
| containsString("lookup index [lookup] is not available in remote cluster [remote-b]"), | ||
| () -> runQuery( | ||
| syncEsqlQueryRequest().query("FROM data,*:data | LOOKUP JOIN lookup ON key | WHERE f1 == 1") | ||
| .filter(new TermQueryBuilder("f2", 2)) | ||
| ) | ||
| ); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test would fail if we only retry previously resolved subset of clusters opposed to ones resolved to all clusters without the filter. |
||
| } | ||
|
|
||
| private void createIndexWithDocument(String clusterAlias, String indexName, Settings.Builder settings, Map<String, Object> source) { | ||
| var client = client(clusterAlias); | ||
| client.admin().indices().prepareCreate(indexName).setSettings(settings).get(); | ||
| client.prepareIndex(indexName).setSource(source).get(); | ||
| client.admin().indices().prepareRefresh(indexName).get(); | ||
| } | ||
|
|
||
| protected Map<String, Object> setupClustersAndLookups() throws IOException { | ||
| var setupData = setupClusters(2); | ||
| populateLookupIndex(LOCAL_CLUSTER, "values_lookup", 10); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -439,7 +439,20 @@ public void analyzedPlan( | |
|
|
||
| var preAnalysis = preAnalyzer.preAnalyze(parsed); | ||
| var result = FieldNameUtils.resolveFieldNames(parsed, preAnalysis.enriches().isEmpty() == false); | ||
| var description = requestFilter == null ? "the only attempt without filter" : "first attempt with filter"; | ||
|
|
||
| resolveIndices(parsed, executionInfo, description, requestFilter, preAnalysis, result, logicalPlanListener); | ||
| } | ||
|
|
||
| private void resolveIndices( | ||
| LogicalPlan parsed, | ||
| EsqlExecutionInfo executionInfo, | ||
| String description, | ||
| QueryBuilder requestFilter, | ||
| PreAnalyzer.PreAnalysis preAnalysis, | ||
| PreAnalysisResult result, | ||
| ActionListener<LogicalPlan> logicalPlanListener | ||
| ) { | ||
| EsqlCCSUtils.initCrossClusterState(indicesExpressionGrouper, verifier.licenseState(), preAnalysis.indexPattern(), executionInfo); | ||
|
|
||
| SubscribableListener.<PreAnalysisResult>newForked(l -> preAnalyzeMainIndices(preAnalysis, executionInfo, result, requestFilter, l)) | ||
|
|
@@ -459,7 +472,7 @@ public void analyzedPlan( | |
| .<PreAnalysisResult>andThen((l, r) -> { | ||
| inferenceService.inferenceResolver(functionRegistry).resolveInferenceIds(parsed, l.map(r::withInferenceResolution)); | ||
| }) | ||
| .<LogicalPlan>andThen((l, r) -> analyzeWithRetry(parsed, requestFilter, preAnalysis, executionInfo, r, l)) | ||
| .<LogicalPlan>andThen((l, r) -> analyzeWithRetry(parsed, executionInfo, description, requestFilter, preAnalysis, r, l)) | ||
| .addListener(logicalPlanListener); | ||
| } | ||
|
|
||
|
|
@@ -695,15 +708,14 @@ private void preAnalyzeMainIndices( | |
| ThreadPool.Names.SYSTEM_READ | ||
| ); | ||
| if (preAnalysis.indexPattern() != null) { | ||
| String indexExpressionToResolve = EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo); | ||
| if (indexExpressionToResolve.isEmpty()) { | ||
| // if this was a pure remote CCS request (no local indices) and all remotes are offline, return an empty IndexResolution | ||
| if (executionInfo.clusterAliases().isEmpty()) { | ||
| // return empty resolution if the expression is pure CCS and resolved no remote clusters (like no-such-cluster*:index) | ||
| listener.onResponse( | ||
| result.withIndices(IndexResolution.valid(new EsIndex(preAnalysis.indexPattern().indexPattern(), Map.of(), Map.of()))) | ||
| ); | ||
| } else { | ||
| indexResolver.resolveAsMergedMapping( | ||
| indexExpressionToResolve, | ||
| preAnalysis.indexPattern().indexPattern(), | ||
| result.fieldNames, | ||
| // Maybe if no indices are returned, retry without index mode and provide a clearer error message. | ||
| switch (preAnalysis.indexMode()) { | ||
|
|
@@ -732,13 +744,13 @@ private void preAnalyzeMainIndices( | |
|
|
||
| private void analyzeWithRetry( | ||
| LogicalPlan parsed, | ||
| EsqlExecutionInfo executionInfo, | ||
| String description, | ||
| QueryBuilder requestFilter, | ||
| PreAnalyzer.PreAnalysis preAnalysis, | ||
| EsqlExecutionInfo executionInfo, | ||
| PreAnalysisResult result, | ||
| ActionListener<LogicalPlan> listener | ||
| ) { | ||
| var description = requestFilter == null ? "the only attempt without filter" : "first attempt with filter"; | ||
| LOGGER.debug("Analyzing the plan ({})", description); | ||
| try { | ||
| if (result.indices.isValid() || requestFilter != null) { | ||
|
|
@@ -756,20 +768,9 @@ private void analyzeWithRetry( | |
| // if the initial request didn't have a filter, then just pass the exception back to the user | ||
| listener.onFailure(ve); | ||
| } else { | ||
| // retrying and make the index resolution work without any index filtering. | ||
| preAnalyzeMainIndices(preAnalysis, executionInfo, result, null, listener.delegateFailure((l, r) -> { | ||
| LOGGER.debug("Analyzing the plan (second attempt, without filter)"); | ||
| try { | ||
| // the order here is tricky - if the cluster has been filtered and later became unavailable, | ||
| // do we want to declare it successful or skipped? For now, unavailability takes precedence. | ||
| EsqlCCSUtils.updateExecutionInfoWithClustersWithNoMatchingIndices(executionInfo, r.indices, false); | ||
| LogicalPlan plan = analyzedPlan(parsed, r, executionInfo); | ||
| LOGGER.debug("Analyzed plan (second attempt without filter):\n{}", plan); | ||
| l.onResponse(plan); | ||
| } catch (Exception e) { | ||
| l.onFailure(e); | ||
| } | ||
| })); | ||
| // retrying the index resolution without index filtering. | ||
| executionInfo.clusterInfo.clear(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| resolveIndices(parsed, executionInfo, "second attempt, without filter", null, preAnalysis, result, listener); | ||
| } | ||
| } catch (Exception e) { | ||
| listener.onFailure(e); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder: please add the other use case without join we've discussed.