Skip to content

Commit 3a23c7f

Browse files
committed
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 0fccfc1 commit 3a23c7f

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.elasticsearch.cluster.service.ClusterService;
3333
import org.elasticsearch.common.CheckedConsumer;
3434
import org.elasticsearch.common.settings.IndexScopedSettings;
35+
import org.elasticsearch.common.settings.Setting;
3536
import org.elasticsearch.common.settings.Settings;
3637
import org.elasticsearch.common.settings.SettingsModule;
3738
import org.elasticsearch.common.unit.TimeValue;
@@ -173,10 +174,13 @@ protected void innerUpdateSettings(final LongConsumer finalHandler, final Consum
173174
finalHandler.accept(leaderIMD.getSettingsVersion());
174175
} else {
175176
// Figure out which settings have been updated:
176-
final Settings updatedSettings = settings.filter(
177-
s -> existingSettings.get(s) == null || existingSettings.get(s).equals(settings.get(s)) == false
178-
);
179-
177+
final Settings updatedSettings = settings.filter(s -> {
178+
final Setting<?> indexSettings = indexScopedSettings.get(s);
179+
if (indexSettings == null || indexSettings.isPrivateIndex() || indexSettings.isInternalIndex()) {
180+
return false;
181+
}
182+
return existingSettings.get(s) == null || existingSettings.get(s).equals(settings.get(s)) == false;
183+
});
180184
// Figure out whether the updated settings are all dynamic settings and
181185
// if so just update the follower index's settings:
182186
if (updatedSettings.keySet().stream().allMatch(indexScopedSettings::isDynamicSetting)) {

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

+61
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
import org.elasticsearch.action.support.WriteRequest;
4242
import org.elasticsearch.client.Requests;
4343
import org.elasticsearch.cluster.ClusterState;
44+
import org.elasticsearch.cluster.ClusterStateUpdateTask;
4445
import org.elasticsearch.cluster.health.ClusterIndexHealth;
4546
import org.elasticsearch.cluster.health.ClusterShardHealth;
4647
import org.elasticsearch.cluster.metadata.IndexMetaData;
4748
import org.elasticsearch.cluster.metadata.MappingMetaData;
49+
import org.elasticsearch.cluster.metadata.MetaData;
4850
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
4951
import org.elasticsearch.cluster.routing.RoutingTable;
5052
import org.elasticsearch.cluster.service.ClusterService;
@@ -64,6 +66,7 @@
6466
import org.elasticsearch.index.seqno.RetentionLeaseActions;
6567
import org.elasticsearch.index.shard.ShardId;
6668
import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
69+
import org.elasticsearch.plugins.Plugin;
6770
import org.elasticsearch.rest.RestStatus;
6871
import org.elasticsearch.snapshots.SnapshotRestoreException;
6972
import org.elasticsearch.tasks.TaskInfo;
@@ -84,6 +87,7 @@
8487
import org.elasticsearch.xpack.core.ccr.action.UnfollowAction;
8588

8689
import java.io.IOException;
90+
import java.util.Arrays;
8791
import java.util.Collection;
8892
import java.util.Collections;
8993
import java.util.HashMap;
@@ -98,6 +102,7 @@
98102
import java.util.function.BooleanSupplier;
99103
import java.util.function.Consumer;
100104
import java.util.stream.Collectors;
105+
import java.util.stream.Stream;
101106

102107
import static java.util.Collections.singletonMap;
103108
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@@ -114,6 +119,11 @@
114119

115120
public class IndexFollowingIT extends CcrIntegTestCase {
116121

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+
117127
public void testFollowIndex() throws Exception {
118128
final int numberOfPrimaryShards = randomIntBetween(1, 3);
119129
int numberOfReplicas = between(0, 1);
@@ -969,6 +979,46 @@ public void testUpdateAnalysisLeaderIndexSettings() throws Exception {
969979
assertThat(hasFollowIndexBeenClosedChecker.getAsBoolean(), is(true));
970980
}
971981

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+
9721022
public void testMustCloseIndexAndPauseToRestartWithPutFollowing() throws Exception {
9731023
final int numberOfPrimaryShards = randomIntBetween(1, 3);
9741024
final String leaderIndexSettings = getIndexSettings(numberOfPrimaryShards, between(0, 1),
@@ -1336,4 +1386,15 @@ private String getIndexSettingsWithNestedMapping(final int numberOfShards, final
13361386
return settings;
13371387
}
13381388

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

0 commit comments

Comments
 (0)