Update Settings: Allow to change non dynamic settings on a closed index, closes #1048.

This commit is contained in:
kimchy 2011-06-19 17:15:05 +03:00
parent 8470e79aed
commit 35fa6d93ad
2 changed files with 108 additions and 6 deletions

View File

@ -122,19 +122,20 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
}
}
Set<String> removedSettings = Sets.newHashSet();
final Settings closeSettings = updatedSettingsBuilder.build();
final Set<String> removedSettings = Sets.newHashSet();
for (String key : updatedSettingsBuilder.internalMap().keySet()) {
if (!IndexMetaData.dynamicSettings().contains(key)) {
removedSettings.add(key);
}
}
if (!removedSettings.isEmpty()) {
logger.warn("{} ignoring non dynamic index level settings: {}", indices, removedSettings);
for (String removedSetting : removedSettings) {
updatedSettingsBuilder.remove(removedSetting);
}
}
final Settings settings = updatedSettingsBuilder.build();
final Settings openSettings = updatedSettingsBuilder.build();
clusterService.submitStateUpdateTask("update-settings", new ProcessedClusterStateUpdateTask() {
@Override public ClusterState execute(ClusterState currentState) {
@ -143,14 +144,38 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
RoutingTable.Builder routingTableBuilder = newRoutingTableBuilder().routingTable(currentState.routingTable());
MetaData.Builder metaDataBuilder = MetaData.newMetaDataBuilder().metaData(currentState.metaData());
int updatedNumberOfReplicas = settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, -1);
int updatedNumberOfReplicas = openSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, -1);
if (updatedNumberOfReplicas != -1) {
routingTableBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
metaDataBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
logger.info("Updating number_of_replicas to [{}] for indices {}", updatedNumberOfReplicas, actualIndices);
logger.info("updating number_of_replicas to [{}] for indices {}", updatedNumberOfReplicas, actualIndices);
}
// 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);
}
if (!closeIndices.isEmpty()) {
String[] indices = closeIndices.toArray(new String[closeIndices.size()]);
metaDataBuilder.updateSettings(closeSettings, indices);
}
metaDataBuilder.updateSettings(settings, actualIndices);
return ClusterState.builder().state(currentState).metaData(metaDataBuilder).routingTable(routingTableBuilder).build();
} catch (Exception e) {

View File

@ -0,0 +1,77 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.integration.indices.settings;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
public class UpdateSettingsTests extends AbstractNodesTests {
@BeforeClass public void startNodes() {
startNode("node1");
}
@AfterClass public void closeNodes() {
closeAllNodes();
}
@Test public void testOpenCloseUpdateSettings() throws Exception {
try {
client("node1").admin().indices().prepareDelete("test").execute().actionGet();
} catch (Exception e) {
// ignore
}
client("node1").admin().indices().prepareCreate("test").execute().actionGet();
client("node1").admin().indices().prepareUpdateSettings("test")
.setSettings(ImmutableSettings.settingsBuilder()
.put("index.refresh_interval", -1) // this one can change
.put("index.cache.filter.type", "none") // this one can't
)
.execute().actionGet();
IndexMetaData indexMetaData = client("node1").admin().cluster().prepareState().execute().actionGet().getState().metaData().index("test");
assertThat(indexMetaData.settings().get("index.refresh_interval"), equalTo("-1"));
assertThat(indexMetaData.settings().get("index.cache.filter.type"), nullValue());
// now close the index, change the non dynamic setting, and see that it applies
client("node1").admin().indices().prepareClose("test").execute().actionGet();
client("node1").admin().indices().prepareUpdateSettings("test")
.setSettings(ImmutableSettings.settingsBuilder()
.put("index.refresh_interval", "1s") // this one can change
.put("index.cache.filter.type", "none") // this one can't
)
.execute().actionGet();
indexMetaData = client("node1").admin().cluster().prepareState().execute().actionGet().getState().metaData().index("test");
assertThat(indexMetaData.settings().get("index.refresh_interval"), equalTo("1s"));
assertThat(indexMetaData.settings().get("index.cache.filter.type"), equalTo("none"));
}
}