|
11 | 11 | import org.apache.logging.log4j.LogManager; |
12 | 12 | import org.apache.logging.log4j.Logger; |
13 | 13 | import org.elasticsearch.ExceptionsHelper; |
14 | | -import org.elasticsearch.Version; |
15 | 14 | import org.elasticsearch.action.ActionListener; |
16 | 15 | import org.elasticsearch.action.ActionListenerResponseHandler; |
17 | 16 | import org.elasticsearch.action.NoShardAvailableActionException; |
18 | 17 | import org.elasticsearch.action.OriginalIndices; |
19 | 18 | import org.elasticsearch.cluster.ClusterState; |
20 | 19 | import org.elasticsearch.cluster.node.DiscoveryNode; |
21 | | -import org.elasticsearch.cluster.node.DiscoveryNodes; |
22 | 20 | import org.elasticsearch.cluster.routing.GroupShardsIterator; |
23 | 21 | import org.elasticsearch.cluster.routing.ShardIterator; |
24 | 22 | import org.elasticsearch.cluster.routing.ShardRouting; |
|
49 | 47 | * Dispatches child field-caps requests to old/new data nodes in the local cluster that have shards of the requesting indices. |
50 | 48 | */ |
51 | 49 | final class RequestDispatcher { |
52 | | - |
53 | | - static final Version GROUP_REQUESTS_VERSION = Version.V_8_0_0; |
54 | | - |
55 | 50 | static final Logger LOGGER = LogManager.getLogger(RequestDispatcher.class); |
56 | 51 |
|
57 | 52 | private final TransportService transportService; |
@@ -128,7 +123,7 @@ private void innerExecute() { |
128 | 123 | for (Map.Entry<String, IndexSelector> e : indexSelectors.entrySet()) { |
129 | 124 | final String index = e.getKey(); |
130 | 125 | final IndexSelector indexSelector = e.getValue(); |
131 | | - final List<ShardRouting> selectedShards = indexSelector.nextTarget(clusterState.nodes(), hasFilter); |
| 126 | + final List<ShardRouting> selectedShards = indexSelector.nextTarget(hasFilter); |
132 | 127 | if (selectedShards.isEmpty()) { |
133 | 128 | failedIndices.add(index); |
134 | 129 | } else { |
@@ -163,41 +158,18 @@ int executionRound() { |
163 | 158 | private void sendRequestToNode(String nodeId, List<ShardId> shardIds) { |
164 | 159 | final DiscoveryNode node = clusterState.nodes().get(nodeId); |
165 | 160 | 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)); |
201 | 173 | } |
202 | 174 |
|
203 | 175 | private void afterRequestsCompleted(int numRequests) { |
@@ -274,7 +246,7 @@ synchronized void addUnmatchedShardId(ShardId shardId) { |
274 | 246 | failures.remove(shardId); |
275 | 247 | } |
276 | 248 |
|
277 | | - synchronized List<ShardRouting> nextTarget(DiscoveryNodes discoveryNodes, boolean withQueryFilter) { |
| 249 | + synchronized List<ShardRouting> nextTarget(boolean withQueryFilter) { |
278 | 250 | if (nodeToShards.isEmpty()) { |
279 | 251 | return Collections.emptyList(); |
280 | 252 | } |
@@ -306,21 +278,8 @@ synchronized List<ShardRouting> nextTarget(DiscoveryNodes discoveryNodes, boolea |
306 | 278 | } else { |
307 | 279 | assert unmatchedShardIds.isEmpty(); |
308 | 280 | 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(); |
324 | 283 | } |
325 | 284 | } |
326 | 285 | } |
|
0 commit comments