23
23
import java .util .ArrayList ;
24
24
import java .util .Collections ;
25
25
import java .util .HashMap ;
26
+ import java .util .HashSet ;
26
27
import java .util .List ;
27
28
import java .util .Map ;
29
+ import java .util .Set ;
28
30
29
31
/**
30
32
* PrimaryShardBatchAllocator is similar to {@link org.opensearch.gateway.PrimaryShardAllocator} only difference is
@@ -82,6 +84,7 @@ public AllocateUnassignedDecision makeAllocationDecision(ShardRouting unassigned
82
84
* @param allocation the allocation state container object
83
85
*/
84
86
public void allocateUnassignedBatch (List <ShardRouting > shardRoutings , RoutingAllocation allocation ) {
87
+ logger .trace ("Starting shard allocation execution for unassigned primary shards: {}" , shardRoutings .size ());
85
88
HashMap <ShardId , AllocateUnassignedDecision > ineligibleShardAllocationDecisions = new HashMap <>();
86
89
List <ShardRouting > eligibleShards = new ArrayList <>();
87
90
List <ShardRouting > inEligibleShards = new ArrayList <>();
@@ -99,12 +102,13 @@ public void allocateUnassignedBatch(List<ShardRouting> shardRoutings, RoutingAll
99
102
// only fetch data for eligible shards
100
103
final FetchResult <NodeGatewayStartedShardsBatch > shardsState = fetchData (eligibleShards , inEligibleShards , allocation );
101
104
105
+ Set <ShardRouting > batchShardRoutingSet = new HashSet <>(shardRoutings );
102
106
RoutingNodes .UnassignedShards .UnassignedIterator iterator = allocation .routingNodes ().unassigned ().iterator ();
103
107
while (iterator .hasNext ()) {
104
108
ShardRouting unassignedShard = iterator .next ();
105
109
AllocateUnassignedDecision allocationDecision ;
106
110
107
- if (shardRoutings .contains (unassignedShard )) {
111
+ if (unassignedShard . primary () && batchShardRoutingSet .contains (unassignedShard )) {
108
112
assert unassignedShard .primary ();
109
113
if (ineligibleShardAllocationDecisions .containsKey (unassignedShard .shardId ())) {
110
114
allocationDecision = ineligibleShardAllocationDecisions .get (unassignedShard .shardId ());
@@ -115,6 +119,7 @@ public void allocateUnassignedBatch(List<ShardRouting> shardRoutings, RoutingAll
115
119
executeDecision (unassignedShard , allocationDecision , allocation , iterator );
116
120
}
117
121
}
122
+ logger .trace ("Finished shard allocation execution for unassigned primary shards: {}" , shardRoutings .size ());
118
123
}
119
124
120
125
/**
0 commit comments