|
44 | 44 | import org.elasticsearch.action.support.WriteRequest;
|
45 | 45 | import org.elasticsearch.client.Requests;
|
46 | 46 | import org.elasticsearch.cluster.ClusterState;
|
| 47 | +import org.elasticsearch.cluster.ClusterStateUpdateTask; |
47 | 48 | import org.elasticsearch.cluster.health.ClusterIndexHealth;
|
48 | 49 | import org.elasticsearch.cluster.health.ClusterShardHealth;
|
49 | 50 | import org.elasticsearch.cluster.metadata.AliasMetaData;
|
50 | 51 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
51 | 52 | import org.elasticsearch.cluster.metadata.MappingMetaData;
|
| 53 | +import org.elasticsearch.cluster.metadata.MetaData; |
52 | 54 | import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
53 | 55 | import org.elasticsearch.cluster.routing.RoutingTable;
|
54 | 56 | import org.elasticsearch.cluster.service.ClusterService;
|
|
68 | 70 | import org.elasticsearch.index.seqno.RetentionLeaseActions;
|
69 | 71 | import org.elasticsearch.index.shard.ShardId;
|
70 | 72 | import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
|
| 73 | +import org.elasticsearch.plugins.Plugin; |
71 | 74 | import org.elasticsearch.rest.RestStatus;
|
72 | 75 | import org.elasticsearch.snapshots.SnapshotRestoreException;
|
73 | 76 | import org.elasticsearch.tasks.TaskInfo;
|
|
88 | 91 | import org.elasticsearch.xpack.core.ccr.action.UnfollowAction;
|
89 | 92 |
|
90 | 93 | import java.io.IOException;
|
| 94 | +import java.util.Arrays; |
91 | 95 | import java.util.Collection;
|
92 | 96 | import java.util.Collections;
|
93 | 97 | import java.util.HashMap;
|
|
102 | 106 | import java.util.function.BooleanSupplier;
|
103 | 107 | import java.util.function.Consumer;
|
104 | 108 | import java.util.stream.Collectors;
|
| 109 | +import java.util.stream.Stream; |
105 | 110 |
|
106 | 111 | import static java.util.Collections.singletonMap;
|
107 | 112 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
120 | 125 |
|
121 | 126 | public class IndexFollowingIT extends CcrIntegTestCase {
|
122 | 127 |
|
| 128 | + @Override |
| 129 | + protected Collection<Class<? extends Plugin>> nodePlugins() { |
| 130 | + return Stream.concat(super.nodePlugins().stream(), Stream.of(PrivateSettingPlugin.class)).collect(Collectors.toList()); |
| 131 | + } |
| 132 | + |
123 | 133 | public void testFollowIndex() throws Exception {
|
124 | 134 | final int numberOfPrimaryShards = randomIntBetween(1, 3);
|
125 | 135 | int numberOfReplicas = between(0, 1);
|
@@ -1012,6 +1022,46 @@ public void testUpdateAnalysisLeaderIndexSettings() throws Exception {
|
1012 | 1022 | assertThat(hasFollowIndexBeenClosedChecker.getAsBoolean(), is(true));
|
1013 | 1023 | }
|
1014 | 1024 |
|
| 1025 | + public void testDoNotReplicatePrivateSettings() throws Exception { |
| 1026 | + assertAcked(leaderClient().admin().indices().prepareCreate("leader").setSource( |
| 1027 | + getIndexSettings(1, 0, singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true")), XContentType.JSON)); |
| 1028 | + ensureLeaderGreen("leader"); |
| 1029 | + final PutFollowAction.Request followRequest = putFollow("leader", "follower"); |
| 1030 | + followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); |
| 1031 | + ClusterService clusterService = getLeaderCluster().getInstance(ClusterService.class, getLeaderCluster().getMasterName()); |
| 1032 | + clusterService.submitStateUpdateTask("test", new ClusterStateUpdateTask() { |
| 1033 | + @Override |
| 1034 | + public ClusterState execute(ClusterState currentState) { |
| 1035 | + final IndexMetaData indexMetaData = currentState.metaData().index("leader"); |
| 1036 | + Settings.Builder settings = Settings.builder() |
| 1037 | + .put(indexMetaData.getSettings()) |
| 1038 | + .put("index.max_ngram_diff", 2); |
| 1039 | + if (randomBoolean()) { |
| 1040 | + settings.put(PrivateSettingPlugin.INDEX_INTERNAL_SETTING.getKey(), "private-value"); |
| 1041 | + } |
| 1042 | + if (randomBoolean()) { |
| 1043 | + settings.put(PrivateSettingPlugin.INDEX_PRIVATE_SETTING.getKey(), "interval-value"); |
| 1044 | + } |
| 1045 | + final MetaData.Builder metadata = MetaData.builder(currentState.metaData()) |
| 1046 | + .put(IndexMetaData.builder(indexMetaData) |
| 1047 | + .settingsVersion(indexMetaData.getSettingsVersion() + 1) |
| 1048 | + .settings(settings).build(), true); |
| 1049 | + return ClusterState.builder(currentState).metaData(metadata).build(); |
| 1050 | + } |
| 1051 | + |
| 1052 | + @Override |
| 1053 | + public void onFailure(String source, Exception e) { |
| 1054 | + throw new AssertionError(e); |
| 1055 | + } |
| 1056 | + }); |
| 1057 | + assertBusy(() -> { |
| 1058 | + GetSettingsResponse resp = followerClient().admin().indices().prepareGetSettings("follower").get(); |
| 1059 | + assertThat(resp.getSetting("follower", "index.max_ngram_diff"), equalTo("2")); |
| 1060 | + assertThat(resp.getSetting("follower", PrivateSettingPlugin.INDEX_INTERNAL_SETTING.getKey()), nullValue()); |
| 1061 | + assertThat(resp.getSetting("follower", PrivateSettingPlugin.INDEX_PRIVATE_SETTING.getKey()), nullValue()); |
| 1062 | + }); |
| 1063 | + } |
| 1064 | + |
1015 | 1065 | public void testMustCloseIndexAndPauseToRestartWithPutFollowing() throws Exception {
|
1016 | 1066 | final int numberOfPrimaryShards = randomIntBetween(1, 3);
|
1017 | 1067 | final String leaderIndexSettings = getIndexSettings(numberOfPrimaryShards, between(0, 1),
|
@@ -1379,4 +1429,15 @@ private String getIndexSettingsWithNestedMapping(final int numberOfShards, final
|
1379 | 1429 | return settings;
|
1380 | 1430 | }
|
1381 | 1431 |
|
| 1432 | + public static class PrivateSettingPlugin extends Plugin { |
| 1433 | + static final Setting<String> INDEX_INTERNAL_SETTING = |
| 1434 | + Setting.simpleString("index.internal", Setting.Property.IndexScope, Setting.Property.InternalIndex); |
| 1435 | + static final Setting<String> INDEX_PRIVATE_SETTING = |
| 1436 | + Setting.simpleString("index.private", Setting.Property.IndexScope, Setting.Property.PrivateIndex); |
| 1437 | + |
| 1438 | + @Override |
| 1439 | + public List<Setting<?>> getSettings() { |
| 1440 | + return Arrays.asList(INDEX_INTERNAL_SETTING, INDEX_PRIVATE_SETTING); |
| 1441 | + } |
| 1442 | + } |
1382 | 1443 | }
|
0 commit comments