|
41 | 41 | import org.elasticsearch.action.support.WriteRequest;
|
42 | 42 | import org.elasticsearch.client.Requests;
|
43 | 43 | import org.elasticsearch.cluster.ClusterState;
|
| 44 | +import org.elasticsearch.cluster.ClusterStateUpdateTask; |
44 | 45 | import org.elasticsearch.cluster.health.ClusterIndexHealth;
|
45 | 46 | import org.elasticsearch.cluster.health.ClusterShardHealth;
|
46 | 47 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
47 | 48 | import org.elasticsearch.cluster.metadata.MappingMetaData;
|
| 49 | +import org.elasticsearch.cluster.metadata.MetaData; |
48 | 50 | import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
49 | 51 | import org.elasticsearch.cluster.routing.RoutingTable;
|
50 | 52 | import org.elasticsearch.cluster.service.ClusterService;
|
|
64 | 66 | import org.elasticsearch.index.seqno.RetentionLeaseActions;
|
65 | 67 | import org.elasticsearch.index.shard.ShardId;
|
66 | 68 | import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
|
| 69 | +import org.elasticsearch.plugins.Plugin; |
67 | 70 | import org.elasticsearch.rest.RestStatus;
|
68 | 71 | import org.elasticsearch.snapshots.SnapshotRestoreException;
|
69 | 72 | import org.elasticsearch.tasks.TaskInfo;
|
|
84 | 87 | import org.elasticsearch.xpack.core.ccr.action.UnfollowAction;
|
85 | 88 |
|
86 | 89 | import java.io.IOException;
|
| 90 | +import java.util.Arrays; |
87 | 91 | import java.util.Collection;
|
88 | 92 | import java.util.Collections;
|
89 | 93 | import java.util.HashMap;
|
|
98 | 102 | import java.util.function.BooleanSupplier;
|
99 | 103 | import java.util.function.Consumer;
|
100 | 104 | import java.util.stream.Collectors;
|
| 105 | +import java.util.stream.Stream; |
101 | 106 |
|
102 | 107 | import static java.util.Collections.singletonMap;
|
103 | 108 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
114 | 119 |
|
115 | 120 | public class IndexFollowingIT extends CcrIntegTestCase {
|
116 | 121 |
|
| 122 | + @Override |
| 123 | + protected Collection<Class<? extends Plugin>> nodePlugins() { |
| 124 | + return Stream.concat(super.nodePlugins().stream(), Stream.of(PrivateSettingPlugin.class)).collect(Collectors.toList()); |
| 125 | + } |
| 126 | + |
117 | 127 | public void testFollowIndex() throws Exception {
|
118 | 128 | final int numberOfPrimaryShards = randomIntBetween(1, 3);
|
119 | 129 | int numberOfReplicas = between(0, 1);
|
@@ -969,6 +979,46 @@ public void testUpdateAnalysisLeaderIndexSettings() throws Exception {
|
969 | 979 | assertThat(hasFollowIndexBeenClosedChecker.getAsBoolean(), is(true));
|
970 | 980 | }
|
971 | 981 |
|
| 982 | + public void testDoNotReplicatePrivateSettings() throws Exception { |
| 983 | + assertAcked(leaderClient().admin().indices().prepareCreate("leader").setSource( |
| 984 | + getIndexSettings(1, 0, singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true")), XContentType.JSON)); |
| 985 | + ensureLeaderGreen("leader"); |
| 986 | + final PutFollowAction.Request followRequest = putFollow("leader", "follower"); |
| 987 | + followerClient().execute(PutFollowAction.INSTANCE, followRequest).get(); |
| 988 | + ClusterService clusterService = getLeaderCluster().getInstance(ClusterService.class, getLeaderCluster().getMasterName()); |
| 989 | + clusterService.submitStateUpdateTask("test", new ClusterStateUpdateTask() { |
| 990 | + @Override |
| 991 | + public ClusterState execute(ClusterState currentState) { |
| 992 | + final IndexMetaData indexMetaData = currentState.metaData().index("leader"); |
| 993 | + Settings.Builder settings = Settings.builder() |
| 994 | + .put(indexMetaData.getSettings()) |
| 995 | + .put("index.max_ngram_diff", 2); |
| 996 | + if (randomBoolean()) { |
| 997 | + settings.put(PrivateSettingPlugin.INDEX_INTERNAL_SETTING.getKey(), "private-value"); |
| 998 | + } |
| 999 | + if (randomBoolean()) { |
| 1000 | + settings.put(PrivateSettingPlugin.INDEX_PRIVATE_SETTING.getKey(), "interval-value"); |
| 1001 | + } |
| 1002 | + final MetaData.Builder metadata = MetaData.builder(currentState.metaData()) |
| 1003 | + .put(IndexMetaData.builder(indexMetaData) |
| 1004 | + .settingsVersion(indexMetaData.getSettingsVersion() + 1) |
| 1005 | + .settings(settings).build(), true); |
| 1006 | + return ClusterState.builder(currentState).metaData(metadata).build(); |
| 1007 | + } |
| 1008 | + |
| 1009 | + @Override |
| 1010 | + public void onFailure(String source, Exception e) { |
| 1011 | + throw new AssertionError(e); |
| 1012 | + } |
| 1013 | + }); |
| 1014 | + assertBusy(() -> { |
| 1015 | + GetSettingsResponse resp = followerClient().admin().indices().prepareGetSettings("follower").get(); |
| 1016 | + assertThat(resp.getSetting("follower", "index.max_ngram_diff"), equalTo("2")); |
| 1017 | + assertThat(resp.getSetting("follower", PrivateSettingPlugin.INDEX_INTERNAL_SETTING.getKey()), nullValue()); |
| 1018 | + assertThat(resp.getSetting("follower", PrivateSettingPlugin.INDEX_PRIVATE_SETTING.getKey()), nullValue()); |
| 1019 | + }); |
| 1020 | + } |
| 1021 | + |
972 | 1022 | public void testMustCloseIndexAndPauseToRestartWithPutFollowing() throws Exception {
|
973 | 1023 | final int numberOfPrimaryShards = randomIntBetween(1, 3);
|
974 | 1024 | final String leaderIndexSettings = getIndexSettings(numberOfPrimaryShards, between(0, 1),
|
@@ -1336,4 +1386,15 @@ private String getIndexSettingsWithNestedMapping(final int numberOfShards, final
|
1336 | 1386 | return settings;
|
1337 | 1387 | }
|
1338 | 1388 |
|
| 1389 | + public static class PrivateSettingPlugin extends Plugin { |
| 1390 | + static final Setting<String> INDEX_INTERNAL_SETTING = |
| 1391 | + Setting.simpleString("index.internal", Setting.Property.IndexScope, Setting.Property.InternalIndex); |
| 1392 | + static final Setting<String> INDEX_PRIVATE_SETTING = |
| 1393 | + Setting.simpleString("index.private", Setting.Property.IndexScope, Setting.Property.PrivateIndex); |
| 1394 | + |
| 1395 | + @Override |
| 1396 | + public List<Setting<?>> getSettings() { |
| 1397 | + return Arrays.asList(INDEX_INTERNAL_SETTING, INDEX_PRIVATE_SETTING); |
| 1398 | + } |
| 1399 | + } |
1339 | 1400 | }
|
0 commit comments