File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed
server/src/main/java/org/elasticsearch/cluster/routing Expand file tree Collapse file tree 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> {
105105 // create the target initializing shard routing on the node the shard is relocating to
106106 allInitializingShards .add (shard .getTargetRelocatingShard ());
107107 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 ());
108112 }
109113 if (shard .assignedToNode ()) {
110114 assignedShards .add (shard );
@@ -211,7 +215,7 @@ public List<ShardRouting> getActiveShards() {
211215 }
212216
213217 /**
214- * Returns a {@link List} of assigned shards
218+ * Returns a {@link List} of assigned shards, including relocation targets
215219 *
216220 * @return a {@link List} of shards
217221 */
@@ -518,11 +522,6 @@ public ShardRouting getByAllocationId(String allocationId) {
518522 if (shardRouting .allocationId ().getId ().equals (allocationId )) {
519523 return shardRouting ;
520524 }
521- if (shardRouting .relocating ()) {
522- if (shardRouting .getTargetRelocatingShard ().allocationId ().getId ().equals (allocationId )) {
523- return shardRouting .getTargetRelocatingShard ();
524- }
525- }
526525 }
527526 return null ;
528527 }
Original file line number Diff line number Diff line change @@ -194,9 +194,13 @@ private IndexMetaData.Builder updateInSyncAllocations(RoutingTable newRoutingTab
194194 // of replicas was decreased while shards were unassigned.
195195 int maxActiveShards = oldIndexMetaData .getNumberOfReplicas () + 1 ; // +1 for the primary
196196 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 ;
197200 if (inSyncAllocationIds .size () > oldInSyncAllocationIds .size () && inSyncAllocationIds .size () > maxActiveShards ) {
198201 // 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 ());
200204 assert assignedShards .size () <= maxActiveShards :
201205 "cannot have more assigned shards " + assignedShards + " than maximum possible active shards " + maxActiveShards ;
202206 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