Skip to content

Commit 700d01e

Browse files
authored
Adjust BWC for node-level field cap requests (#79301)
Relates #79212
1 parent e86de06 commit 700d01e

File tree

7 files changed

+96
-426
lines changed

7 files changed

+96
-426
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ tasks.register("verifyVersions") {
132132
* after the backport of the backcompat code is complete.
133133
*/
134134

135-
boolean bwc_tests_enabled = false
135+
boolean bwc_tests_enabled = true
136136
// place a PR link here when committing bwc changes:
137-
String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/79301"
137+
String bwc_tests_disabled_issue = ""
138138
/*
139139
* FIPS 140-2 behavior was fixed in 7.11.0. Before that there is no way to run elasticsearch in a
140140
* JVM that is properly configured to be in fips mode with BCFIPS. For now we need to disable

rest-api-spec/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ tasks.named("yamlRestTestV7CompatTransform").configure { task ->
8484

8585
task.replaceValueInMatch("_type", "_doc")
8686
task.addAllowedWarningRegex("\\[types removal\\].*")
87-
task.addAllowedWarning("[transient settings removal] Updating cluster settings through transientSettings is deprecated. Use persistent settings instead.")
8887
task.replaceValueInMatch("nodes.\$node_id.roles.8", "ml", "node_info role test")
8988
task.replaceValueInMatch("nodes.\$node_id.roles.9", "remote_cluster_client", "node_info role test")
9089
task.removeMatch("nodes.\$node_id.roles.10", "node_info role test")

server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesFetcher.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.index.mapper.ObjectMapper;
1515
import org.elasticsearch.index.mapper.RuntimeField;
1616
import org.elasticsearch.index.query.MatchAllQueryBuilder;
17+
import org.elasticsearch.index.query.QueryBuilder;
1718
import org.elasticsearch.index.query.SearchExecutionContext;
1819
import org.elasticsearch.index.shard.IndexShard;
1920
import org.elasticsearch.index.shard.ShardId;
@@ -42,21 +43,21 @@ class FieldCapabilitiesFetcher {
4243
this.indicesService = indicesService;
4344
}
4445

45-
public FieldCapabilitiesIndexResponse fetch(final FieldCapabilitiesIndexRequest request) throws IOException {
46-
final ShardId shardId = request.shardId();
46+
FieldCapabilitiesIndexResponse fetch(ShardId shardId, String[] fieldPatterns, QueryBuilder indexFilter,
47+
long nowInMillis, Map<String, Object> runtimeFields) throws IOException {
4748
final IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
48-
final IndexShard indexShard = indexService.getShard(request.shardId().getId());
49+
final IndexShard indexShard = indexService.getShard(shardId.getId());
4950
try (Engine.Searcher searcher = indexShard.acquireSearcher(Engine.CAN_MATCH_SEARCH_SOURCE)) {
5051

5152
final SearchExecutionContext searchExecutionContext = indexService.newSearchExecutionContext(shardId.id(), 0,
52-
searcher, request::nowInMillis, null, request.runtimeFields());
53+
searcher, () -> nowInMillis, null, runtimeFields);
5354

54-
if (canMatchShard(request, searchExecutionContext) == false) {
55-
return new FieldCapabilitiesIndexResponse(request.index(), Collections.emptyMap(), false);
55+
if (canMatchShard(shardId, indexFilter, nowInMillis, searchExecutionContext) == false) {
56+
return new FieldCapabilitiesIndexResponse(shardId.getIndexName(), Collections.emptyMap(), false);
5657
}
5758

5859
Set<String> fieldNames = new HashSet<>();
59-
for (String pattern : request.fields()) {
60+
for (String pattern : fieldPatterns) {
6061
fieldNames.addAll(searchExecutionContext.getMatchingFieldNames(pattern));
6162
}
6263

@@ -100,17 +101,18 @@ public FieldCapabilitiesIndexResponse fetch(final FieldCapabilitiesIndexRequest
100101
}
101102
}
102103
}
103-
return new FieldCapabilitiesIndexResponse(request.index(), responseMap, true);
104+
return new FieldCapabilitiesIndexResponse(shardId.getIndexName(), responseMap, true);
104105
}
105106
}
106107

107-
private boolean canMatchShard(FieldCapabilitiesIndexRequest req, SearchExecutionContext searchExecutionContext) throws IOException {
108-
if (req.indexFilter() == null || req.indexFilter() instanceof MatchAllQueryBuilder) {
108+
private boolean canMatchShard(ShardId shardId, QueryBuilder indexFilter, long nowInMillis,
109+
SearchExecutionContext searchExecutionContext) throws IOException {
110+
if (indexFilter == null || indexFilter instanceof MatchAllQueryBuilder) {
109111
return true;
110112
}
111-
assert req.nowInMillis() != 0L;
112-
ShardSearchRequest searchRequest = new ShardSearchRequest(req.shardId(), req.nowInMillis(), AliasFilter.EMPTY);
113-
searchRequest.source(new SearchSourceBuilder().query(req.indexFilter()));
113+
assert nowInMillis != 0L;
114+
ShardSearchRequest searchRequest = new ShardSearchRequest(shardId, nowInMillis, AliasFilter.EMPTY);
115+
searchRequest.source(new SearchSourceBuilder().query(indexFilter));
114116
return SearchService.queryStillMatchesAfterRewrite(searchRequest, searchExecutionContext);
115117
}
116118

server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesIndexRequest.java

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

server/src/main/java/org/elasticsearch/action/fieldcaps/RequestDispatcher.java

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
import org.apache.logging.log4j.LogManager;
1212
import org.apache.logging.log4j.Logger;
1313
import org.elasticsearch.ExceptionsHelper;
14-
import org.elasticsearch.Version;
1514
import org.elasticsearch.action.ActionListener;
1615
import org.elasticsearch.action.ActionListenerResponseHandler;
1716
import org.elasticsearch.action.NoShardAvailableActionException;
1817
import org.elasticsearch.action.OriginalIndices;
1918
import org.elasticsearch.cluster.ClusterState;
2019
import org.elasticsearch.cluster.node.DiscoveryNode;
21-
import org.elasticsearch.cluster.node.DiscoveryNodes;
2220
import org.elasticsearch.cluster.routing.GroupShardsIterator;
2321
import org.elasticsearch.cluster.routing.ShardIterator;
2422
import org.elasticsearch.cluster.routing.ShardRouting;
@@ -49,9 +47,6 @@
4947
* Dispatches child field-caps requests to old/new data nodes in the local cluster that have shards of the requesting indices.
5048
*/
5149
final class RequestDispatcher {
52-
53-
static final Version GROUP_REQUESTS_VERSION = Version.V_8_0_0;
54-
5550
static final Logger LOGGER = LogManager.getLogger(RequestDispatcher.class);
5651

5752
private final TransportService transportService;
@@ -128,7 +123,7 @@ private void innerExecute() {
128123
for (Map.Entry<String, IndexSelector> e : indexSelectors.entrySet()) {
129124
final String index = e.getKey();
130125
final IndexSelector indexSelector = e.getValue();
131-
final List<ShardRouting> selectedShards = indexSelector.nextTarget(clusterState.nodes(), hasFilter);
126+
final List<ShardRouting> selectedShards = indexSelector.nextTarget(hasFilter);
132127
if (selectedShards.isEmpty()) {
133128
failedIndices.add(index);
134129
} else {
@@ -163,41 +158,18 @@ int executionRound() {
163158
private void sendRequestToNode(String nodeId, List<ShardId> shardIds) {
164159
final DiscoveryNode node = clusterState.nodes().get(nodeId);
165160
assert node != null;
166-
if (node.getVersion().onOrAfter(GROUP_REQUESTS_VERSION)) {
167-
LOGGER.debug("round {} sends field caps node request to node {} for shardIds {}", executionRound, node, shardIds);
168-
final ActionListener<FieldCapabilitiesNodeResponse> listener =
169-
ActionListener.wrap(r -> onRequestResponse(shardIds, r), failure -> onRequestFailure(shardIds, failure));
170-
final FieldCapabilitiesNodeRequest nodeRequest = new FieldCapabilitiesNodeRequest(
171-
shardIds,
172-
fieldCapsRequest.fields(),
173-
originalIndices,
174-
fieldCapsRequest.indexFilter(),
175-
nowInMillis,
176-
fieldCapsRequest.runtimeFields());
177-
transportService.sendChildRequest(node, TransportFieldCapabilitiesAction.ACTION_NODE_NAME, nodeRequest, parentTask,
178-
TransportRequestOptions.EMPTY, new ActionListenerResponseHandler<>(listener, FieldCapabilitiesNodeResponse::new));
179-
} else {
180-
for (ShardId shardId : shardIds) {
181-
LOGGER.debug("round {} sends field caps shard request to node {} for shardId {}", executionRound, node, shardId);
182-
final ActionListener<FieldCapabilitiesIndexResponse> listener = ActionListener.wrap(
183-
r -> {
184-
final FieldCapabilitiesNodeResponse nodeResponse;
185-
if (r.canMatch()) {
186-
nodeResponse = new FieldCapabilitiesNodeResponse(
187-
Collections.singletonList(r), Collections.emptyMap(), Collections.emptySet());
188-
} else {
189-
nodeResponse = new FieldCapabilitiesNodeResponse(Collections.emptyList(), Collections.emptyMap(),
190-
Collections.singleton(shardId));
191-
}
192-
onRequestResponse(Collections.singletonList(shardId), nodeResponse);
193-
},
194-
e -> onRequestFailure(Collections.singletonList(shardId), e));
195-
final FieldCapabilitiesIndexRequest shardRequest = new FieldCapabilitiesIndexRequest(fieldCapsRequest.fields(), shardId,
196-
originalIndices, fieldCapsRequest.indexFilter(), nowInMillis, fieldCapsRequest.runtimeFields());
197-
transportService.sendChildRequest(node, TransportFieldCapabilitiesAction.ACTION_SHARD_NAME, shardRequest, parentTask,
198-
TransportRequestOptions.EMPTY, new ActionListenerResponseHandler<>(listener, FieldCapabilitiesIndexResponse::new));
199-
}
200-
}
161+
LOGGER.debug("round {} sends field caps node request to node {} for shardIds {}", executionRound, node, shardIds);
162+
final ActionListener<FieldCapabilitiesNodeResponse> listener =
163+
ActionListener.wrap(r -> onRequestResponse(shardIds, r), failure -> onRequestFailure(shardIds, failure));
164+
final FieldCapabilitiesNodeRequest nodeRequest = new FieldCapabilitiesNodeRequest(
165+
shardIds,
166+
fieldCapsRequest.fields(),
167+
originalIndices,
168+
fieldCapsRequest.indexFilter(),
169+
nowInMillis,
170+
fieldCapsRequest.runtimeFields());
171+
transportService.sendChildRequest(node, TransportFieldCapabilitiesAction.ACTION_NODE_NAME, nodeRequest, parentTask,
172+
TransportRequestOptions.EMPTY, new ActionListenerResponseHandler<>(listener, FieldCapabilitiesNodeResponse::new));
201173
}
202174

203175
private void afterRequestsCompleted(int numRequests) {
@@ -274,7 +246,7 @@ synchronized void addUnmatchedShardId(ShardId shardId) {
274246
failures.remove(shardId);
275247
}
276248

277-
synchronized List<ShardRouting> nextTarget(DiscoveryNodes discoveryNodes, boolean withQueryFilter) {
249+
synchronized List<ShardRouting> nextTarget(boolean withQueryFilter) {
278250
if (nodeToShards.isEmpty()) {
279251
return Collections.emptyList();
280252
}
@@ -306,21 +278,8 @@ synchronized List<ShardRouting> nextTarget(DiscoveryNodes discoveryNodes, boolea
306278
} else {
307279
assert unmatchedShardIds.isEmpty();
308280
final Map.Entry<String, List<ShardRouting>> node = nodeIt.next();
309-
// If the target node is on the new version, then we can ask it to process all its copies in a single request
310-
// and the target node will process at most one valid copy. Otherwise, we should ask for a single copy to avoid
311-
// sending multiple requests.
312-
final DiscoveryNode discoNode = discoveryNodes.get(node.getKey());
313-
if (discoNode.getVersion().onOrAfter(GROUP_REQUESTS_VERSION)) {
314-
nodeIt.remove();
315-
return node.getValue();
316-
} else {
317-
final List<ShardRouting> shards = node.getValue();
318-
final ShardRouting selectedShard = shards.remove(0);
319-
if (shards.isEmpty()) {
320-
nodeIt.remove();
321-
}
322-
return Collections.singletonList(selectedShard);
323-
}
281+
nodeIt.remove();
282+
return node.getValue();
324283
}
325284
}
326285
}

server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747

4848
public class TransportFieldCapabilitiesAction extends HandledTransportAction<FieldCapabilitiesRequest, FieldCapabilitiesResponse> {
4949
public static final String ACTION_NODE_NAME = FieldCapabilitiesAction.NAME + "[n]";
50-
public static final String ACTION_SHARD_NAME = FieldCapabilitiesAction.NAME + "[index][s]";
5150

5251
private final ThreadPool threadPool;
5352
private final TransportService transportService;
@@ -72,11 +71,8 @@ public TransportFieldCapabilitiesAction(TransportService transportService,
7271
this.fieldCapabilitiesFetcher = new FieldCapabilitiesFetcher(indicesService);
7372
final Set<String> metadataFields = indicesService.getAllMetadataFields();
7473
this.metadataFieldPred = metadataFields::contains;
75-
7674
transportService.registerRequestHandler(ACTION_NODE_NAME, ThreadPool.Names.MANAGEMENT,
7775
FieldCapabilitiesNodeRequest::new, new NodeTransportHandler());
78-
transportService.registerRequestHandler(ACTION_SHARD_NAME, ThreadPool.Names.SAME,
79-
FieldCapabilitiesIndexRequest::new, new ShardTransportHandler());
8076
}
8177

8278
@Override
@@ -323,10 +319,9 @@ public void messageReceived(FieldCapabilitiesNodeRequest request, TransportChann
323319
final Map<ShardId, Exception> failures = new HashMap<>();
324320
final Set<ShardId> unmatched = new HashSet<>();
325321
for (ShardId shardId : shardIds) {
326-
final FieldCapabilitiesIndexRequest indexRequest = new FieldCapabilitiesIndexRequest(request.fields(), shardId,
327-
request.originalIndices(), request.indexFilter(), request.nowInMillis(), request.runtimeFields());
328322
try {
329-
final FieldCapabilitiesIndexResponse response = fieldCapabilitiesFetcher.fetch(indexRequest);
323+
final FieldCapabilitiesIndexResponse response = fieldCapabilitiesFetcher.fetch(
324+
shardId, request.fields(), request.indexFilter(), request.nowInMillis(), request.runtimeFields());
330325
if (response.canMatch()) {
331326
unmatched.clear();
332327
failures.clear();
@@ -346,13 +341,4 @@ public void messageReceived(FieldCapabilitiesNodeRequest request, TransportChann
346341
});
347342
}
348343
}
349-
350-
private class ShardTransportHandler implements TransportRequestHandler<FieldCapabilitiesIndexRequest> {
351-
@Override
352-
public void messageReceived(FieldCapabilitiesIndexRequest request, TransportChannel channel, Task task) throws Exception {
353-
ActionListener<FieldCapabilitiesIndexResponse> listener = new ChannelActionListener<>(channel, ACTION_SHARD_NAME, request);
354-
ActionListener.completeWith(listener, () -> fieldCapabilitiesFetcher.fetch(request));
355-
}
356-
}
357-
358344
}

0 commit comments

Comments
 (0)