Skip to content

Commit 4b44561

Browse files
authored
CCR should not replicate private/internal settings (#43067)
With this change, CCR will not replicate internal or private settings to follower indices. Closes #41268
1 parent efc6b31 commit 4b44561

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.cluster.service.ClusterService;
3535
import org.elasticsearch.common.CheckedConsumer;
3636
import org.elasticsearch.common.settings.IndexScopedSettings;
37+
import org.elasticsearch.common.settings.Setting;
3738
import org.elasticsearch.common.settings.Settings;
3839
import org.elasticsearch.common.settings.SettingsModule;
3940
import org.elasticsearch.common.unit.TimeValue;
@@ -177,10 +178,13 @@ protected void innerUpdateSettings(final LongConsumer finalHandler, final Consum
177178
finalHandler.accept(leaderIMD.getSettingsVersion());
178179
} else {
179180
// Figure out which settings have been updated:
180-
final Settings updatedSettings = settings.filter(
181-
s -> existingSettings.get(s) == null || existingSettings.get(s).equals(settings.get(s)) == false
182-
);
183-
181+
final Settings updatedSettings = settings.filter(s -> {
182+
final Setting<?> indexSettings = indexScopedSettings.get(s);
183+
if (indexSettings == null || indexSettings.isPrivateIndex() || indexSettings.isInternalIndex()) {
184+
return false;
185+
}
186+
return existingSettings.get(s) == null || existingSettings.get(s).equals(settings.get(s)) == false;
187+
});
184188
// Figure out whether the updated settings are all dynamic settings and
185189
// if so just update the follower index's settings:
186190
if (updatedSettings.keySet().stream().allMatch(indexScopedSettings::isDynamicSetting)) {

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java

+61
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@
4444
import org.elasticsearch.action.support.WriteRequest;
4545
import org.elasticsearch.client.Requests;
4646
import org.elasticsearch.cluster.ClusterState;
47+
import org.elasticsearch.cluster.ClusterStateUpdateTask;
4748
import org.elasticsearch.cluster.health.ClusterIndexHealth;
4849
import org.elasticsearch.cluster.health.ClusterShardHealth;
4950
import org.elasticsearch.cluster.metadata.AliasMetaData;
5051
import org.elasticsearch.cluster.metadata.IndexMetaData;
5152
import org.elasticsearch.cluster.metadata.MappingMetaData;
53+
import org.elasticsearch.cluster.metadata.MetaData;
5254
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
5355
import org.elasticsearch.cluster.routing.RoutingTable;
5456
import org.elasticsearch.cluster.service.ClusterService;
@@ -68,6 +70,7 @@
6870
import org.elasticsearch.index.seqno.RetentionLeaseActions;
6971
import org.elasticsearch.index.shard.ShardId;
7072
import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
73+
import org.elasticsearch.plugins.Plugin;
7174
import org.elasticsearch.rest.RestStatus;
7275
import org.elasticsearch.snapshots.SnapshotRestoreException;
7376
import org.elasticsearch.tasks.TaskInfo;
@@ -88,6 +91,7 @@
8891
import org.elasticsearch.xpack.core.ccr.action.UnfollowAction;
8992

9093
import java.io.IOException;
94+
import java.util.Arrays;
9195
import java.util.Collection;
9296
import java.util.Collections;
9397
import java.util.HashMap;
@@ -102,6 +106,7 @@
102106
import java.util.function.BooleanSupplier;
103107
import java.util.function.Consumer;
104108
import java.util.stream.Collectors;
109+
import java.util.stream.Stream;
105110

106111
import static java.util.Collections.singletonMap;
107112
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@@ -120,6 +125,11 @@
120125

121126
public class IndexFollowingIT extends CcrIntegTestCase {
122127

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+
123133
public void testFollowIndex() throws Exception {
124134
final int numberOfPrimaryShards = randomIntBetween(1, 3);
125135
int numberOfReplicas = between(0, 1);
@@ -1012,6 +1022,46 @@ public void testUpdateAnalysisLeaderIndexSettings() throws Exception {
10121022
assertThat(hasFollowIndexBeenClosedChecker.getAsBoolean(), is(true));
10131023
}
10141024

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+
10151065
public void testMustCloseIndexAndPauseToRestartWithPutFollowing() throws Exception {
10161066
final int numberOfPrimaryShards = randomIntBetween(1, 3);
10171067
final String leaderIndexSettings = getIndexSettings(numberOfPrimaryShards, between(0, 1),
@@ -1379,4 +1429,15 @@ private String getIndexSettingsWithNestedMapping(final int numberOfShards, final
13791429
return settings;
13801430
}
13811431

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+
}
13821443
}

0 commit comments

Comments
 (0)