Skip to content

Commit 241bf1b

Browse files
committed
Fix comments, typos and names
1 parent 035f2ef commit 241bf1b

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

server/src/main/java/org/elasticsearch/health/node/ShardsCapacityHealthIndicatorService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ private HealthIndicatorResult mergeIndicators(boolean verbose, List<StatusResult
141141
final var nodeTypeNames = new ArrayList<String>();
142142
for (var statusResult : statusResults) {
143143
if (statusResult.status.indicatesHealthProblem()) {
144-
nodeTypeNames.add(nodeTypeFroResultGroup(statusResult.result.group()));
145-
diagnoses.add(diagnosisForResultGroup(statusResult.result.group()));
144+
nodeTypeNames.add(nodeTypeFroLimitGroup(statusResult.result.group()));
145+
diagnoses.add(diagnosisForLimitGroup(statusResult.result.group()));
146146
}
147147
}
148148

@@ -195,7 +195,7 @@ static HealthIndicatorDetails buildDetails(List<ShardLimitValidator.Result> resu
195195
return (builder, params) -> {
196196
builder.startObject();
197197
for (var result : results) {
198-
builder.startObject(nodeTypeFroResultGroup(result.group()));
198+
builder.startObject(nodeTypeFroLimitGroup(result.group()));
199199
builder.field("max_shards_in_cluster", result.maxShardsInCluster());
200200
if (result.currentUsedShards().isPresent()) {
201201
builder.field("current_used_shards", result.currentUsedShards().get());
@@ -217,7 +217,7 @@ private HealthIndicatorResult unknownIndicator() {
217217
);
218218
}
219219

220-
private static String nodeTypeFroResultGroup(ShardLimitValidator.LimitGroup limitGroup) {
220+
private static String nodeTypeFroLimitGroup(ShardLimitValidator.LimitGroup limitGroup) {
221221
return switch (limitGroup) {
222222
case NORMAL -> "data";
223223
case FROZEN -> "frozen";
@@ -226,7 +226,7 @@ private static String nodeTypeFroResultGroup(ShardLimitValidator.LimitGroup limi
226226
};
227227
}
228228

229-
private static Diagnosis diagnosisForResultGroup(ShardLimitValidator.LimitGroup limitGroup) {
229+
private static Diagnosis diagnosisForLimitGroup(ShardLimitValidator.LimitGroup limitGroup) {
230230
return switch (limitGroup) {
231231
case NORMAL, INDEX, SEARCH -> SHARDS_MAX_CAPACITY_REACHED_DATA_NODES;
232232
case FROZEN -> SHARDS_MAX_CAPACITY_REACHED_FROZEN_NODES;

server/src/main/java/org/elasticsearch/indices/ShardLimitValidator.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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
);

server/src/test/java/org/elasticsearch/indices/ShardLimitValidatorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,15 @@ public static DiscoveryNodes createDiscoveryNodes(int nodesInCluster, LimitGroup
372372
}
373373

374374
if (group == LimitGroup.INDEX) {
375-
// Also add search nodes for index result group and they should not affect the result of the index group
375+
// Also add search nodes for index limit group and they should not affect the result of the index group
376376
IntStream.range(0, nodesInCluster + 1)
377377
.forEach(
378378
i -> builder.add(
379379
DiscoveryNodeUtils.builder(randomAlphaOfLength(16) + i).roles(Set.of(DiscoveryNodeRole.SEARCH_ROLE)).build()
380380
)
381381
);
382382
} else if (group == LimitGroup.SEARCH) {
383-
// Also add index nodes for search result group and they should not affect the result of the search group
383+
// Also add index nodes for search limit group and they should not affect the result of the search group
384384
IntStream.range(0, nodesInCluster + 1)
385385
.forEach(
386386
i -> builder.add(

0 commit comments

Comments
 (0)