Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

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.
Expand All @@ -30,36 +28,7 @@
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public Map<String, OriginalIndices> groupIndices(Set<String> remoteClusterNames,
return groupIndices(remoteClusterNames, indicesOptions, indices, true);
}

@Override
public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indices, boolean returnLocalAll) {
return groupIndices(getRegisteredRemoteClusterNames(), indicesOptions, indices, returnLocalAll);
}
Expand All @@ -176,11 +177,6 @@ public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions,
return groupIndices(getRegisteredRemoteClusterNames(), indicesOptions, indices, true);
}

@Override
public Set<String> getConfiguredClusters() {
return getRegisteredRemoteClusterNames();
}

/**
* Returns the registered remote cluster names.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;
Expand Down Expand Up @@ -340,11 +339,9 @@ public static void initCrossClusterState(
}
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);
Expand All @@ -363,11 +360,8 @@ public static void initCrossClusterState(
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,7 @@ private XPackLicenseStatus inactiveLicenseStatus(License.OperationMode operation

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void testFailedMetric() {
// 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)
);
Expand Down