Skip to content
Closed
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 @@ -16,26 +16,56 @@
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.metadata.IndexAbstraction;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.Index;

import java.util.function.BiFunction;

/**
* Deletes a single index.
*/
public class DeleteStep extends AsyncRetryDuringSnapshotActionStep {

public static final String NAME = "delete";
private static final Logger logger = LogManager.getLogger(DeleteStep.class);
private static final BiFunction<String, LifecycleExecutionState, String> DEFAULT_TARGET_INDEX_NAME_SUPPLIER = (
indexName,
lifecycleState) -> indexName;

private final BiFunction<String, LifecycleExecutionState, String> targetIndexNameSupplier;
private final boolean indexSurvives;

/**
* Use this constructor to delete the index that ILM is currently operating on.
*/
public DeleteStep(StepKey key, StepKey nextStepKey, Client client) {
this(key, nextStepKey, client, DEFAULT_TARGET_INDEX_NAME_SUPPLIER, false);
}

/**
* Use this constructor to delete a specific index, potentially different from the one that ILM is currently operating on. The parameter
* {@code indexSurvives} indicates whether the index that ILM runs on will survive (i.e. not get deleted) this step.
* Look at the callers of {@link AsyncActionStep#indexSurvives()} for more details.
*/
public DeleteStep(
StepKey key,
StepKey nextStepKey,
Client client,
BiFunction<String, LifecycleExecutionState, String> targetIndexNameSupplier,
boolean indexSurvives
) {
super(key, nextStepKey, client);
this.targetIndexNameSupplier = targetIndexNameSupplier;
this.indexSurvives = indexSurvives;
}

@Override
public void performDuringNoSnapshot(IndexMetadata indexMetadata, ProjectMetadata currentProject, ActionListener<Void> listener) {
String policyName = indexMetadata.getLifecyclePolicyName();
String indexName = indexMetadata.getIndex().getName();
String indexName = targetIndexNameSupplier.apply(indexMetadata.getIndex().getName(), indexMetadata.getLifecycleExecutionState());
IndexAbstraction indexAbstraction = currentProject.getIndicesLookup().get(indexName);
assert indexAbstraction != null : "invalid cluster metadata. index [" + indexName + "] was not found";
DataStream dataStream = indexAbstraction.getParentDataStream();
Expand Down Expand Up @@ -88,7 +118,7 @@ public void performDuringNoSnapshot(IndexMetadata indexMetadata, ProjectMetadata

@Override
public boolean indexSurvives() {
return false;
return indexSurvives;
}

@Override
Expand Down