-
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 5 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 |
---|---|---|
|
@@ -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? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.ilm; | ||
|
||
import org.elasticsearch.common.util.set.Sets; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Defines a record of the actions that are allowed for the timeseries lifecycle. | ||
* The order of actions is versioned, newer versions must contain all previous defined actions and are | ||
* allowed to make additive changes (we do not support removing actions, but actions to be removed | ||
* must be converted to no-ops) | ||
*/ | ||
public final class TimeseriesLifecycleActionsRegistry { | ||
|
||
public static final int VERSION_ONE = 1; | ||
// moves the downsample action after the migrate action in the warm and cold phases | ||
public static final int VERSION_TWO = 2; | ||
public static final int CURRENT_VERSION = VERSION_TWO; | ||
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. Suggestion, maybe we should call this |
||
|
||
public static final String HOT_PHASE = "hot"; | ||
public static final String WARM_PHASE = "warm"; | ||
public static final String COLD_PHASE = "cold"; | ||
public static final String FROZEN_PHASE = "frozen"; | ||
public static final String DELETE_PHASE = "delete"; | ||
|
||
public static final Map<Integer, List<String>> ORDERED_VALID_HOT_ACTIONS = Map.of( | ||
VERSION_ONE, | ||
Stream.of( | ||
SetPriorityAction.NAME, | ||
UnfollowAction.NAME, | ||
RolloverAction.NAME, | ||
ReadOnlyAction.NAME, | ||
DownsampleAction.NAME, | ||
ShrinkAction.NAME, | ||
ForceMergeAction.NAME, | ||
SearchableSnapshotAction.NAME | ||
).filter(Objects::nonNull).toList(), | ||
VERSION_TWO, | ||
Stream.of( | ||
SetPriorityAction.NAME, | ||
UnfollowAction.NAME, | ||
RolloverAction.NAME, | ||
ReadOnlyAction.NAME, | ||
DownsampleAction.NAME, | ||
ShrinkAction.NAME, | ||
ForceMergeAction.NAME, | ||
SearchableSnapshotAction.NAME | ||
).filter(Objects::nonNull).toList() | ||
Comment on lines
+38
to
+59
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. Since these are the same, can we put them in a variable so it's clear here that the order isn't changing between versions? |
||
); | ||
|
||
public static final Map<Integer, List<String>> ORDERED_VALID_WARM_ACTIONS = Map.of( | ||
VERSION_ONE, | ||
Stream.of( | ||
SetPriorityAction.NAME, | ||
UnfollowAction.NAME, | ||
ReadOnlyAction.NAME, | ||
DownsampleAction.NAME, | ||
AllocateAction.NAME, | ||
MigrateAction.NAME, | ||
ShrinkAction.NAME, | ||
ForceMergeAction.NAME | ||
).filter(Objects::nonNull).toList(), | ||
VERSION_TWO, | ||
Stream.of( | ||
SetPriorityAction.NAME, | ||
UnfollowAction.NAME, | ||
ReadOnlyAction.NAME, | ||
AllocateAction.NAME, | ||
MigrateAction.NAME, | ||
DownsampleAction.NAME, | ||
Comment on lines
+79
to
+81
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 a comment about the differences here, so that someone doesn't have to eyeball it? |
||
ShrinkAction.NAME, | ||
ForceMergeAction.NAME | ||
).filter(Objects::nonNull).toList() | ||
); | ||
|
||
public static final Map<Integer, List<String>> ORDERED_VALID_COLD_ACTIONS = Map.of( | ||
VERSION_ONE, | ||
Stream.of( | ||
SetPriorityAction.NAME, | ||
UnfollowAction.NAME, | ||
ReadOnlyAction.NAME, | ||
DownsampleAction.NAME, | ||
SearchableSnapshotAction.NAME, | ||
AllocateAction.NAME, | ||
MigrateAction.NAME, | ||
FreezeAction.NAME | ||
).filter(Objects::nonNull).toList(), | ||
VERSION_TWO, | ||
Stream.of( | ||
SetPriorityAction.NAME, | ||
UnfollowAction.NAME, | ||
ReadOnlyAction.NAME, | ||
SearchableSnapshotAction.NAME, | ||
AllocateAction.NAME, | ||
MigrateAction.NAME, | ||
DownsampleAction.NAME, | ||
Comment on lines
+105
to
+107
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. Same here about adding a comment |
||
FreezeAction.NAME | ||
).filter(Objects::nonNull).toList() | ||
); | ||
|
||
public static final Map<Integer, List<String>> ORDERED_VALID_FROZEN_ACTIONS = Map.of( | ||
VERSION_ONE, | ||
List.of(UnfollowAction.NAME, SearchableSnapshotAction.NAME), | ||
VERSION_TWO, | ||
List.of(UnfollowAction.NAME, SearchableSnapshotAction.NAME) | ||
); | ||
public static final Map<Integer, List<String>> ORDERED_VALID_DELETE_ACTIONS = Map.of( | ||
VERSION_ONE, | ||
List.of(WaitForSnapshotAction.NAME, DeleteAction.NAME), | ||
VERSION_TWO, | ||
List.of(WaitForSnapshotAction.NAME, DeleteAction.NAME) | ||
); | ||
|
||
static final Set<String> VALID_HOT_ACTIONS = Sets.newHashSet(ORDERED_VALID_HOT_ACTIONS.get(CURRENT_VERSION)); | ||
static final Set<String> VALID_WARM_ACTIONS = Sets.newHashSet(ORDERED_VALID_WARM_ACTIONS.get(CURRENT_VERSION)); | ||
static final Set<String> VALID_COLD_ACTIONS = Sets.newHashSet(ORDERED_VALID_COLD_ACTIONS.get(CURRENT_VERSION)); | ||
static final Set<String> VALID_FROZEN_ACTIONS = Sets.newHashSet(ORDERED_VALID_FROZEN_ACTIONS.get(CURRENT_VERSION)); | ||
static final Set<String> VALID_DELETE_ACTIONS = Sets.newHashSet(ORDERED_VALID_DELETE_ACTIONS.get(CURRENT_VERSION)); | ||
Comment on lines
+125
to
+129
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. Are we concerned that a step may be considered valid but that a different version may not contain the action name? For example, we have to be careful not to remove any actions from later version because they will be considered "invalid" even if they exist in older action version orders. Should we have an assert for this? |
||
|
||
static final Map<String, Set<String>> ALLOWED_ACTIONS = Map.of( | ||
HOT_PHASE, | ||
VALID_HOT_ACTIONS, | ||
WARM_PHASE, | ||
VALID_WARM_ACTIONS, | ||
COLD_PHASE, | ||
VALID_COLD_ACTIONS, | ||
DELETE_PHASE, | ||
VALID_DELETE_ACTIONS, | ||
FROZEN_PHASE, | ||
VALID_FROZEN_ACTIONS | ||
); | ||
} |
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