Skip to content

Commit c752e6e

Browse files
Respond to comments from Mary
1 parent 866aa07 commit c752e6e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

server/src/main/java/org/elasticsearch/action/datastreams/autosharding/DataStreamAutoShardingService.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,19 @@ record IncreaseCalculation(
238238
) {}
239239

240240
record DecreaseCalculation(
241-
MaxLoadWithinCooldown maxLoadWithinCooldownForDecrease,
241+
MaxLoadWithinCooldown maxLoadWithinCooldown,
242242
int optimalShardCountForDecrease,
243243
@Nullable AutoShardingResult decreaseResult
244244
) {
245+
246+
/**
247+
* Contains information about the backing index with the highest load, out of the current write index and all the older
248+
* indices created within the cooldown period.
249+
*
250+
* @param load The highest load
251+
* @param previousIndexWithMaxLoad If this load came from one of the previous backing indices, the name of that index; null if
252+
* it came from the current write index
253+
*/
245254
record MaxLoadWithinCooldown(double load, @Nullable String previousIndexWithMaxLoad) {}
246255
}
247256

@@ -270,9 +279,9 @@ public String toString() {
270279
: Strings.format(
271280
", and using %s value %g for dec based on %s gives %d shards",
272281
inputs.decreaseShardsMetric,
273-
decreaseCalculation.maxLoadWithinCooldownForDecrease.load,
274-
decreaseCalculation.maxLoadWithinCooldownForDecrease.previousIndexWithMaxLoad != null
275-
? decreaseCalculation.maxLoadWithinCooldownForDecrease.previousIndexWithMaxLoad
282+
decreaseCalculation.maxLoadWithinCooldown.load,
283+
decreaseCalculation.maxLoadWithinCooldown.previousIndexWithMaxLoad != null
284+
? decreaseCalculation.maxLoadWithinCooldown.previousIndexWithMaxLoad
276285
: "write index",
277286
decreaseCalculation.optimalShardCountForDecrease
278287
)
@@ -372,7 +381,7 @@ private Decision innerCalculate(ProjectMetadata project, DataStream dataStream,
372381
return new Decision(inputs, increaseCalculation, null, increaseCalculation.increaseResult());
373382
}
374383
// If not, see whether we recommend decreasing the number of shards.
375-
Decision.DecreaseCalculation decreaseCalculation = calculateIncreaseShardsDecision(project, dataStream, inputs);
384+
Decision.DecreaseCalculation decreaseCalculation = calculateDecreaseShardsDecision(project, dataStream, inputs);
376385
if (decreaseCalculation.decreaseResult() != null) {
377386
return new Decision(inputs, increaseCalculation, decreaseCalculation, decreaseCalculation.decreaseResult());
378387
}
@@ -451,7 +460,7 @@ private TimeValue getRemainingDecreaseShardsCooldown(ProjectMetadata project, Da
451460
);
452461
}
453462

454-
private Decision.DecreaseCalculation calculateIncreaseShardsDecision(
463+
private Decision.DecreaseCalculation calculateDecreaseShardsDecision(
455464
ProjectMetadata project,
456465
DataStream dataStream,
457466
Decision.Inputs inputs

server/src/test/java/org/elasticsearch/action/datastreams/autosharding/DataStreamAutoShardingServiceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,9 @@ public void testCalculateDecreaseShardingRecommendations_correctDecisionData() {
665665
// Increase shard count based on all-time load of 1.9 for write index:
666666
assertThat(decision.increaseCalculation().optimalShardCountForIncrease(), equalTo(2));
667667
// The highest load for decrease (i.e. recent load) within the cooling period is the 0.333 from generation 3
668-
assertThat(decision.decreaseCalculation().maxLoadWithinCooldownForDecrease().load(), closeTo(0.333, 1.0e-8));
668+
assertThat(decision.decreaseCalculation().maxLoadWithinCooldown().load(), closeTo(0.333, 1.0e-8));
669669
assertThat(
670-
decision.decreaseCalculation().maxLoadWithinCooldownForDecrease().previousIndexWithMaxLoad(),
670+
decision.decreaseCalculation().maxLoadWithinCooldown().previousIndexWithMaxLoad(),
671671
equalTo(DataStream.getDefaultBackingIndexName(dataStreamName, 3, now - TimeValue.timeValueDays(2).getMillis()))
672672
);
673673
// Decrease shard count based on recent load of 0.333 for gen 3 index

0 commit comments

Comments
 (0)