33
33
import org .elasticsearch .cluster .routing .ShardIterator ;
34
34
import org .elasticsearch .cluster .routing .ShardRouting ;
35
35
import org .elasticsearch .cluster .routing .ShardRoutingState ;
36
+ import org .elasticsearch .cluster .routing .TestShardRouting ;
36
37
import org .elasticsearch .cluster .routing .allocation .AllocationService ;
37
38
import org .elasticsearch .cluster .routing .allocation .FailedRerouteAllocation ;
38
39
import org .elasticsearch .cluster .routing .allocation .RoutingAllocation ;
39
40
import org .elasticsearch .cluster .routing .allocation .decider .ClusterRebalanceAllocationDecider ;
40
- import org .elasticsearch .common .settings .Settings ;
41
41
import org .elasticsearch .test .ESAllocationTestCase ;
42
42
import org .junit .Before ;
43
43
@@ -95,7 +95,9 @@ public void testDuplicateFailuresAreOkay() throws Exception {
95
95
}
96
96
97
97
public void testNonExistentShardsAreMarkedAsSuccessful () throws Exception {
98
- List <ShardStateAction .ShardRoutingEntry > tasks = createNonExistentShards ("test non existent shards are marked as successful" );
98
+ String reason = "test non existent shards are marked as successful" ;
99
+ ClusterState currentState = createClusterStateWithStartedShards (reason );
100
+ List <ShardStateAction .ShardRoutingEntry > tasks = createNonExistentShards (currentState , reason );
99
101
ClusterStateTaskExecutor .BatchResult <ShardStateAction .ShardRoutingEntry > result = executor .execute (clusterState , tasks );
100
102
assertTasksSuccessful (tasks , result , clusterState , false );
101
103
}
@@ -104,7 +106,7 @@ public void testTriviallySuccessfulTasksBatchedWithFailingTasks() throws Excepti
104
106
String reason = "test trivially successful tasks batched with failing tasks" ;
105
107
ClusterState currentState = createClusterStateWithStartedShards (reason );
106
108
List <ShardStateAction .ShardRoutingEntry > failingTasks = createExistingShards (currentState , reason );
107
- List <ShardStateAction .ShardRoutingEntry > nonExistentTasks = createNonExistentShards (reason );
109
+ List <ShardStateAction .ShardRoutingEntry > nonExistentTasks = createNonExistentShards (currentState , reason );
108
110
ShardStateAction .ShardFailedClusterStateTaskExecutor failingExecutor = new ShardStateAction .ShardFailedClusterStateTaskExecutor (allocationService , null , logger ) {
109
111
@ Override
110
112
RoutingAllocation .Result applyFailedShards (ClusterState currentState , List <FailedRerouteAllocation .FailedShard > failedShards ) {
@@ -155,14 +157,28 @@ private List<ShardStateAction.ShardRoutingEntry> createExistingShards(ClusterSta
155
157
return toTasks (shardsToFail , indexUUID , reason );
156
158
}
157
159
158
- private List <ShardStateAction .ShardRoutingEntry > createNonExistentShards (String reason ) {
160
+ private List <ShardStateAction .ShardRoutingEntry > createNonExistentShards (ClusterState currentState , String reason ) {
161
+ // add shards from a non-existent index
159
162
MetaData nonExistentMetaData =
160
163
MetaData .builder ()
161
164
.put (IndexMetaData .builder ("non-existent" ).settings (settings (Version .CURRENT )).numberOfShards (1 ).numberOfReplicas (numberOfReplicas ))
162
165
.build ();
163
166
RoutingTable routingTable = RoutingTable .builder ().addAsNew (nonExistentMetaData .index ("non-existent" )).build ();
164
167
String nonExistentIndexUUID = nonExistentMetaData .index ("non-existent" ).getIndexUUID ();
165
- return toTasks (routingTable .allShards (), nonExistentIndexUUID , reason );
168
+
169
+ List <ShardStateAction .ShardRoutingEntry > existingShards = createExistingShards (currentState , reason );
170
+ List <ShardStateAction .ShardRoutingEntry > shardsWithMismatchedAllocationIds = new ArrayList <>();
171
+ for (ShardStateAction .ShardRoutingEntry existingShard : existingShards ) {
172
+ ShardRouting sr = existingShard .getShardRouting ();
173
+ ShardRouting nonExistentShardRouting =
174
+ TestShardRouting .newShardRouting (sr .index (), sr .id (), sr .currentNodeId (), sr .relocatingNodeId (), sr .restoreSource (), sr .primary (), sr .state (), sr .version ());
175
+ shardsWithMismatchedAllocationIds .add (new ShardStateAction .ShardRoutingEntry (nonExistentShardRouting , existingShard .indexUUID , existingShard .message , existingShard .failure ));
176
+ }
177
+
178
+ List <ShardStateAction .ShardRoutingEntry > tasks = new ArrayList <>();
179
+ tasks .addAll (toTasks (routingTable .allShards (), nonExistentIndexUUID , reason ));
180
+ tasks .addAll (shardsWithMismatchedAllocationIds );
181
+ return tasks ;
166
182
}
167
183
168
184
private static void assertTasksSuccessful (
0 commit comments