@@ -116,11 +116,11 @@ public static int getShardLimitPerNode(LimitGroup limitGroup, HealthMetadata.Sha
116116 * @throws ValidationException if creating this index would put the cluster over the cluster shard limit
117117 */
118118 public void validateShardLimit (final Settings settings , final DiscoveryNodes discoveryNodes , final Metadata metadata ) {
119- final var resultGroups = applicableLimitGroups (isStateless );
120- final var shardsToCreatePerGroup = resultGroups .stream ()
119+ final var limitGroups = applicableLimitGroups (isStateless );
120+ final var shardsToCreatePerGroup = limitGroups .stream ()
121121 .collect (Collectors .toUnmodifiableMap (Function .identity (), limitGroup -> limitGroup .newShardsTotal (settings )));
122122
123- final var result = checkShardLimitOnGroups (resultGroups , shardsToCreatePerGroup , discoveryNodes , metadata );
123+ final var result = checkShardLimitOnGroups (limitGroups , shardsToCreatePerGroup , discoveryNodes , metadata );
124124 if (result .canAddShards == false ) {
125125 final ValidationException e = new ValidationException ();
126126 e .addValidationError (errorMessageFrom (result ));
@@ -138,20 +138,20 @@ public void validateShardLimit(final Settings settings, final DiscoveryNodes dis
138138 * @throws ValidationException If this operation would take the cluster over the limit and enforcement is enabled.
139139 */
140140 public void validateShardLimit (DiscoveryNodes discoveryNodes , Metadata metadata , Index [] indicesToOpen ) {
141- final var resultGroups = applicableLimitGroups (isStateless );
141+ final var limitGroups = applicableLimitGroups (isStateless );
142142 final Map <LimitGroup , Integer > shardsToCreatePerGroup = new HashMap <>();
143143
144- // TODO: we can short circuit when indindicesToOpenices is empty
144+ // TODO: we can short circuit when indicesToOpen is empty
145145 for (Index index : indicesToOpen ) {
146146 IndexMetadata imd = metadata .indexMetadata (index );
147147 if (imd .getState ().equals (IndexMetadata .State .CLOSE )) {
148- resultGroups .forEach (
148+ limitGroups .forEach (
149149 limitGroup -> shardsToCreatePerGroup .merge (limitGroup , limitGroup .newShardsTotal (imd .getSettings ()), Integer ::sum )
150150 );
151151 }
152152 }
153153
154- var result = checkShardLimitOnGroups (resultGroups , shardsToCreatePerGroup , discoveryNodes , metadata );
154+ var result = checkShardLimitOnGroups (limitGroups , shardsToCreatePerGroup , discoveryNodes , metadata );
155155 if (result .canAddShards == false ) {
156156 ValidationException ex = new ValidationException ();
157157 ex .addValidationError (errorMessageFrom (result ));
@@ -160,18 +160,18 @@ public void validateShardLimit(DiscoveryNodes discoveryNodes, Metadata metadata,
160160 }
161161
162162 public void validateShardLimitOnReplicaUpdate (DiscoveryNodes discoveryNodes , Metadata metadata , Index [] indices , int replicas ) {
163- final var resultGroups = applicableLimitGroups (isStateless );
163+ final var limitGroups = applicableLimitGroups (isStateless );
164164 final Map <LimitGroup , Integer > shardsToCreatePerGroup = new HashMap <>();
165165
166166 // TODO: we can short circuit when indices is empty
167167 for (Index index : indices ) {
168168 IndexMetadata imd = metadata .indexMetadata (index );
169- resultGroups .forEach (
169+ limitGroups .forEach (
170170 limitGroup -> shardsToCreatePerGroup .merge (limitGroup , limitGroup .newShardsTotal (imd .getSettings (), replicas ), Integer ::sum )
171171 );
172172 }
173173
174- var result = checkShardLimitOnGroups (resultGroups , shardsToCreatePerGroup , discoveryNodes , metadata );
174+ var result = checkShardLimitOnGroups (limitGroups , shardsToCreatePerGroup , discoveryNodes , metadata );
175175 if (result .canAddShards == false ) {
176176 ValidationException ex = new ValidationException ();
177177 ex .addValidationError (errorMessageFrom (result ));
@@ -186,12 +186,13 @@ public static List<LimitGroup> applicableLimitGroups(boolean isStateless) {
186186 /**
187187 * Checks to see if an operation can be performed without taking the cluster over the cluster-wide shard limit. It follows the
188188 * next rules:
189- * - Check limits for _normal_ nodes
190- * - If there's no room -> return the Result for _normal_ nodes (fail-fast)
191- * - otherwise -> returns the Result of checking the limits for _frozen_ nodes
189+ * - Check limits for nodes in the first group, e.g. _normal_ nodes
190+ * - If there's no room -> return the Result for nodes of the first group (fail-fast)
191+ * - otherwise -> returns the Result of checking the limits for the next group, e.g. _frozen_ nodes
192+ * - Rinse and repeat if thera re more groups. But so far we only have 2 members in a group.
192193 *
193- * @param limitGroups The applicable result groups to check for shard limits
194- * @param shardsToCreatePerGroup The number of new shards to create per result group
194+ * @param limitGroups The applicable limit groups to check for shard limits
195+ * @param shardsToCreatePerGroup The number of new shards to create per limit group
195196 * @param discoveryNodes The nodes in the cluster
196197 * @param metadata The cluster state metadata
197198 */
@@ -202,15 +203,15 @@ private Result checkShardLimitOnGroups(
202203 Metadata metadata
203204 ) {
204205 assert limitGroups .containsAll (shardsToCreatePerGroup .keySet ())
205- : "result groups " + limitGroups + " do not contain groups for shards creation " + shardsToCreatePerGroup .keySet ();
206+ : "limit groups " + limitGroups + " do not contain groups for shards creation " + shardsToCreatePerGroup .keySet ();
206207 // we verify the two limits independently. This also means that if they have mixed frozen and other data-roles nodes, such a mixed
207208 // node can have both 1000 normal and 3000 frozen shards. This is the trade-off to keep the simplicity of the counts. We advocate
208209 // against such mixed nodes for production use anyway.
209210 Result result = null ;
210- for (var resultGroup : limitGroups ) {
211- result = resultGroup .checkShardLimit (
212- getShardLimitPerNode (resultGroup ),
213- shardsToCreatePerGroup .getOrDefault (resultGroup , 0 ),
211+ for (var limitGroup : limitGroups ) {
212+ result = limitGroup .checkShardLimit (
213+ getShardLimitPerNode (limitGroup ),
214+ shardsToCreatePerGroup .getOrDefault (limitGroup , 0 ),
214215 discoveryNodes ,
215216 metadata
216217 );
0 commit comments