Skip to content
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

Improve error message when pausing index #48915

Merged
merged 4 commits into from
Nov 11, 2019
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 @@ -13,15 +13,18 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
import org.elasticsearch.persistent.PersistentTasksService;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.ccr.Ccr;
import org.elasticsearch.xpack.core.ccr.action.PauseFollowAction;

import java.io.IOException;
Expand Down Expand Up @@ -57,11 +60,19 @@ protected AcknowledgedResponse read(StreamInput in) throws IOException {

@Override
protected void masterOperation(Task task, PauseFollowAction.Request request,
ClusterState state,
ActionListener<AcknowledgedResponse> listener) throws Exception {
ClusterState state, ActionListener<AcknowledgedResponse> listener) {
final IndexMetaData followerIMD = state.metaData().index(request.getFollowIndex());
if (followerIMD == null) {
listener.onFailure(new IndexNotFoundException(request.getFollowIndex()));
return;
}
if (followerIMD.getCustomData(Ccr.CCR_CUSTOM_METADATA_KEY) == null) {
listener.onFailure(new IllegalArgumentException("index [" + request.getFollowIndex() + "] is not a follower index"));
return;
}
PersistentTasksCustomMetaData persistentTasksMetaData = state.metaData().custom(PersistentTasksCustomMetaData.TYPE);
if (persistentTasksMetaData == null) {
listener.onFailure(new IllegalArgumentException("no shard follow tasks for [" + request.getFollowIndex() + "]"));
listener.onFailure(new IllegalArgumentException("no shard follow tasks found"));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public void testFollowIndexWithNestedField() throws Exception {

public void testUnfollowNonExistingIndex() {
PauseFollowAction.Request unfollowRequest = new PauseFollowAction.Request("non-existing-index");
expectThrows(IllegalArgumentException.class,
expectThrows(IndexNotFoundException.class,
() -> followerClient().execute(PauseFollowAction.INSTANCE, unfollowRequest).actionGet());
}

Expand Down Expand Up @@ -817,6 +817,27 @@ public void testDeleteFollowerIndex() throws Exception {
ensureNoCcrTasks();
}

public void testPauseIndex() throws Exception {
assertAcked(leaderClient().admin().indices().prepareCreate("leader")
.setSettings(Settings.builder()
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.build()));
followerClient().execute(PutFollowAction.INSTANCE, putFollow("leader", "follower")).get();
assertAcked(followerClient().admin().indices().prepareCreate("regular-index"));
assertAcked(followerClient().execute(PauseFollowAction.INSTANCE, new PauseFollowAction.Request("follower")).actionGet());
assertThat(expectThrows(IllegalArgumentException.class, () -> followerClient().execute(
PauseFollowAction.INSTANCE, new PauseFollowAction.Request("follower")).actionGet()).getMessage(),
equalTo("no shard follow tasks for [follower]"));
assertThat(expectThrows(IllegalArgumentException.class, () -> followerClient().execute(
PauseFollowAction.INSTANCE, new PauseFollowAction.Request("regular-index")).actionGet()).getMessage(),
equalTo("index [regular-index] is not a follower index"));
assertThat(expectThrows(IndexNotFoundException.class, () -> followerClient().execute(
PauseFollowAction.INSTANCE, new PauseFollowAction.Request("xyz")).actionGet()).getMessage(),
equalTo("no such index [xyz]"));
}

public void testUnfollowIndex() throws Exception {
String leaderIndexSettings = getIndexSettings(1, 0, singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true"));
assertAcked(leaderClient().admin().indices().prepareCreate("index1").setSource(leaderIndexSettings, XContentType.JSON).get());
Expand Down