Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public class Phase implements ToXContentObject {

static final ParseField AFTER_FIELD = new ParseField("after");
static final ParseField MINIMUM_AGE = new ParseField("minimum_age");
static final ParseField ACTIONS_FIELD = new ParseField("actions");

@SuppressWarnings("unchecked")
Expand All @@ -49,7 +49,7 @@ public class Phase implements ToXContentObject {
.collect(Collectors.toMap(LifecycleAction::getName, Function.identity()))));
static {
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
(p, c) -> TimeValue.parseTimeValue(p.text(), AFTER_FIELD.getPreferredName()), AFTER_FIELD, ValueType.VALUE);
(p, c) -> TimeValue.parseTimeValue(p.text(), MINIMUM_AGE.getPreferredName()), MINIMUM_AGE, ValueType.VALUE);
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(),
(p, c, n) -> p.namedObject(LifecycleAction.class, n, null), v -> {
throw new IllegalArgumentException("ordered " + ACTIONS_FIELD.getPreferredName() + " are not supported");
Expand All @@ -62,25 +62,25 @@ public static Phase parse(XContentParser parser, String name) {

private final String name;
private final Map<String, LifecycleAction> actions;
private final TimeValue after;
private final TimeValue minimumAge;

/**
* @param name
* the name of this {@link Phase}.
* @param after
* @param minimumAge
* the age of the index when the index should move to this
* {@link Phase}.
* @param actions
* a {@link Map} of the {@link LifecycleAction}s to run when
* during this {@link Phase}. The keys in this map are the associated
* action names.
*/
public Phase(String name, TimeValue after, Map<String, LifecycleAction> actions) {
public Phase(String name, TimeValue minimumAge, Map<String, LifecycleAction> actions) {
this.name = name;
if (after == null) {
this.after = TimeValue.ZERO;
if (minimumAge == null) {
this.minimumAge = TimeValue.ZERO;
} else {
this.after = after;
this.minimumAge = minimumAge;
}
this.actions = actions;
}
Expand All @@ -89,8 +89,8 @@ public Phase(String name, TimeValue after, Map<String, LifecycleAction> actions)
* @return the age of the index when the index should move to this
* {@link Phase}.
*/
public TimeValue getAfter() {
return after;
public TimeValue getMinimumAge() {
return minimumAge;
}

/**
Expand All @@ -111,15 +111,15 @@ public Map<String, LifecycleAction> getActions() {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(AFTER_FIELD.getPreferredName(), after.getStringRep());
builder.field(MINIMUM_AGE.getPreferredName(), minimumAge.getStringRep());
builder.field(ACTIONS_FIELD.getPreferredName(), actions);
builder.endObject();
return builder;
}

@Override
public int hashCode() {
return Objects.hash(name, after, actions);
return Objects.hash(name, minimumAge, actions);
}

@Override
Expand All @@ -132,7 +132,7 @@ public boolean equals(Object obj) {
}
Phase other = (Phase) obj;
return Objects.equals(name, other.name) &&
Objects.equals(after, other.after) &&
Objects.equals(minimumAge, other.minimumAge) &&
Objects.equals(actions, other.actions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ protected boolean supportsUnknownFields() {

public void testDefaultAfter() {
Phase phase = new Phase(randomAlphaOfLength(20), null, Collections.emptyMap());
assertEquals(TimeValue.ZERO, phase.getAfter());
assertEquals(TimeValue.ZERO, phase.getMinimumAge());
}
}
2 changes: 1 addition & 1 deletion x-pack/docs/en/ilm/set-up-lifecycle-policy.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PUT _ilm/my_policy
}
},
"delete": {
"after": "30d",
"minimum_age": "30d",
"actions": {
"delete": {} <2>
}
Expand Down
6 changes: 3 additions & 3 deletions x-pack/docs/en/ilm/using-policies-rollover.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ when the index size reaches 25GB. The old index is subsequently deleted after

NOTE: Once an index rolls over, {ilm} uses the timestamp of the rollover
operation rather than the index creation time to evaluate when to move the
index to the next phase. For indices that have rolled over, the `after`
index to the next phase. For indices that have rolled over, the `minimum_age`
criteria specified for a phase is relative to the rollover time for indices. In
this example, that means the index will be deleted 30 days after rollover, not
30 days from when the index was created.
Expand All @@ -58,7 +58,7 @@ PUT /_ilm/my_policy
}
},
"delete": {
"after": "30d",
"minimum_age": "30d",
"actions": {
"delete": {}
}
Expand Down Expand Up @@ -112,4 +112,4 @@ suffix number for each subsequent index.

When the rollover is performed, the newly-created index is set as the write
index for the rolled over alias. Documents sent to the alias are indexed into
the new index, enabling indexing to continue uninterrupted.
the new index, enabling indexing to continue uninterrupted.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class Phase implements ToXContentObject, Writeable {

public static final ParseField AFTER_FIELD = new ParseField("after");
public static final ParseField MINIMUM_AGE = new ParseField("minimum_age");
public static final ParseField ACTIONS_FIELD = new ParseField("actions");

@SuppressWarnings("unchecked")
Expand All @@ -40,7 +40,7 @@ public class Phase implements ToXContentObject, Writeable {
.collect(Collectors.toMap(LifecycleAction::getWriteableName, Function.identity()))));
static {
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
(p, c) -> TimeValue.parseTimeValue(p.text(), AFTER_FIELD.getPreferredName()), AFTER_FIELD, ValueType.VALUE);
(p, c) -> TimeValue.parseTimeValue(p.text(), MINIMUM_AGE.getPreferredName()), MINIMUM_AGE, ValueType.VALUE);
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(),
(p, c, n) -> p.namedObject(LifecycleAction.class, n, null), v -> {
throw new IllegalArgumentException("ordered " + ACTIONS_FIELD.getPreferredName() + " are not supported");
Expand All @@ -53,12 +53,12 @@ public static Phase parse(XContentParser parser, String name) {

private final String name;
private final Map<String, LifecycleAction> actions;
private final TimeValue after;
private final TimeValue minimumAge;

/**
* @param name
* the name of this {@link Phase}.
* @param after
* @param minimumAge
* the age of the index when the index should move to this
* {@link Phase}.
* @param actions
Expand All @@ -67,12 +67,12 @@ public static Phase parse(XContentParser parser, String name) {
* action names. The order of these actions is defined
* by the {@link LifecycleType}
*/
public Phase(String name, TimeValue after, Map<String, LifecycleAction> actions) {
public Phase(String name, TimeValue minimumAge, Map<String, LifecycleAction> actions) {
this.name = name;
if (after == null) {
this.after = TimeValue.ZERO;
if (minimumAge == null) {
this.minimumAge = TimeValue.ZERO;
} else {
this.after = after;
this.minimumAge = minimumAge;
}
this.actions = actions;
}
Expand All @@ -82,7 +82,7 @@ public Phase(String name, TimeValue after, Map<String, LifecycleAction> actions)
*/
public Phase(StreamInput in) throws IOException {
this.name = in.readString();
this.after = in.readTimeValue();
this.minimumAge = in.readTimeValue();
int size = in.readVInt();
TreeMap<String, LifecycleAction> actions = new TreeMap<>();
for (int i = 0; i < size; i++) {
Expand All @@ -94,7 +94,7 @@ public Phase(StreamInput in) throws IOException {
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(name);
out.writeTimeValue(after);
out.writeTimeValue(minimumAge);
out.writeVInt(actions.size());
for (Map.Entry<String, LifecycleAction> entry : actions.entrySet()) {
out.writeString(entry.getKey());
Expand All @@ -106,8 +106,8 @@ public void writeTo(StreamOutput out) throws IOException {
* @return the age of the index when the index should move to this
* {@link Phase}.
*/
public TimeValue getAfter() {
return after;
public TimeValue getMinimumAge() {
return minimumAge;
}

/**
Expand All @@ -128,15 +128,15 @@ public Map<String, LifecycleAction> getActions() {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(AFTER_FIELD.getPreferredName(), after.getStringRep());
builder.field(MINIMUM_AGE.getPreferredName(), minimumAge.getStringRep());
builder.field(ACTIONS_FIELD.getPreferredName(), actions);
builder.endObject();
return builder;
}

@Override
public int hashCode() {
return Objects.hash(name, after, actions);
return Objects.hash(name, minimumAge, actions);
}

@Override
Expand All @@ -149,7 +149,7 @@ public boolean equals(Object obj) {
}
Phase other = (Phase) obj;
return Objects.equals(name, other.name) &&
Objects.equals(after, other.after) &&
Objects.equals(minimumAge, other.minimumAge) &&
Objects.equals(actions, other.actions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public List<Phase> getOrderedPhases(Map<String, Phase> phases) {
} else if (phase.getActions().containsKey(ReadOnlyAction.NAME) == false){
Map<String, LifecycleAction> actionMap = new HashMap<>(phase.getActions());
actionMap.put(ReadOnlyAction.NAME, ReadOnlyAction.INSTANCE);
phase = new Phase(phase.getName(), phase.getAfter(), actionMap);
phase = new Phase(phase.getName(), phase.getMinimumAge(), actionMap);
}
}
if (phase != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected NamedXContentRegistry xContentRegistry() {
@Override
protected Phase mutateInstance(Phase instance) throws IOException {
String name = instance.getName();
TimeValue after = instance.getAfter();
TimeValue after = instance.getMinimumAge();
Map<String, LifecycleAction> actions = instance.getActions();
switch (between(0, 2)) {
case 0:
Expand All @@ -90,6 +90,6 @@ protected Phase mutateInstance(Phase instance) throws IOException {

public void testDefaultAfter() {
Phase phase = new Phase(randomAlphaOfLength(20), null, Collections.emptyMap());
assertEquals(TimeValue.ZERO, phase.getAfter());
assertEquals(TimeValue.ZERO, phase.getMinimumAge());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public TimeValue getIndexAgeForPhase(final String policy, final String phase) {
// We don't have that phase registered, proceed right through it
return TimeValue.ZERO;
} else {
return retrievedPhase.getAfter();
return retrievedPhase.getMinimumAge();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ setup:
"policy": {
"phases": {
"warm": {
"after": "10s",
"minimum_age": "10s",
"actions": {
"forcemerge": {
"max_num_segments": 10000
}
}
},
"delete": {
"after": "30s",
"minimum_age": "30s",
"actions": {
"delete": {}
}
Expand All @@ -48,8 +48,8 @@ setup:
lifecycle: "my_timeseries_lifecycle"
- match: { my_timeseries_lifecycle.version: 1 }
- is_true: my_timeseries_lifecycle.modified_date
- match: { my_timeseries_lifecycle.policy.phases.warm.after: "10s" }
- match: { my_timeseries_lifecycle.policy.phases.delete.after: "30s" }
- match: { my_timeseries_lifecycle.policy.phases.warm.minimum_age: "10s" }
- match: { my_timeseries_lifecycle.policy.phases.delete.minimum_age: "30s" }

- do:
acknowledge: true
Expand All @@ -72,15 +72,15 @@ setup:
"policy": {
"phases": {
"warm": {
"after": "10s",
"minimum_age": "10s",
"actions": {
"forcemerge": {
"max_num_segments": 10000
}
}
},
"delete": {
"after": "30s",
"minimum_age": "30s",
"actions": {
"delete": {}
}
Expand All @@ -95,8 +95,8 @@ setup:
lifecycle: "my_timeseries_lifecycle"
- match: { my_timeseries_lifecycle.version: 1 }
- is_true: my_timeseries_lifecycle.modified_date
- match: { my_timeseries_lifecycle.policy.phases.warm.after: "10s" }
- match: { my_timeseries_lifecycle.policy.phases.delete.after: "30s" }
- match: { my_timeseries_lifecycle.policy.phases.warm.minimum_age: "10s" }
- match: { my_timeseries_lifecycle.policy.phases.delete.minimum_age: "30s" }


- do:
Expand All @@ -122,15 +122,15 @@ setup:
"policy": {
"phases": {
"warm": {
"after": "300s",
"minimum_age": "300s",
"actions": {
"forcemerge": {
"max_num_segments": 10000
}
}
},
"delete": {
"after": "600s",
"minimum_age": "600s",
"actions": {
"delete": {}
}
Expand All @@ -145,8 +145,8 @@ setup:
lifecycle: "my_timeseries_lifecycle"
- match: { my_timeseries_lifecycle.version: 2 }
- is_true: my_timeseries_lifecycle.modified_date
- match: { my_timeseries_lifecycle.policy.phases.warm.after: "300s" }
- match: { my_timeseries_lifecycle.policy.phases.delete.after: "600s" }
- match: { my_timeseries_lifecycle.policy.phases.warm.minimum_age: "300s" }
- match: { my_timeseries_lifecycle.policy.phases.delete.minimum_age: "600s" }

- do:
acknowledge: true
Expand Down Expand Up @@ -178,15 +178,15 @@ setup:
"policy": {
"phases": {
"warm": {
"after": "10s",
"minimum_age": "10s",
"actions": {
"forcemerge": {
"max_num_segments": 10000
}
}
},
"delete": {
"after": "30s",
"minimum_age": "30s",
"actions": {
"delete": {}
}
Expand All @@ -199,8 +199,8 @@ setup:
acknowledge: true
ilm.get_lifecycle:
lifecycle: "my_timeseries_lifecycle"
- match: { my_timeseries_lifecycle.policy.phases.warm.after: "10s" }
- match: { my_timeseries_lifecycle.policy.phases.delete.after: "30s" }
- match: { my_timeseries_lifecycle.policy.phases.warm.minimum_age: "10s" }
- match: { my_timeseries_lifecycle.policy.phases.delete.minimum_age: "30s" }

- do:
indices.create:
Expand Down
Loading