瀏覽代碼

Simplify returnLocalAll handling in ES|QL (#135353)

Ievgen Degtiarenko 3 周之前
父節點
當前提交
fe74aa47c6

+ 2 - 33
server/src/main/java/org/elasticsearch/indices/IndicesExpressionGrouper.java

@@ -11,10 +11,8 @@ package org.elasticsearch.indices;
 
 import org.elasticsearch.action.OriginalIndices;
 import org.elasticsearch.action.support.IndicesOptions;
-import org.elasticsearch.common.Strings;
 
 import java.util.Map;
-import java.util.Set;
 
 /**
  * Interface for grouping index expressions, along with IndicesOptions by cluster alias.
@@ -30,36 +28,7 @@ import java.util.Set;
 public interface IndicesExpressionGrouper {
 
     /**
-     * @param remoteClusterNames Set of configured remote cluster names.
-     * @param indicesOptions IndicesOptions to clarify how the index expression should be parsed/applied
-     * @param indexExpressionCsv Multiple index expressions as CSV string (with no spaces), e.g., "logs1,logs2,cluster-a:logs1".
-     *                           A single index expression is also supported.
-     * @return Map where the key is the cluster alias (for "local" cluster, it is RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY)
-     *         and the value for that cluster from the index expression is an OriginalIndices object.
+     * See {@link org.elasticsearch.transport.RemoteClusterService#groupIndices} for details
      */
-    default Map<String, OriginalIndices> groupIndices(
-        Set<String> remoteClusterNames,
-        IndicesOptions indicesOptions,
-        String indexExpressionCsv
-    ) {
-        return groupIndices(remoteClusterNames, indicesOptions, Strings.splitStringByCommaToArray(indexExpressionCsv));
-    }
-
-    /**
-     * Same behavior as the other groupIndices, except the incoming multiple index expressions must already be
-     * parsed into a String array.
-     * @param remoteClusterNames Set of configured remote cluster names.
-     * @param indicesOptions IndicesOptions to clarify how the index expressions should be parsed/applied
-     * @param indexExpressions Multiple index expressions as string[].
-     * @return Map where the key is the cluster alias (for "local" cluster, it is RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY)
-     *         and the value for that cluster from the index expression is an OriginalIndices object.
-     */
-    Map<String, OriginalIndices> groupIndices(Set<String> remoteClusterNames, IndicesOptions indicesOptions, String[] indexExpressions);
-
-    /**
-     * Returns a set of currently configured remote clusters.
-     */
-    default Set<String> getConfiguredClusters() {
-        return Set.of();
-    }
+    Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indexExpressions, boolean returnLocalAll);
 }

+ 1 - 5
server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java

@@ -168,6 +168,7 @@ public final class RemoteClusterService extends RemoteClusterAware
         return groupIndices(remoteClusterNames, indicesOptions, indices, true);
     }
 
+    @Override
     public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indices, boolean returnLocalAll) {
         return groupIndices(getRegisteredRemoteClusterNames(), indicesOptions, indices, returnLocalAll);
     }
@@ -176,11 +177,6 @@ public final class RemoteClusterService extends RemoteClusterAware
         return groupIndices(getRegisteredRemoteClusterNames(), indicesOptions, indices, true);
     }
 
-    @Override
-    public Set<String> getConfiguredClusters() {
-        return getRegisteredRemoteClusterNames();
-    }
-
     /**
      * Returns the registered remote cluster names.
      */

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

@@ -23,7 +23,6 @@ import org.elasticsearch.license.XPackLicenseState;
 import org.elasticsearch.transport.ConnectTransportException;
 import org.elasticsearch.transport.NoSuchRemoteClusterException;
 import org.elasticsearch.transport.RemoteClusterAware;
-import org.elasticsearch.transport.RemoteClusterService;
 import org.elasticsearch.transport.RemoteTransportException;
 import org.elasticsearch.xpack.esql.VerificationException;
 import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo;
@@ -340,11 +339,9 @@ public class EsqlCCSUtils {
         }
         try {
             var groupedIndices = indicesGrouper.groupIndices(
-                // indicesGrouper.getConfiguredClusters() might return mutable set that changes as clusters connect or disconnect.
-                // it is copied here so that we have the same resolution when request contains multiple remote cluster patterns with *
-                Set.copyOf(indicesGrouper.getConfiguredClusters()),
                 IndicesOptions.DEFAULT,
-                indexPattern.indexPattern()
+                Strings.splitStringByCommaToArray(indexPattern.indexPattern()),
+                false
             );
 
             executionInfo.clusterInfoInitializing(true);
@@ -363,11 +360,8 @@ public class EsqlCCSUtils {
                 executionInfo.clusterInfoInitializing(false);
             }
 
-            // check if it is a cross-cluster query
-            if (groupedIndices.size() > 1 || groupedIndices.containsKey(RemoteClusterService.LOCAL_CLUSTER_GROUP_KEY) == false) {
-                if (EsqlLicenseChecker.isCcsAllowed(licenseState) == false) {
-                    throw EsqlLicenseChecker.invalidLicenseForCcsException(licenseState);
-                }
+            if (executionInfo.isCrossClusterSearch() && EsqlLicenseChecker.isCcsAllowed(licenseState) == false) {
+                throw EsqlLicenseChecker.invalidLicenseForCcsException(licenseState);
             }
         } catch (NoSuchRemoteClusterException e) {
             if (EsqlLicenseChecker.isCcsAllowed(licenseState)) {

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

@@ -799,11 +799,7 @@ public class EsqlCCSUtilsTests extends ESTestCase {
 
     static class TestIndicesExpressionGrouper implements IndicesExpressionGrouper {
         @Override
-        public Map<String, OriginalIndices> groupIndices(
-            Set<String> remoteClusterNames,
-            IndicesOptions indicesOptions,
-            String[] indexExpressions
-        ) {
+        public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indexExpressions, boolean returnLocalAll) {
             final Map<String, OriginalIndices> originalIndicesMap = new HashMap<>();
             final String localKey = RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY;
 

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

@@ -157,7 +157,7 @@ public class PlanExecutorMetricsTests extends ESTestCase {
         // test a failed query: xyz field doesn't exist
         request.query("from test | stats m = max(xyz)");
         EsqlSession.PlanRunner runPhase = (p, r) -> fail("this shouldn't happen");
-        IndicesExpressionGrouper groupIndicesByCluster = (remoteClusterNames, indicesOptions, indexExpressions) -> Map.of(
+        IndicesExpressionGrouper groupIndicesByCluster = (indicesOptions, indexExpressions, returnLocalAll) -> Map.of(
             "",
             new OriginalIndices(new String[] { "test" }, IndicesOptions.DEFAULT)
         );