Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow removing index.number_of_replicas setting #56656

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,28 @@ public void testNumberOfReplicasSettingsVersion() {
assertThat(newSettingsVersion, equalTo(1 + settingsVersion));
}

/*
* Test that we are able to set the setting index.number_of_replicas to the default.
*/
public void testDefaultNumberOfReplicas() {
if (randomBoolean()) {
assertAcked(client().admin()
.indices()
.prepareCreate("test")
.setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, randomIntBetween(1, 8))));
} else {
assertAcked(client().admin().indices().prepareCreate("test"));
}

/*
* Previous versions of Elasticsearch would throw an exception that the number of replicas had to have a value, and could not be
* null. In the update settings logic, we ensure this by providing an explicit default value if the setting is set to null.
*/
assertAcked(client().admin()
.indices()
.prepareUpdateSettings("test")
.setSettings(Settings.builder().putNull(IndexMetadata.SETTING_NUMBER_OF_REPLICAS)));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ public ClusterState execute(ClusterState currentState) {
if (preserveExisting) {
indexSettings.put(indexMetadata.getSettings());
}
/*
* The setting index.number_of_replicas is special; we require that this setting has a value in the index. When
* creating the index, we ensure this by explicitly providing a value for the setting to the default (one) if
* there is a not value provided on the source of the index creation. A user can update this setting though,
* including updating it to null, indicating that they want to use the default value. In this case, we again
* have to provide an explicit value for the setting to the default (one).
*/
if (indexSettings.get(IndexMetadata.SETTING_NUMBER_OF_REPLICAS) == null) {
indexSettings.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1);
}
Settings finalSettings = indexSettings.build();
indexScopedSettings.validate(
finalSettings.filter(k -> indexScopedSettings.isPrivateSetting(k) == false), true);
Expand Down