From 12d45cb43e736659cb9ee912cbb4537c6147dd9f Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Fri, 8 Nov 2019 12:42:25 -0500 Subject: [PATCH 1/3] Improve error message when pausing index --- .../action/TransportPauseFollowAction.java | 15 +++++++++++-- .../xpack/ccr/IndexFollowingIT.java | 21 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java index 52b2e8bbdae68..acc18dc1c336c 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java @@ -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; @@ -57,8 +60,16 @@ protected AcknowledgedResponse read(StreamInput in) throws IOException { @Override protected void masterOperation(Task task, PauseFollowAction.Request request, - ClusterState state, - ActionListener listener) throws Exception { + ClusterState state, ActionListener 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() + "]")); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index 42dcb709b6591..f548af8a3ccd8 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -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()); From 2f4d442cc4ec16a65535a6b5ac22f34a7d3c95db Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Mon, 11 Nov 2019 08:00:26 -0500 Subject: [PATCH 2/3] fix test --- .../test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index f548af8a3ccd8..7bf5ce22892b4 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -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()); } From 6b12208f63f6c1e49e3db6ff4c2a2965e6ed0760 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Mon, 11 Nov 2019 08:13:09 -0500 Subject: [PATCH 3/3] adjust message --- .../xpack/ccr/action/TransportPauseFollowAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java index acc18dc1c336c..25e9df1ea231f 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java @@ -72,7 +72,7 @@ protected void masterOperation(Task task, PauseFollowAction.Request request, } 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; }