File tree 2 files changed +10
-7
lines changed
server/src/main/java/org/elasticsearch/cluster/routing
2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,10 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
105
105
// create the target initializing shard routing on the node the shard is relocating to
106
106
allInitializingShards .add (shard .getTargetRelocatingShard ());
107
107
allAllocationIds .add (shard .getTargetRelocatingShard ().allocationId ().getId ());
108
+
109
+ assert shard .assignedToNode () : "relocating from unassigned " + shard ;
110
+ assert shard .getTargetRelocatingShard ().assignedToNode () : "relocating to unassigned " + shard .getTargetRelocatingShard ();
111
+ assignedShards .add (shard .getTargetRelocatingShard ());
108
112
}
109
113
if (shard .assignedToNode ()) {
110
114
assignedShards .add (shard );
@@ -211,7 +215,7 @@ public List<ShardRouting> getActiveShards() {
211
215
}
212
216
213
217
/**
214
- * Returns a {@link List} of assigned shards
218
+ * Returns a {@link List} of assigned shards, including relocation targets
215
219
*
216
220
* @return a {@link List} of shards
217
221
*/
@@ -518,11 +522,6 @@ public ShardRouting getByAllocationId(String allocationId) {
518
522
if (shardRouting .allocationId ().getId ().equals (allocationId )) {
519
523
return shardRouting ;
520
524
}
521
- if (shardRouting .relocating ()) {
522
- if (shardRouting .getTargetRelocatingShard ().allocationId ().getId ().equals (allocationId )) {
523
- return shardRouting .getTargetRelocatingShard ();
524
- }
525
- }
526
525
}
527
526
return null ;
528
527
}
Original file line number Diff line number Diff line change @@ -194,9 +194,13 @@ private IndexMetaData.Builder updateInSyncAllocations(RoutingTable newRoutingTab
194
194
// of replicas was decreased while shards were unassigned.
195
195
int maxActiveShards = oldIndexMetaData .getNumberOfReplicas () + 1 ; // +1 for the primary
196
196
IndexShardRoutingTable newShardRoutingTable = newRoutingTable .shardRoutingTable (shardId );
197
+ assert newShardRoutingTable .assignedShards ().stream ()
198
+ .filter (ShardRouting ::isRelocationTarget ).map (s -> s .allocationId ().getId ()).noneMatch (inSyncAllocationIds ::contains )
199
+ : newShardRoutingTable .assignedShards () + " vs " + inSyncAllocationIds ;
197
200
if (inSyncAllocationIds .size () > oldInSyncAllocationIds .size () && inSyncAllocationIds .size () > maxActiveShards ) {
198
201
// trim entries that have no corresponding shard routing in the cluster state (i.e. trim unavailable copies)
199
- List <ShardRouting > assignedShards = newShardRoutingTable .assignedShards ();
202
+ List <ShardRouting > assignedShards = newShardRoutingTable .assignedShards ()
203
+ .stream ().filter (s -> s .isRelocationTarget () == false ).collect (Collectors .toList ());
200
204
assert assignedShards .size () <= maxActiveShards :
201
205
"cannot have more assigned shards " + assignedShards + " than maximum possible active shards " + maxActiveShards ;
202
206
Set <String > assignedAllocations = assignedShards .stream ().map (s -> s .allocationId ().getId ()).collect (Collectors .toSet ());
You can’t perform that action at this time.
0 commit comments