Skip to content

Commit

Permalink
Let the update index settings action fail if non dynamic settings are…
Browse files Browse the repository at this point in the history
… changed for open indices.

Closes #2647
  • Loading branch information
martijnvg committed Feb 13, 2013
1 parent 5ad540a commit 2193a8e
Showing 1 changed file with 21 additions and 15 deletions.
Expand Up @@ -158,6 +158,27 @@ public ClusterState execute(ClusterState currentState) {
RoutingTable.Builder routingTableBuilder = RoutingTable.builder().routingTable(currentState.routingTable());
MetaData.Builder metaDataBuilder = MetaData.newMetaDataBuilder().metaData(currentState.metaData());

// allow to change any settings to a close index, and only allow dynamic settings to be changed
// on an open index
Set<String> openIndices = Sets.newHashSet();
Set<String> closeIndices = Sets.newHashSet();
for (String index : actualIndices) {
if (currentState.metaData().index(index).state() == IndexMetaData.State.OPEN) {
openIndices.add(index);
} else {
closeIndices.add(index);
}
}

if (!removedSettings.isEmpty() && !openIndices.isEmpty()) {
listener.onFailure(new ElasticSearchIllegalArgumentException(String.format(
"Can't update non dynamic settings[%s] for open indices[%s]",
removedSettings,
openIndices
)));
return currentState;
}

int updatedNumberOfReplicas = openSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, -1);
if (updatedNumberOfReplicas != -1) {
routingTableBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
Expand Down Expand Up @@ -209,23 +230,8 @@ public ClusterState execute(ClusterState currentState) {
}
}

// allow to change any settings to a close index, and only allow dynamic settings to be changed
// on an open index
Set<String> openIndices = Sets.newHashSet();
Set<String> closeIndices = Sets.newHashSet();
for (String index : actualIndices) {
if (currentState.metaData().index(index).state() == IndexMetaData.State.OPEN) {
openIndices.add(index);
} else {
closeIndices.add(index);
}
}

if (!openIndices.isEmpty()) {
String[] indices = openIndices.toArray(new String[openIndices.size()]);
if (!removedSettings.isEmpty()) {
logger.warn("{} ignoring non dynamic index level settings for open indices: {}", indices, removedSettings);
}
metaDataBuilder.updateSettings(openSettings, indices);
}

Expand Down

0 comments on commit 2193a8e

Please sign in to comment.