浏览代码

[CCR] Make index.xpack.ccr.following_index an internal setting (#33768)

Martijn van Groningen 7 年之前
父节点
当前提交
7046cc467f

+ 1 - 1
x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrSettings.java

@@ -27,7 +27,7 @@ public final class CcrSettings {
      * Index setting for a following index.
      */
     public static final Setting<Boolean> CCR_FOLLOWING_INDEX_SETTING =
-            Setting.boolSetting("index.xpack.ccr.following_index", false, Setting.Property.IndexScope);
+            Setting.boolSetting("index.xpack.ccr.following_index", false, Property.IndexScope, Property.InternalIndex);
 
     /**
      * Setting for controlling the interval in between polling leader clusters to check whether there are indices to follow

+ 20 - 0
x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/ShardChangesIT.java

@@ -9,6 +9,8 @@ package org.elasticsearch.xpack.ccr;
 import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
 import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
 import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
+import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
+import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
 import org.elasticsearch.action.admin.indices.stats.ShardStats;
 import org.elasticsearch.action.bulk.BulkProcessor;
 import org.elasticsearch.action.bulk.BulkRequest;
@@ -477,6 +479,24 @@ public class ShardChangesIT extends ESIntegTestCase {
         assertThat(e.getMessage(), containsString("follow index [index2] should reference"));
     }
 
+    public void testAttemptToChangeCcrFollowingIndexSetting() throws Exception {
+        String leaderIndexSettings = getIndexSettings(1, 0, singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true"));
+        assertAcked(client().admin().indices().prepareCreate("index1").setSource(leaderIndexSettings, XContentType.JSON).get());
+        ensureYellow("index1");
+        FollowIndexAction.Request followRequest = createFollowRequest("index1", "index2");
+        CreateAndFollowIndexAction.Request createAndFollowRequest = new CreateAndFollowIndexAction.Request(followRequest);
+        client().execute(CreateAndFollowIndexAction.INSTANCE, createAndFollowRequest).get();
+        unfollowIndex("index2");
+        client().admin().indices().close(new CloseIndexRequest("index2")).actionGet();
+
+        UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest("index2");
+        updateSettingsRequest.settings(Settings.builder().put(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey(), false).build());
+        Exception e = expectThrows(IllegalArgumentException.class,
+            () -> client().admin().indices().updateSettings(updateSettingsRequest).actionGet());
+        assertThat(e.getMessage(), equalTo("can not update internal setting [index.xpack.ccr.following_index]; " +
+            "this setting is managed via a dedicated API"));
+    }
+
     private CheckedRunnable<Exception> assertTask(final int numberOfPrimaryShards, final Map<ShardId, Long> numDocsPerShard) {
         return () -> {
             final ClusterState clusterState = client().admin().cluster().prepareState().get().getState();