Skip to content

Commit fe74aa4

Browse files
authored
Simplify returnLocalAll handling in ES|QL (elastic#135353)
1 parent afd10f4 commit fe74aa4

File tree

5 files changed

+9
-54
lines changed

5 files changed

+9
-54
lines changed

server/src/main/java/org/elasticsearch/indices/IndicesExpressionGrouper.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111

1212
import org.elasticsearch.action.OriginalIndices;
1313
import org.elasticsearch.action.support.IndicesOptions;
14-
import org.elasticsearch.common.Strings;
1514

1615
import java.util.Map;
17-
import java.util.Set;
1816

1917
/**
2018
* Interface for grouping index expressions, along with IndicesOptions by cluster alias.
@@ -30,36 +28,7 @@
3028
public interface IndicesExpressionGrouper {
3129

3230
/**
33-
* @param remoteClusterNames Set of configured remote cluster names.
34-
* @param indicesOptions IndicesOptions to clarify how the index expression should be parsed/applied
35-
* @param indexExpressionCsv Multiple index expressions as CSV string (with no spaces), e.g., "logs1,logs2,cluster-a:logs1".
36-
* A single index expression is also supported.
37-
* @return Map where the key is the cluster alias (for "local" cluster, it is RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY)
38-
* and the value for that cluster from the index expression is an OriginalIndices object.
31+
* See {@link org.elasticsearch.transport.RemoteClusterService#groupIndices} for details
3932
*/
40-
default Map<String, OriginalIndices> groupIndices(
41-
Set<String> remoteClusterNames,
42-
IndicesOptions indicesOptions,
43-
String indexExpressionCsv
44-
) {
45-
return groupIndices(remoteClusterNames, indicesOptions, Strings.splitStringByCommaToArray(indexExpressionCsv));
46-
}
47-
48-
/**
49-
* Same behavior as the other groupIndices, except the incoming multiple index expressions must already be
50-
* parsed into a String array.
51-
* @param remoteClusterNames Set of configured remote cluster names.
52-
* @param indicesOptions IndicesOptions to clarify how the index expressions should be parsed/applied
53-
* @param indexExpressions Multiple index expressions as string[].
54-
* @return Map where the key is the cluster alias (for "local" cluster, it is RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY)
55-
* and the value for that cluster from the index expression is an OriginalIndices object.
56-
*/
57-
Map<String, OriginalIndices> groupIndices(Set<String> remoteClusterNames, IndicesOptions indicesOptions, String[] indexExpressions);
58-
59-
/**
60-
* Returns a set of currently configured remote clusters.
61-
*/
62-
default Set<String> getConfiguredClusters() {
63-
return Set.of();
64-
}
33+
Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indexExpressions, boolean returnLocalAll);
6534
}

server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public Map<String, OriginalIndices> groupIndices(Set<String> remoteClusterNames,
168168
return groupIndices(remoteClusterNames, indicesOptions, indices, true);
169169
}
170170

171+
@Override
171172
public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indices, boolean returnLocalAll) {
172173
return groupIndices(getRegisteredRemoteClusterNames(), indicesOptions, indices, returnLocalAll);
173174
}
@@ -176,11 +177,6 @@ public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions,
176177
return groupIndices(getRegisteredRemoteClusterNames(), indicesOptions, indices, true);
177178
}
178179

179-
@Override
180-
public Set<String> getConfiguredClusters() {
181-
return getRegisteredRemoteClusterNames();
182-
}
183-
184180
/**
185181
* Returns the registered remote cluster names.
186182
*/

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.transport.ConnectTransportException;
2424
import org.elasticsearch.transport.NoSuchRemoteClusterException;
2525
import org.elasticsearch.transport.RemoteClusterAware;
26-
import org.elasticsearch.transport.RemoteClusterService;
2726
import org.elasticsearch.transport.RemoteTransportException;
2827
import org.elasticsearch.xpack.esql.VerificationException;
2928
import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo;
@@ -340,11 +339,9 @@ public static void initCrossClusterState(
340339
}
341340
try {
342341
var groupedIndices = indicesGrouper.groupIndices(
343-
// indicesGrouper.getConfiguredClusters() might return mutable set that changes as clusters connect or disconnect.
344-
// it is copied here so that we have the same resolution when request contains multiple remote cluster patterns with *
345-
Set.copyOf(indicesGrouper.getConfiguredClusters()),
346342
IndicesOptions.DEFAULT,
347-
indexPattern.indexPattern()
343+
Strings.splitStringByCommaToArray(indexPattern.indexPattern()),
344+
false
348345
);
349346

350347
executionInfo.clusterInfoInitializing(true);
@@ -363,11 +360,8 @@ public static void initCrossClusterState(
363360
executionInfo.clusterInfoInitializing(false);
364361
}
365362

366-
// check if it is a cross-cluster query
367-
if (groupedIndices.size() > 1 || groupedIndices.containsKey(RemoteClusterService.LOCAL_CLUSTER_GROUP_KEY) == false) {
368-
if (EsqlLicenseChecker.isCcsAllowed(licenseState) == false) {
369-
throw EsqlLicenseChecker.invalidLicenseForCcsException(licenseState);
370-
}
363+
if (executionInfo.isCrossClusterSearch() && EsqlLicenseChecker.isCcsAllowed(licenseState) == false) {
364+
throw EsqlLicenseChecker.invalidLicenseForCcsException(licenseState);
371365
}
372366
} catch (NoSuchRemoteClusterException e) {
373367
if (EsqlLicenseChecker.isCcsAllowed(licenseState)) {

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtilsTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,11 +799,7 @@ private XPackLicenseStatus inactiveLicenseStatus(License.OperationMode operation
799799

800800
static class TestIndicesExpressionGrouper implements IndicesExpressionGrouper {
801801
@Override
802-
public Map<String, OriginalIndices> groupIndices(
803-
Set<String> remoteClusterNames,
804-
IndicesOptions indicesOptions,
805-
String[] indexExpressions
806-
) {
802+
public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indexExpressions, boolean returnLocalAll) {
807803
final Map<String, OriginalIndices> originalIndicesMap = new HashMap<>();
808804
final String localKey = RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY;
809805

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/telemetry/PlanExecutorMetricsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void testFailedMetric() {
157157
// test a failed query: xyz field doesn't exist
158158
request.query("from test | stats m = max(xyz)");
159159
EsqlSession.PlanRunner runPhase = (p, r) -> fail("this shouldn't happen");
160-
IndicesExpressionGrouper groupIndicesByCluster = (remoteClusterNames, indicesOptions, indexExpressions) -> Map.of(
160+
IndicesExpressionGrouper groupIndicesByCluster = (indicesOptions, indexExpressions, returnLocalAll) -> Map.of(
161161
"",
162162
new OriginalIndices(new String[] { "test" }, IndicesOptions.DEFAULT)
163163
);

0 commit comments

Comments
 (0)