-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ILM] Version the order of the actions in a phase. #97745
base: main
Are you sure you want to change the base?
Changes from all commits
05a4cd1
788741b
8775cfb
1bb3676
2b106fe
a35195b
72ed49b
6549e95
1573fb6
3111380
9cf38a7
f475798
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,16 @@ public record LifecycleExecutionState( | |
String snapshotName, | ||
String shrinkIndexName, | ||
String snapshotIndexName, | ||
String downsampleIndexName | ||
String downsampleIndexName, | ||
Integer actionsOrderVersion | ||
) { | ||
|
||
public LifecycleExecutionState { | ||
if (actionsOrderVersion == null) { | ||
actionsOrderVersion = 1; | ||
} | ||
} | ||
|
||
public static final String ILM_CUSTOM_METADATA_KEY = "ilm"; | ||
|
||
private static final String PHASE = "phase"; | ||
|
@@ -58,6 +65,7 @@ public record LifecycleExecutionState( | |
private static final String SNAPSHOT_INDEX_NAME = "snapshot_index_name"; | ||
private static final String SHRINK_INDEX_NAME = "shrink_index_name"; | ||
private static final String DOWNSAMPLE_INDEX_NAME = "rollup_index_name"; | ||
private static final String ACTIONS_ORDER_VERSION = "actions_order_version"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should go with |
||
|
||
public static final LifecycleExecutionState EMPTY_STATE = LifecycleExecutionState.builder().build(); | ||
|
||
|
@@ -82,7 +90,8 @@ public static Builder builder(LifecycleExecutionState state) { | |
.setShrinkIndexName(state.shrinkIndexName) | ||
.setSnapshotIndexName(state.snapshotIndexName) | ||
.setDownsampleIndexName(state.downsampleIndexName) | ||
.setStepTime(state.stepTime); | ||
.setStepTime(state.stepTime) | ||
.setActionsOrderVersion(state.actionsOrderVersion); | ||
} | ||
|
||
public static LifecycleExecutionState fromCustomMetadata(Map<String, String> customData) { | ||
|
@@ -191,6 +200,10 @@ public static LifecycleExecutionState fromCustomMetadata(Map<String, String> cus | |
if (downsampleIndexName != null) { | ||
builder.setDownsampleIndexName(downsampleIndexName); | ||
} | ||
String actionsOrderVersion = customData.get(ACTIONS_ORDER_VERSION); | ||
if (actionsOrderVersion != null) { | ||
builder.setActionsOrderVersion(Integer.parseInt(actionsOrderVersion)); | ||
} | ||
return builder.build(); | ||
} | ||
|
||
|
@@ -253,6 +266,9 @@ public Map<String, String> asMap() { | |
if (downsampleIndexName != null) { | ||
result.put(DOWNSAMPLE_INDEX_NAME, downsampleIndexName); | ||
} | ||
if (actionsOrderVersion != null) { | ||
result.put(ACTIONS_ORDER_VERSION, String.valueOf(actionsOrderVersion)); | ||
} | ||
return Collections.unmodifiableMap(result); | ||
} | ||
|
||
|
@@ -274,6 +290,7 @@ public static class Builder { | |
private String shrinkIndexName; | ||
private String snapshotIndexName; | ||
private String downsampleIndexName; | ||
private Integer actionsOrderVersion; | ||
|
||
public Builder setPhase(String phase) { | ||
this.phase = phase; | ||
|
@@ -360,6 +377,11 @@ public Builder setDownsampleIndexName(String downsampleIndexName) { | |
return this; | ||
} | ||
|
||
public Builder setActionsOrderVersion(Integer actionsOrderVersion) { | ||
this.actionsOrderVersion = actionsOrderVersion; | ||
return this; | ||
} | ||
|
||
public LifecycleExecutionState build() { | ||
return new LifecycleExecutionState( | ||
phase, | ||
|
@@ -378,7 +400,8 @@ public LifecycleExecutionState build() { | |
snapshotName, | ||
shrinkIndexName, | ||
snapshotIndexName, | ||
downsampleIndexName | ||
downsampleIndexName, | ||
actionsOrderVersion | ||
); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
|
||
import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleActionsRegistry.VERSION_ONE; | ||
|
||
public class IndexLifecycleExplainResponse implements ToXContentObject, Writeable { | ||
|
||
private static final ParseField INDEX_FIELD = new ParseField("index"); | ||
|
@@ -54,6 +56,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl | |
private static final ParseField REPOSITORY_NAME = new ParseField("repository_name"); | ||
private static final ParseField SHRINK_INDEX_NAME = new ParseField("shrink_index_name"); | ||
private static final ParseField SNAPSHOT_NAME = new ParseField("snapshot_name"); | ||
private static ParseField ACTIONS_ORDER_VERSION_FIELD = new ParseField("actions_order_version"); | ||
|
||
public static final ConstructingObjectParser<IndexLifecycleExplainResponse, Void> PARSER = new ConstructingObjectParser<>( | ||
"index_lifecycle_explain_response", | ||
|
@@ -76,9 +79,10 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl | |
(String) a[17], | ||
(String) a[18], | ||
(BytesReference) a[11], | ||
(PhaseExecutionInfo) a[12] | ||
(PhaseExecutionInfo) a[12], | ||
// a[13] == "age" | ||
// a[20] == "time_since_index_creation" | ||
(Integer) a[21] | ||
) | ||
); | ||
static { | ||
|
@@ -111,6 +115,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl | |
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), SHRINK_INDEX_NAME); | ||
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), INDEX_CREATION_DATE_MILLIS_FIELD); | ||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), TIME_SINCE_INDEX_CREATION_FIELD); | ||
PARSER.declareInt(ConstructingObjectParser.optionalConstructorArg(), ACTIONS_ORDER_VERSION_FIELD); | ||
} | ||
|
||
private final String index; | ||
|
@@ -132,6 +137,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl | |
private final String repositoryName; | ||
private final String snapshotName; | ||
private final String shrinkIndexName; | ||
private final Integer actionsOrderVersion; | ||
|
||
Supplier<Long> nowSupplier = System::currentTimeMillis; // Can be changed for testing | ||
|
||
|
@@ -153,7 +159,8 @@ public static IndexLifecycleExplainResponse newManagedIndexResponse( | |
String snapshotName, | ||
String shrinkIndexName, | ||
BytesReference stepInfo, | ||
PhaseExecutionInfo phaseExecutionInfo | ||
PhaseExecutionInfo phaseExecutionInfo, | ||
Integer actionsOrderVersion | ||
) { | ||
return new IndexLifecycleExplainResponse( | ||
index, | ||
|
@@ -174,7 +181,8 @@ public static IndexLifecycleExplainResponse newManagedIndexResponse( | |
snapshotName, | ||
shrinkIndexName, | ||
stepInfo, | ||
phaseExecutionInfo | ||
phaseExecutionInfo, | ||
actionsOrderVersion | ||
); | ||
} | ||
|
||
|
@@ -198,6 +206,7 @@ public static IndexLifecycleExplainResponse newUnmanagedIndexResponse(String ind | |
null, | ||
null, | ||
null, | ||
null, | ||
null | ||
); | ||
} | ||
|
@@ -221,7 +230,8 @@ private IndexLifecycleExplainResponse( | |
String snapshotName, | ||
String shrinkIndexName, | ||
BytesReference stepInfo, | ||
PhaseExecutionInfo phaseExecutionInfo | ||
PhaseExecutionInfo phaseExecutionInfo, | ||
Integer actionsOrderVersion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We treat this as non-nullable elsewhere with the check in the state against null and setting it to |
||
) { | ||
if (managedByILM) { | ||
if (policyName == null) { | ||
|
@@ -283,6 +293,7 @@ private IndexLifecycleExplainResponse( | |
this.repositoryName = repositoryName; | ||
this.snapshotName = snapshotName; | ||
this.shrinkIndexName = shrinkIndexName; | ||
this.actionsOrderVersion = actionsOrderVersion; | ||
} | ||
|
||
public IndexLifecycleExplainResponse(StreamInput in) throws IOException { | ||
|
@@ -310,6 +321,11 @@ public IndexLifecycleExplainResponse(StreamInput in) throws IOException { | |
} else { | ||
indexCreationDate = null; | ||
} | ||
if (in.getTransportVersion().onOrAfter(TransportVersion.V_8_500_040)) { | ||
actionsOrderVersion = in.readOptionalInt(); | ||
} else { | ||
actionsOrderVersion = VERSION_ONE; | ||
} | ||
} else { | ||
policyName = null; | ||
lifecycleDate = null; | ||
|
@@ -328,6 +344,7 @@ public IndexLifecycleExplainResponse(StreamInput in) throws IOException { | |
snapshotName = null; | ||
shrinkIndexName = null; | ||
indexCreationDate = null; | ||
actionsOrderVersion = null; | ||
} | ||
} | ||
|
||
|
@@ -355,6 +372,9 @@ public void writeTo(StreamOutput out) throws IOException { | |
if (out.getTransportVersion().onOrAfter(TransportVersion.V_8_1_0)) { | ||
out.writeOptionalLong(indexCreationDate); | ||
} | ||
if (out.getTransportVersion().onOrAfter(TransportVersion.V_8_500_040)) { | ||
out.writeOptionalInt(actionsOrderVersion); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -450,6 +470,10 @@ public String getShrinkIndexName() { | |
return shrinkIndexName; | ||
} | ||
|
||
public Integer getActionsOrderVersion() { | ||
return actionsOrderVersion; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
|
@@ -514,6 +538,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
if (phaseExecutionInfo != null) { | ||
builder.field(PHASE_EXECUTION_INFO.getPreferredName(), phaseExecutionInfo); | ||
} | ||
if (actionsOrderVersion != null) { | ||
builder.field(ACTIONS_ORDER_VERSION_FIELD.getPreferredName(), actionsOrderVersion); | ||
} | ||
} | ||
builder.endObject(); | ||
return builder; | ||
|
@@ -540,7 +567,8 @@ public int hashCode() { | |
snapshotName, | ||
shrinkIndexName, | ||
stepInfo, | ||
phaseExecutionInfo | ||
phaseExecutionInfo, | ||
actionsOrderVersion | ||
); | ||
} | ||
|
||
|
@@ -571,7 +599,8 @@ public boolean equals(Object obj) { | |
&& Objects.equals(snapshotName, other.snapshotName) | ||
&& Objects.equals(shrinkIndexName, other.shrinkIndexName) | ||
&& Objects.equals(stepInfo, other.stepInfo) | ||
&& Objects.equals(phaseExecutionInfo, other.phaseExecutionInfo); | ||
&& Objects.equals(phaseExecutionInfo, other.phaseExecutionInfo) | ||
&& Objects.equals(actionsOrderVersion, other.actionsOrderVersion); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ public interface LifecycleType extends NamedWriteable { | |
*/ | ||
List<Phase> getOrderedPhases(Map<String, Phase> phases); | ||
|
||
List<LifecycleAction> getOrderedActions(Phase phase); | ||
List<LifecycleAction> getOrderedActions(Phase phase, int orderVersion); | ||
|
||
/** | ||
* validates whether the specified <code>phases</code> are valid for this | ||
|
@@ -31,4 +31,6 @@ public interface LifecycleType extends NamedWriteable { | |
* if a specific phase or lack of a specific phase is invalid. | ||
*/ | ||
void validate(Collection<Phase> phases); | ||
|
||
int getLatestActionsOrderVersion(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add javadocs for this? |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also enforce that it's > 0, to avoid weird
-1
issues