Skip to content

Commit

Permalink
Prevent changing the number of replicas on a closed index
Browse files Browse the repository at this point in the history
Setting the number of replicas on a closed index can leave the index
in an unopenable state since we might not be able to recover a quorum.
This commit simply prevents updating this setting on a closed index.

Closes elastic#9566
  • Loading branch information
s1monw committed May 29, 2015
1 parent 87a0c76 commit 0d7e637
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Expand Up @@ -231,9 +231,15 @@ public ClusterState execute(ClusterState currentState) {
}
}

if (closeIndices.size() > 0 && closeSettings.get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS) != null) {
throw new IllegalArgumentException(String.format(Locale.ROOT,
"Can't update [%s] on closed indices [%s] - can leave index in an unopenable state", IndexMetaData.SETTING_NUMBER_OF_REPLICAS,
closeIndices
));
}
if (!removedSettings.isEmpty() && !openIndices.isEmpty()) {
throw new IllegalArgumentException(String.format(Locale.ROOT,
"Can't update non dynamic settings[%s] for open indices[%s]",
"Can't update non dynamic settings[%s] for open indices [%s]",
removedSettings,
openIndices
));
Expand Down
Expand Up @@ -773,7 +773,7 @@ public void testUpdateSettings() throws Exception {
try {
verify(client().admin().indices().prepareUpdateSettings("barbaz").setSettings(Settings.builder().put("e", "f")), false);
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("Can't update non dynamic settings[[index.e]] for open indices[[barbaz]]"));
assertThat(e.getMessage(), equalTo("Can't update non dynamic settings[[index.e]] for open indices [[barbaz]]"));
}
verify(client().admin().indices().prepareUpdateSettings("baz*").setSettings(Settings.builder().put("a", "b")), true);
}
Expand Down
Expand Up @@ -92,6 +92,17 @@ public void testOpenCloseUpdateSettings() throws Exception {

client().admin().indices().prepareClose("test").execute().actionGet();

try {
client().admin().indices().prepareUpdateSettings("test")
.setSettings(Settings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
)
.execute().actionGet();
fail("can't change number of replicas on a closed index");
} catch (IllegalArgumentException ex) {
assertEquals(ex.getMessage(), "Can't update [index.number_of_replicas] on closed indices [[test]] - can leave index in an unopenable state");
// expected
}
client().admin().indices().prepareUpdateSettings("test")
.setSettings(Settings.settingsBuilder()
.put("index.refresh_interval", "1s") // this one can change
Expand Down

0 comments on commit 0d7e637

Please sign in to comment.