Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x][Transform] implement retention policy to delete data from a tra…
…nsform (#67832) (#68814) add a retention policy to transform to delete data that is considered outdated as part of a transform checkpoint. backport #67832 fixes #67916
- Loading branch information
Hendrik Muhs
committed
Feb 11, 2021
1 parent
f8b9876
commit 040b9a8
Showing
72 changed files
with
2,393 additions
and
794 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...el/src/main/java/org/elasticsearch/client/transform/transforms/RetentionPolicyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client.transform.transforms; | ||
|
||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
|
||
public interface RetentionPolicyConfig extends ToXContentObject { | ||
|
||
/** | ||
* Returns the name of the writeable object | ||
*/ | ||
String getName(); | ||
} |
99 changes: 99 additions & 0 deletions
99
...rc/main/java/org/elasticsearch/client/transform/transforms/TimeRetentionPolicyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client.transform.transforms; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
public class TimeRetentionPolicyConfig implements RetentionPolicyConfig { | ||
|
||
public static final String NAME = "time"; | ||
|
||
private static final ParseField FIELD = new ParseField("field"); | ||
private static final ParseField MAX_AGE = new ParseField("max_age"); | ||
|
||
private final String field; | ||
private final TimeValue maxAge; | ||
|
||
private static final ConstructingObjectParser<TimeRetentionPolicyConfig, Void> PARSER = new ConstructingObjectParser<>( | ||
"time_retention_policy_config", | ||
true, | ||
args -> new TimeRetentionPolicyConfig((String) args[0], args[1] != null ? (TimeValue) args[1] : TimeValue.ZERO) | ||
); | ||
|
||
static { | ||
PARSER.declareString(constructorArg(), FIELD); | ||
PARSER.declareField( | ||
constructorArg(), | ||
(p, c) -> TimeValue.parseTimeValue(p.text(), MAX_AGE.getPreferredName()), | ||
MAX_AGE, | ||
ObjectParser.ValueType.STRING | ||
); | ||
} | ||
|
||
public static TimeRetentionPolicyConfig fromXContent(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
|
||
public TimeRetentionPolicyConfig(String field, TimeValue maxAge) { | ||
this.field = field; | ||
this.maxAge = maxAge; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(FIELD.getPreferredName(), field); | ||
builder.field(MAX_AGE.getPreferredName(), maxAge.getStringRep()); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
||
public TimeValue getMaxAge() { | ||
return maxAge; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
final TimeRetentionPolicyConfig that = (TimeRetentionPolicyConfig) other; | ||
|
||
return Objects.equals(this.field, that.field) && Objects.equals(this.maxAge, that.maxAge); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(field, maxAge); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.