19
19
20
20
package org .elasticsearch .cluster .routing ;
21
21
22
- import org .apache .logging .log4j .LogManager ;
23
- import org .apache .logging .log4j .Logger ;
24
22
import org .elasticsearch .Version ;
25
23
import org .elasticsearch .cluster .ClusterState ;
26
24
import org .elasticsearch .cluster .metadata .IndexMetaData ;
33
31
import org .elasticsearch .common .settings .Settings ;
34
32
import org .elasticsearch .index .IndexNotFoundException ;
35
33
import org .elasticsearch .index .shard .ShardId ;
36
- import org .elasticsearch .index .shard .ShardNotFoundException ;
37
34
import org .elasticsearch .node .ResponseCollectorService ;
38
35
39
36
import java .util .ArrayList ;
47
44
48
45
public class OperationRouting {
49
46
50
- private static final Logger logger = LogManager .getLogger (OperationRouting .class );
51
-
52
47
public static final Setting <Boolean > USE_ADAPTIVE_REPLICA_SELECTION_SETTING =
53
48
Setting .boolSetting ("cluster.routing.use_adaptive_replica_selection" , true ,
54
49
Setting .Property .Dynamic , Setting .Property .NodeScope );
@@ -129,7 +124,7 @@ private Set<IndexShardRoutingTable> computeTargetedShards(ClusterState clusterSt
129
124
for (String r : effectiveRouting ) {
130
125
final int routingPartitionSize = indexMetaData .getRoutingPartitionSize ();
131
126
for (int partitionOffset = 0 ; partitionOffset < routingPartitionSize ; partitionOffset ++) {
132
- set .add (shardRoutingTable (indexRouting , calculateScaledShardId (indexMetaData , r , partitionOffset )));
127
+ set .add (RoutingTable . shardRoutingTable (indexRouting , calculateScaledShardId (indexMetaData , r , partitionOffset )));
133
128
}
134
129
}
135
130
} else {
@@ -146,15 +141,7 @@ private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable index
146
141
@ Nullable ResponseCollectorService collectorService ,
147
142
@ Nullable Map <String , Long > nodeCounts ) {
148
143
if (preference == null || preference .isEmpty ()) {
149
- if (awarenessAttributes .isEmpty ()) {
150
- if (useAdaptiveReplicaSelection ) {
151
- return indexShard .activeInitializingShardsRankedIt (collectorService , nodeCounts );
152
- } else {
153
- return indexShard .activeInitializingShardsRandomIt ();
154
- }
155
- } else {
156
- return indexShard .preferAttributesActiveInitializingShardsIt (awarenessAttributes , nodes );
157
- }
144
+ return shardRoutings (indexShard , nodes , collectorService , nodeCounts );
158
145
}
159
146
if (preference .charAt (0 ) == '_' ) {
160
147
Preference preferenceType = Preference .parse (preference );
@@ -181,15 +168,7 @@ private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable index
181
168
}
182
169
// no more preference
183
170
if (index == -1 || index == preference .length () - 1 ) {
184
- if (awarenessAttributes .isEmpty ()) {
185
- if (useAdaptiveReplicaSelection ) {
186
- return indexShard .activeInitializingShardsRankedIt (collectorService , nodeCounts );
187
- } else {
188
- return indexShard .activeInitializingShardsRandomIt ();
189
- }
190
- } else {
191
- return indexShard .preferAttributesActiveInitializingShardsIt (awarenessAttributes , nodes );
192
- }
171
+ return shardRoutings (indexShard , nodes , collectorService , nodeCounts );
193
172
} else {
194
173
// update the preference and continue
195
174
preference = preference .substring (index + 1 );
@@ -232,12 +211,17 @@ private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable index
232
211
}
233
212
}
234
213
235
- private IndexShardRoutingTable shardRoutingTable (IndexRoutingTable indexRouting , int shardId ) {
236
- IndexShardRoutingTable indexShard = indexRouting .shard (shardId );
237
- if (indexShard == null ) {
238
- throw new ShardNotFoundException (new ShardId (indexRouting .getIndex (), shardId ));
214
+ private ShardIterator shardRoutings (IndexShardRoutingTable indexShard , DiscoveryNodes nodes ,
215
+ @ Nullable ResponseCollectorService collectorService , @ Nullable Map <String , Long > nodeCounts ) {
216
+ if (awarenessAttributes .isEmpty ()) {
217
+ if (useAdaptiveReplicaSelection ) {
218
+ return indexShard .activeInitializingShardsRankedIt (collectorService , nodeCounts );
219
+ } else {
220
+ return indexShard .activeInitializingShardsRandomIt ();
221
+ }
222
+ } else {
223
+ return indexShard .preferAttributesActiveInitializingShardsIt (awarenessAttributes , nodes );
239
224
}
240
- return indexShard ;
241
225
}
242
226
243
227
protected IndexRoutingTable indexRoutingTable (ClusterState clusterState , String index ) {
0 commit comments