Skip to content

Commit 7bdaebb

Browse files
committed
Merge branch 'main' into handle-9/deprecate-node-attrs-v2-follow-up
2 parents 7ce49fc + 2e84950 commit 7bdaebb

File tree

25 files changed

+375
-334
lines changed

25 files changed

+375
-334
lines changed

docs/changelog/121260.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121260
2+
summary: Introduce a pre-mapping logical plan processing step
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

muted-tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,6 @@ tests:
231231
- class: org.elasticsearch.datastreams.DataStreamsClientYamlTestSuiteIT
232232
method: test {p0=data_stream/140_data_stream_aliases/Create data stream aliases using wildcard expression}
233233
issue: https://github.com/elastic/elasticsearch/issues/120890
234-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
235-
method: test {p0=ml/inference_crud/*}
236-
issue: https://github.com/elastic/elasticsearch/issues/120816
237234
- class: org.elasticsearch.xpack.security.authc.service.ServiceAccountIT
238235
method: testAuthenticateShouldNotFallThroughInCaseOfFailure
239236
issue: https://github.com/elastic/elasticsearch/issues/120902
@@ -330,6 +327,10 @@ tests:
330327
method: testCrossClusterAsyncQueryStop
331328
issue: https://github.com/elastic/elasticsearch/issues/121249
332329
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
330+
method: test {p0=transform/*}
331+
issue: https://github.com/elastic/elasticsearch/issues/120816
332+
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
333+
method: test {p0=ml/*}
333334
issue: https://github.com/elastic/elasticsearch/issues/120816
334335
- class: org.elasticsearch.upgrades.VectorSearchIT
335336
method: testBBQVectorSearch {upgradedNodes=0}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.admin.indices.mapping.put;
11+
12+
import org.apache.logging.log4j.Level;
13+
import org.elasticsearch.action.support.master.AcknowledgedResponse;
14+
import org.elasticsearch.test.ESSingleNodeTestCase;
15+
import org.elasticsearch.test.MockLog;
16+
import org.elasticsearch.test.junit.annotations.TestLogging;
17+
18+
import static org.hamcrest.Matchers.equalTo;
19+
20+
public class PutMappingIT extends ESSingleNodeTestCase {
21+
22+
@TestLogging(
23+
reason = "testing DEBUG logging",
24+
value = "org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction:DEBUG"
25+
)
26+
public void testFailureLogging() {
27+
final var indexName = randomIdentifier();
28+
createIndex(indexName);
29+
final var fieldName = randomIdentifier();
30+
safeGet(client().execute(TransportPutMappingAction.TYPE, new PutMappingRequest(indexName).source(fieldName, "type=keyword")));
31+
MockLog.assertThatLogger(
32+
() -> assertThat(
33+
asInstanceOf(
34+
IllegalArgumentException.class,
35+
safeAwaitFailure(
36+
AcknowledgedResponse.class,
37+
l -> client().execute(
38+
TransportPutMappingAction.TYPE,
39+
new PutMappingRequest(indexName).source(fieldName, "type=long"),
40+
l
41+
)
42+
)
43+
).getMessage(),
44+
equalTo("mapper [" + fieldName + "] cannot be changed from type [keyword] to [long]")
45+
),
46+
TransportPutMappingAction.class,
47+
new MockLog.SeenEventExpectation(
48+
"failure message",
49+
TransportPutMappingAction.class.getCanonicalName(),
50+
Level.DEBUG,
51+
"failed to put mappings on indices [[" + indexName
52+
)
53+
);
54+
}
55+
}

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.elasticsearch.threadpool.ThreadPool;
3737
import org.elasticsearch.transport.TransportService;
3838

39-
import java.io.IOException;
4039
import java.util.ArrayList;
4140
import java.util.Arrays;
4241
import java.util.List;
@@ -126,7 +125,7 @@ protected void masterOperation(
126125

127126
performMappingUpdate(concreteIndices, request, listener, metadataMappingService, false);
128127
} catch (IndexNotFoundException ex) {
129-
logger.debug(() -> "failed to put mappings on indices [" + Arrays.asList(request.indices() + "]"), ex);
128+
logger.debug(() -> "failed to put mappings on indices " + Arrays.toString(request.indices()), ex);
130129
throw ex;
131130
}
132131
}
@@ -162,25 +161,21 @@ static void performMappingUpdate(
162161
MetadataMappingService metadataMappingService,
163162
boolean autoUpdate
164163
) {
165-
final ActionListener<AcknowledgedResponse> wrappedListener = listener.delegateResponse((l, e) -> {
166-
logger.debug(() -> "failed to put mappings on indices [" + Arrays.asList(concreteIndices) + "]", e);
164+
ActionListener.run(listener.delegateResponse((l, e) -> {
165+
logger.debug(() -> "failed to put mappings on indices " + Arrays.toString(concreteIndices), e);
167166
l.onFailure(e);
168-
});
169-
final PutMappingClusterStateUpdateRequest updateRequest;
170-
try {
171-
updateRequest = new PutMappingClusterStateUpdateRequest(
172-
request.masterNodeTimeout(),
173-
request.ackTimeout(),
174-
request.source(),
175-
autoUpdate,
176-
concreteIndices
177-
);
178-
} catch (IOException e) {
179-
wrappedListener.onFailure(e);
180-
return;
181-
}
182-
183-
metadataMappingService.putMapping(updateRequest, wrappedListener);
167+
}),
168+
wrappedListener -> metadataMappingService.putMapping(
169+
new PutMappingClusterStateUpdateRequest(
170+
request.masterNodeTimeout(),
171+
request.ackTimeout(),
172+
request.source(),
173+
autoUpdate,
174+
concreteIndices
175+
),
176+
wrappedListener
177+
)
178+
);
184179
}
185180

186181
static String checkForFailureStoreViolations(ClusterState clusterState, Index[] concreteIndices, PutMappingRequest request) {

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataMappingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class MetadataMappingService {
5656
public MetadataMappingService(ClusterService clusterService, IndicesService indicesService) {
5757
this.clusterService = clusterService;
5858
this.indicesService = indicesService;
59-
taskQueue = clusterService.createTaskQueue("put-mapping", Priority.HIGH, new PutMappingExecutor());
59+
this.taskQueue = clusterService.createTaskQueue("put-mapping", Priority.HIGH, new PutMappingExecutor());
6060
}
6161

6262
record PutMappingClusterStateUpdateTask(PutMappingClusterStateUpdateRequest request, ActionListener<AcknowledgedResponse> listener)

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/util/Holder.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public void set(T value) {
2626
this.value = value;
2727
}
2828

29+
/**
30+
* Sets a value in the holder, but only if none has already been set.
31+
* @param value the new value to set.
32+
*/
33+
public void setIfAbsent(T value) {
34+
if (this.value == null) {
35+
this.value = value;
36+
}
37+
}
38+
2939
public T get() {
3040
return value;
3141
}

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.apache.lucene.sandbox.document.HalfFloatPoint;
1212
import org.apache.lucene.util.BytesRef;
1313
import org.elasticsearch.ExceptionsHelper;
14+
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
15+
import org.elasticsearch.cluster.service.ClusterService;
1416
import org.elasticsearch.common.Strings;
1517
import org.elasticsearch.common.breaker.CircuitBreaker;
1618
import org.elasticsearch.common.breaker.NoopCircuitBreaker;
@@ -31,9 +33,11 @@
3133
import org.elasticsearch.geo.ShapeTestUtils;
3234
import org.elasticsearch.index.IndexMode;
3335
import org.elasticsearch.license.XPackLicenseState;
36+
import org.elasticsearch.search.SearchService;
3437
import org.elasticsearch.tasks.TaskCancelledException;
3538
import org.elasticsearch.test.ESTestCase;
3639
import org.elasticsearch.transport.RemoteTransportException;
40+
import org.elasticsearch.transport.TransportService;
3741
import org.elasticsearch.xcontent.json.JsonXContent;
3842
import org.elasticsearch.xpack.esql.action.EsqlQueryResponse;
3943
import org.elasticsearch.xpack.esql.analysis.EnrichResolution;
@@ -72,8 +76,8 @@
7276
import org.elasticsearch.xpack.esql.plan.logical.local.LocalSupplier;
7377
import org.elasticsearch.xpack.esql.plugin.EsqlPlugin;
7478
import org.elasticsearch.xpack.esql.plugin.QueryPragmas;
79+
import org.elasticsearch.xpack.esql.plugin.TransportActionServices;
7580
import org.elasticsearch.xpack.esql.session.Configuration;
76-
import org.elasticsearch.xpack.esql.session.QueryBuilderResolver;
7781
import org.elasticsearch.xpack.esql.stats.SearchStats;
7882
import org.elasticsearch.xpack.esql.telemetry.Metrics;
7983
import org.elasticsearch.xpack.versionfield.Version;
@@ -140,6 +144,7 @@
140144
import static org.hamcrest.Matchers.instanceOf;
141145
import static org.junit.Assert.assertNotNull;
142146
import static org.junit.Assert.assertNull;
147+
import static org.mockito.Mockito.mock;
143148

144149
public final class EsqlTestUtils {
145150

@@ -360,7 +365,14 @@ public static LogicalOptimizerContext unboundLogicalOptimizerContext() {
360365

361366
public static final Verifier TEST_VERIFIER = new Verifier(new Metrics(new EsqlFunctionRegistry()), new XPackLicenseState(() -> 0L));
362367

363-
public static final QueryBuilderResolver MOCK_QUERY_BUILDER_RESOLVER = new MockQueryBuilderResolver();
368+
public static final TransportActionServices MOCK_TRANSPORT_ACTION_SERVICES = new TransportActionServices(
369+
mock(TransportService.class),
370+
mock(SearchService.class),
371+
null,
372+
mock(ClusterService.class),
373+
mock(IndexNameExpressionResolver.class),
374+
null
375+
);
364376

365377
private EsqlTestUtils() {}
366378

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/MockQueryBuilderResolver.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/MatchFunctionIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void testWhereMatchWithRow() {
246246
var error = expectThrows(ElasticsearchException.class, () -> run(query));
247247
assertThat(
248248
error.getMessage(),
249-
containsString("[MATCH] function cannot operate on [\"a brown fox\"], which is not a field from an index mapping")
249+
containsString("line 2:15: [MATCH] function cannot operate on [content], which is not a field from an index mapping")
250250
);
251251
}
252252

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/MatchOperatorIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public void testWhereMatchWithRow() {
230230
var error = expectThrows(ElasticsearchException.class, () -> run(query));
231231
assertThat(
232232
error.getMessage(),
233-
containsString("[:] operator cannot operate on [\"a brown fox\"], which is not a field from an index mapping")
233+
containsString("line 2:9: [:] operator cannot operate on [content], which is not a field from an index mapping")
234234
);
235235
}
236236

0 commit comments

Comments
 (0)