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 @@ -8,10 +8,10 @@

import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ProjectState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.ProjectId;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.xcontent.ToXContentObject;

/**
Expand Down Expand Up @@ -40,7 +40,7 @@ protected Client getClient(ProjectId projectId) {
return client.projectClient(projectId);
}

public abstract void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout);
public abstract void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout);

public interface Listener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ProjectState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.TimeValue;
Expand Down Expand Up @@ -56,7 +57,8 @@ public int getMaxNumSegments() {
}

@Override
public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) {
public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) {
Index index = indexMetadata.getIndex();
getClient(state.projectId()).admin()
.indices()
.segments(new IndicesSegmentsRequest(index.getName()), ActionListener.wrap(response -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
Expand All @@ -39,16 +38,15 @@ public boolean isRetryable() {
}

@Override
public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) {
IndexMetadata indexMetadata = state.metadata().index(index);
public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) {
Map<String, String> customIndexMetadata = indexMetadata.getCustomData(CCR_METADATA_KEY);
if (customIndexMetadata == null) {
listener.onResponse(true, null);
return;
}

FollowStatsAction.StatsRequest request = new FollowStatsAction.StatsRequest();
request.setIndices(new String[] { index.getName() });
request.setIndices(new String[] { indexMetadata.getIndex().getName() });
getClient(state.projectId()).execute(
FollowStatsAction.INSTANCE,
request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import org.elasticsearch.action.admin.indices.stats.ShardStats;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ProjectState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.ProjectId;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
Expand Down Expand Up @@ -53,7 +53,7 @@ public boolean isRetryable() {
}

@Override
public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) {
public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) {
XPackInfoRequest xPackInfoRequest = new XPackInfoRequest();
xPackInfoRequest.setCategories(EnumSet.of(XPackInfoRequest.Category.FEATURES));
getClient(state.projectId()).execute(XPackInfoFeatureAction.CCR, xPackInfoRequest, ActionListener.wrap((xPackInfoResponse) -> {
Expand All @@ -62,14 +62,13 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener
listener.onResponse(true, null);
return;
}
leaderIndexCheck(state.projectId(), index, listener);
leaderIndexCheck(state.projectId(), indexMetadata.getIndex().getName(), listener);
}, listener::onFailure));
}

private void leaderIndexCheck(ProjectId projectId, Index index, Listener listener) {
private void leaderIndexCheck(ProjectId projectId, String indexName, Listener listener) {
IndicesStatsRequest request = new IndicesStatsRequest();
request.clear();
String indexName = index.getName();
request.indices(indexName);

getClient(projectId).admin().indices().stats(request, ActionListener.wrap((response) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public boolean isRetryable() {
}

@Override
public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) {
public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) {
Index index = indexMetadata.getIndex();
IndexAbstraction indexAbstraction = state.metadata().getIndicesLookup().get(index.getName());
assert indexAbstraction != null : "invalid cluster metadata. index [" + index.getName() + "] was not found";
final String rolloverTarget;
Expand All @@ -95,14 +96,13 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener
index.getName(),
targetFailureStore ? "failure store " : "",
dataStream.getName(),
state.metadata().index(index).getLifecyclePolicyName()
indexMetadata.getLifecyclePolicyName()
);
listener.onResponse(true, EmptyInfo.INSTANCE);
return;
}
rolloverTarget = dataStream.getName();
} else {
IndexMetadata indexMetadata = state.metadata().index(index);
String rolloverAlias = RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.get(indexMetadata.getSettings());

if (Strings.isNullOrEmpty(rolloverAlias)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xpack.core.ilm.step.info.EmptyInfo;
import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata;
Expand Down Expand Up @@ -43,7 +42,6 @@ public class WaitForSnapshotStep extends AsyncWaitStep {

private static final String UNEXPECTED_SNAPSHOT_STATE_MESSAGE =
"unexpected number of snapshots retrieved for repository '%s' and snapshot '%s' (expected 1, found %d)";
private static final String NO_INDEX_METADATA_MESSAGE = "no index metadata found for index '%s'";
private static final String NO_ACTION_TIME_MESSAGE = "no information about ILM action start in index metadata for index '%s'";

private final String policy;
Expand All @@ -54,17 +52,12 @@ public class WaitForSnapshotStep extends AsyncWaitStep {
}

@Override
public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) {
IndexMetadata indexMetadata = state.metadata().index(index);
if (indexMetadata == null) {
listener.onFailure(error(NO_INDEX_METADATA_MESSAGE, index.getName()));
return;
}

public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) {
String indexName = indexMetadata.getIndex().getName();
Long actionTime = indexMetadata.getLifecycleExecutionState().actionTime();

if (actionTime == null) {
listener.onFailure(error(NO_ACTION_TIME_MESSAGE, index.getName()));
listener.onFailure(error(NO_ACTION_TIME_MESSAGE, indexName));
return;
}

Expand Down Expand Up @@ -112,10 +105,10 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener
if (response.getSnapshots().size() != 1) {
listener.onFailure(error(UNEXPECTED_SNAPSHOT_STATE_MESSAGE, repositoryName, snapshotName, response.getSnapshots().size()));
} else {
if (response.getSnapshots().get(0).indices().contains(index.getName())) {
if (response.getSnapshots().get(0).indices().contains(indexName)) {
listener.onResponse(true, EmptyInfo.INSTANCE);
} else {
listener.onFailure(error(INDEX_NOT_INCLUDED_IN_SNAPSHOT_MESSAGE, policy, index.getName()));
listener.onFailure(error(INDEX_NOT_INCLUDED_IN_SNAPSHOT_MESSAGE, policy, indexName));
}
}
}, listener::onFailure));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.xpack.core.ilm.step.info.EmptyInfo;
import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo;

Expand Down Expand Up @@ -66,18 +65,15 @@ public boolean equals(Object obj) {
}

@Override
public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) {
IndexMetadata indexMetadata = state.metadata().index(index);
assert indexMetadata != null
: "the index metadata for index [" + index.getName() + "] must exist in the cluster state for step [" + NAME + "]";

final LifecycleExecutionState executionState = state.metadata().index(index.getName()).getLifecycleExecutionState();
public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) {
String indexName = indexMetadata.getIndex().getName();
final LifecycleExecutionState executionState = indexMetadata.getLifecycleExecutionState();
assert executionState != null
: "the lifecycle execution state for index [" + index.getName() + "] must exist in the cluster state for step [" + NAME + "]";
: "the lifecycle execution state for index [" + indexName + "] must exist in the cluster state for step [" + NAME + "]";

if (replicateFor == null) {
// assert at dev-time, but treat this as a no-op at runtime if somehow this should happen (which it shouldn't)
assert false : "the replicate_for time value for index [" + index.getName() + "] must not be null for step [" + NAME + "]";
assert false : "the replicate_for time value for index [" + indexName + "] must not be null for step [" + NAME + "]";
listener.onResponse(true, EmptyInfo.INSTANCE);
return;
}
Expand All @@ -97,7 +93,7 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener
// balance between precision and efficiency.
approximateTimeRemaining(remaining),
this.replicateFor,
index.getName()
indexName
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.xpack.core.ilm.step.info.EmptyInfo;
Expand Down Expand Up @@ -43,18 +42,15 @@ public boolean isRetryable() {
}

@Override
public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) {
IndexMetadata indexMetadata = state.metadata().index(index);
assert indexMetadata != null
: "the index metadata for index [" + index.getName() + "] must exist in the cluster state for step [" + NAME + "]";

public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) {
String indexName = indexMetadata.getIndex().getName();
if (IndexSettings.MODE.get(indexMetadata.getSettings()) != IndexMode.TIME_SERIES) {
// this index is not a time series index so no need to wait
listener.onResponse(true, EmptyInfo.INSTANCE);
return;
}
Instant configuredEndTime = IndexSettings.TIME_SERIES_END_TIME.get(indexMetadata.getSettings());
assert configuredEndTime != null : "a time series index must have an end time configured but [" + index.getName() + "] does not";
assert configuredEndTime != null : "a time series index must have an end time configured but [" + indexName + "] does not";
if (nowSupplier.get().isBefore(configuredEndTime)) {
listener.onResponse(
false,
Expand All @@ -63,7 +59,7 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener
"The [%s] setting for index [%s] is [%s]. Waiting until the index's time series end time lapses before"
+ " proceeding with action [%s] as the index can still accept writes.",
IndexSettings.TIME_SERIES_END_TIME.getKey(),
index.getName(),
indexName,
configuredEndTime.toEpochMilli(),
getKey().action()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void testIsConditionMet() {
SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments);
IndexMetadata indexMetadata = makeMeta(index);
final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true));
step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() {
@Override
public void onResponse(boolean conditionMet, ToXContentObject info) {
conditionMetResult.set(conditionMet);
Expand Down Expand Up @@ -157,7 +157,7 @@ public void testIsConditionIsTrueEvenWhenMoreSegments() {
SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments);
IndexMetadata indexMetadata = makeMeta(index);
final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true));
step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() {
@Override
public void onResponse(boolean conditionMet, ToXContentObject info) {
conditionMetResult.set(conditionMet);
Expand Down Expand Up @@ -215,7 +215,7 @@ public void testFailedToRetrieveSomeSegments() {
SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments);
IndexMetadata indexMetadata = makeMeta(index);
final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true));
step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() {
@Override
public void onResponse(boolean conditionMet, ToXContentObject info) {
conditionMetResult.set(conditionMet);
Expand Down Expand Up @@ -253,7 +253,7 @@ public void testThrowsException() {
SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments);
IndexMetadata indexMetadata = makeMeta(index);
final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true));
step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() {
@Override
public void onResponse(boolean conditionMet, ToXContentObject info) {
throw new AssertionError("unexpected method call");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testConditionMet() {
final ToXContentObject[] informationContextHolder = new ToXContentObject[1];
final Exception[] exceptionHolder = new Exception[1];
final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true));
createRandomInstance().evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
createRandomInstance().evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() {
@Override
public void onResponse(boolean conditionMet, ToXContentObject informationContext) {
conditionMetHolder[0] = conditionMet;
Expand Down Expand Up @@ -106,7 +106,7 @@ public void testConditionNotMetShardsNotInSync() {
final ToXContentObject[] informationContextHolder = new ToXContentObject[1];
final Exception[] exceptionHolder = new Exception[1];
final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true));
createRandomInstance().evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
createRandomInstance().evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() {
@Override
public void onResponse(boolean conditionMet, ToXContentObject informationContext) {
conditionMetHolder[0] = conditionMet;
Expand Down Expand Up @@ -140,7 +140,7 @@ public void testConditionNotMetNotAFollowerIndex() {
final ToXContentObject[] informationContextHolder = new ToXContentObject[1];
final Exception[] exceptionHolder = new Exception[1];
final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true));
createRandomInstance().evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
createRandomInstance().evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() {
@Override
public void onResponse(boolean conditionMet, ToXContentObject informationContext) {
conditionMetHolder[0] = conditionMet;
Expand Down
Loading