Skip to content

Commit 906c5b6

Browse files
authored
Some ILM tidying cleanups, mostly around String formatting (#118338)
1 parent 17765e7 commit 906c5b6

File tree

61 files changed

+187
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+187
-232
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncWaitStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
public abstract class AsyncWaitStep extends Step {
2222

23-
private Client client;
23+
private final Client client;
2424

2525
public AsyncWaitStep(StepKey key, StepKey nextStepKey, Client client) {
2626
super(key, nextStepKey);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/BranchingStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public ClusterState performAction(Index index, ClusterState clusterState) {
7171
* This method returns the next step to execute based on the predicate. If
7272
* the predicate returned true, then nextStepKeyOnTrue is the key of the
7373
* next step to run, otherwise nextStepKeyOnFalse is.
74-
*
74+
* <p>
7575
* throws {@link UnsupportedOperationException} if performAction was not called yet
7676
*
7777
* @return next step to execute

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckNotDataStreamWriteIndexStep.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
import org.elasticsearch.cluster.metadata.IndexAbstraction;
1414
import org.elasticsearch.cluster.metadata.IndexMetadata;
1515
import org.elasticsearch.cluster.metadata.Metadata;
16+
import org.elasticsearch.common.Strings;
1617
import org.elasticsearch.index.Index;
1718
import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo;
1819

19-
import java.util.Locale;
20-
2120
/**
2221
* Some actions cannot be executed on a data stream's write index (eg. `searchable-snapshot`). This step checks if the managed index is
2322
* part of a data stream, in which case it will check it's not the write index. If the managed index is the write index of a data stream
@@ -46,8 +45,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
4645
String indexName = index.getName();
4746

4847
if (indexMetadata == null) {
49-
String errorMessage = String.format(
50-
Locale.ROOT,
48+
String errorMessage = Strings.format(
5149
"[%s] lifecycle action for index [%s] executed but index no longer exists",
5250
getKey().action(),
5351
indexName
@@ -64,8 +62,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
6462
if (dataStream != null) {
6563
boolean isFailureStoreWriteIndex = index.equals(dataStream.getFailureStoreWriteIndex());
6664
if (isFailureStoreWriteIndex || dataStream.getWriteIndex().equals(index)) {
67-
String errorMessage = String.format(
68-
Locale.ROOT,
65+
String errorMessage = Strings.format(
6966
"index [%s] is the%s write index for data stream [%s], pausing "
7067
+ "ILM execution of lifecycle [%s] until this index is no longer the write index for the data stream via manual or "
7168
+ "automated rollover",

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckShrinkReadyStep.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo;
2424

2525
import java.io.IOException;
26-
import java.util.Locale;
2726
import java.util.Objects;
2827

2928
/**
@@ -158,8 +157,7 @@ public Info(String nodeId, long expectedShards, long numberShardsLeftToAllocate)
158157
if (numberShardsLeftToAllocate < 0) {
159158
this.message = "Waiting for all shards to become active";
160159
} else {
161-
this.message = String.format(
162-
Locale.ROOT,
160+
this.message = Strings.format(
163161
"Waiting for node [%s] to contain [%d] shards, found [%d], remaining [%d]",
164162
nodeId,
165163
expectedShards,

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStep.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
import org.apache.logging.log4j.Logger;
1111
import org.elasticsearch.cluster.ClusterState;
1212
import org.elasticsearch.cluster.metadata.IndexMetadata;
13+
import org.elasticsearch.common.Strings;
1314
import org.elasticsearch.index.Index;
1415
import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo;
1516

16-
import java.util.Locale;
17-
1817
/**
1918
* This step checks whether the new shrunken index's shards count is a factor of the source index's shards count.
2019
*/
@@ -53,8 +52,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
5352
int sourceNumberOfShards = indexMetadata.getNumberOfShards();
5453
if (sourceNumberOfShards % numberOfShards != 0) {
5554
String policyName = indexMetadata.getLifecyclePolicyName();
56-
String errorMessage = String.format(
57-
Locale.ROOT,
55+
String errorMessage = Strings.format(
5856
"lifecycle action of policy [%s] for index [%s] cannot make progress "
5957
+ "because the target shards count [%d] must be a factor of the source index's shards count [%d]",
6058
policyName,

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStep.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,24 @@ void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentCl
6666
}
6767
getClient().admin()
6868
.indices()
69-
.delete(
70-
new DeleteIndexRequest(shrinkIndexName).masterNodeTimeout(TimeValue.MAX_VALUE),
71-
new ActionListener<AcknowledgedResponse>() {
72-
@Override
73-
public void onResponse(AcknowledgedResponse acknowledgedResponse) {
74-
// even if not all nodes acked the delete request yet we can consider this operation as successful as
75-
// we'll generate a new index name and attempt to shrink into the newly generated name
76-
listener.onResponse(null);
77-
}
69+
.delete(new DeleteIndexRequest(shrinkIndexName).masterNodeTimeout(TimeValue.MAX_VALUE), new ActionListener<>() {
70+
@Override
71+
public void onResponse(AcknowledgedResponse acknowledgedResponse) {
72+
// even if not all nodes acked the delete request yet we can consider this operation as successful as
73+
// we'll generate a new index name and attempt to shrink into the newly generated name
74+
listener.onResponse(null);
75+
}
7876

79-
@Override
80-
public void onFailure(Exception e) {
81-
if (e instanceof IndexNotFoundException) {
82-
// we can move on if the index was deleted in the meantime
83-
listener.onResponse(null);
84-
} else {
85-
listener.onFailure(e);
86-
}
77+
@Override
78+
public void onFailure(Exception e) {
79+
if (e instanceof IndexNotFoundException) {
80+
// we can move on if the index was deleted in the meantime
81+
listener.onResponse(null);
82+
} else {
83+
listener.onFailure(e);
8784
}
8885
}
89-
);
86+
});
9087
}
9188

9289
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitStep.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* Checks whether a condition has been met based on the cluster state.
15-
*
15+
* <p>
1616
* If checking a condition not based on the cluster state, or which may take time to evaluate, use {@link AsyncWaitStep}.
1717
*/
1818
public abstract class ClusterStateWaitStep extends Step {
@@ -35,19 +35,19 @@ public boolean isCompletable() {
3535

3636
public static class Result {
3737
private final boolean complete;
38-
private final ToXContentObject infomationContext;
38+
private final ToXContentObject informationContext;
3939

40-
public Result(boolean complete, ToXContentObject infomationContext) {
40+
public Result(boolean complete, ToXContentObject informationContext) {
4141
this.complete = complete;
42-
this.infomationContext = infomationContext;
42+
this.informationContext = informationContext;
4343
}
4444

4545
public boolean isComplete() {
4646
return complete;
4747
}
4848

49-
public ToXContentObject getInfomationContext() {
50-
return infomationContext;
49+
public ToXContentObject getInformationContext() {
50+
return informationContext;
5151
}
5252
}
5353

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStep.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo;
2020

2121
import java.time.Clock;
22-
import java.util.Locale;
2322
import java.util.Objects;
2423
import java.util.concurrent.atomic.AtomicBoolean;
2524

@@ -30,7 +29,7 @@
3029
* If the action response is complete, the {@link ClusterStateWaitUntilThresholdStep}'s nextStepKey will be the nextStepKey of the
3130
* wrapped action. When the threshold level is surpassed, if the underlying step's condition was not met, the nextStepKey will be changed to
3231
* the provided {@link #nextKeyOnThresholdBreach} and this step will stop waiting.
33-
*
32+
* <p>
3433
* Failures encountered whilst executing the wrapped action will be propagated directly.
3534
*/
3635
public class ClusterStateWaitUntilThresholdStep extends ClusterStateWaitStep {
@@ -72,14 +71,13 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
7271
// we may not have passed the time threshold, but the step is not completable due to a different reason
7372
thresholdPassed.set(true);
7473

75-
String message = String.format(
76-
Locale.ROOT,
74+
String message = Strings.format(
7775
"[%s] lifecycle step, as part of [%s] action, for index [%s] Is not "
7876
+ "completable, reason: [%s]. Abandoning execution and moving to the next fallback step [%s]",
7977
getKey().name(),
8078
getKey().action(),
8179
idxMeta.getIndex().getName(),
82-
Strings.toString(stepResult.getInfomationContext()),
80+
Strings.toString(stepResult.getInformationContext()),
8381
nextKeyOnThresholdBreach
8482
);
8583
logger.debug(message);
@@ -90,8 +88,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
9088
// we retried this step enough, next step will be the configured to {@code nextKeyOnThresholdBreach}
9189
thresholdPassed.set(true);
9290

93-
String message = String.format(
94-
Locale.ROOT,
91+
String message = Strings.format(
9592
"[%s] lifecycle step, as part of [%s] action, for index [%s] executed for"
9693
+ " more than [%s]. Abandoning execution and moving to the next fallback step [%s]",
9794
getKey().name(),

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Copies the execution state data from one index to another, typically after a
2424
* new index has been created. As part of the execution state copy it will set the target index
2525
* "current step" to the provided target next step {@link org.elasticsearch.xpack.core.ilm.Step.StepKey}.
26-
*
26+
* <p>
2727
* Useful for actions such as shrink.
2828
*/
2929
public class CopyExecutionStateStep extends ClusterStateActionStep {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CopySettingsStep.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import org.elasticsearch.cluster.metadata.IndexMetadata;
1313
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
1414
import org.elasticsearch.cluster.metadata.Metadata;
15+
import org.elasticsearch.common.Strings;
1516
import org.elasticsearch.common.settings.Settings;
1617
import org.elasticsearch.index.Index;
1718

1819
import java.util.Arrays;
19-
import java.util.Locale;
2020
import java.util.Objects;
2121
import java.util.function.BiFunction;
2222

@@ -78,9 +78,8 @@ public ClusterState performAction(Index index, ClusterState clusterState) {
7878
String targetIndexName = targetIndexNameSupplier.apply(sourceIndexName, sourceIndexMetadata.getLifecycleExecutionState());
7979
IndexMetadata targetIndexMetadata = clusterState.metadata().index(targetIndexName);
8080
if (targetIndexMetadata == null) {
81-
String errorMessage = String.format(
82-
Locale.ROOT,
83-
"index [%s] is being referenced by ILM action [%s] on step [%s] but " + "it doesn't exist",
81+
String errorMessage = Strings.format(
82+
"index [%s] is being referenced by ILM action [%s] on step [%s] but it doesn't exist",
8483
targetIndexName,
8584
getKey().action(),
8685
getKey().name()

0 commit comments

Comments
 (0)