Updating `index.auto_expand_replicas` might not be applied correctly, closes #1237.
This commit is contained in:
parent
001a6b0ff7
commit
fa19239d44
|
@ -61,13 +61,11 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
|
|||
if (!event.state().nodes().localNodeMaster()) {
|
||||
return;
|
||||
}
|
||||
// TODO we only need to do that on first create of an index, or the number of nodes changed
|
||||
// we need to do this each time in case it was changed by update settings
|
||||
for (final IndexMetaData indexMetaData : event.state().metaData()) {
|
||||
String autoExpandReplicas = indexMetaData.settings().get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS);
|
||||
if (autoExpandReplicas != null && Booleans.parseBoolean(autoExpandReplicas, true)) { // Booleans only work for false values, just as we want it here
|
||||
try {
|
||||
final int numberOfReplicas = event.state().nodes().dataNodes().size() - 1;
|
||||
|
||||
int min;
|
||||
int max;
|
||||
try {
|
||||
|
@ -83,20 +81,28 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
|
|||
continue;
|
||||
}
|
||||
|
||||
int numberOfReplicas = event.state().nodes().dataNodes().size() - 1;
|
||||
if (numberOfReplicas < min) {
|
||||
numberOfReplicas = min;
|
||||
} else if (numberOfReplicas > max) {
|
||||
numberOfReplicas = max;
|
||||
}
|
||||
|
||||
// same value, nothing to do there
|
||||
if (numberOfReplicas == indexMetaData.numberOfReplicas()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (numberOfReplicas >= min && numberOfReplicas <= max) {
|
||||
Settings settings = ImmutableSettings.settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, numberOfReplicas).build();
|
||||
final int fNumberOfReplicas = numberOfReplicas;
|
||||
Settings settings = ImmutableSettings.settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, fNumberOfReplicas).build();
|
||||
updateSettings(settings, new String[]{indexMetaData.index()}, new Listener() {
|
||||
@Override public void onSuccess() {
|
||||
logger.info("[{}] auto expanded replicas to [{}]", indexMetaData.index(), numberOfReplicas);
|
||||
logger.info("[{}] auto expanded replicas to [{}]", indexMetaData.index(), fNumberOfReplicas);
|
||||
}
|
||||
|
||||
@Override public void onFailure(Throwable t) {
|
||||
logger.warn("[{}] fail to auto expand replicas to [{}]", indexMetaData.index(), numberOfReplicas);
|
||||
logger.warn("[{}] fail to auto expand replicas to [{}]", indexMetaData.index(), fNumberOfReplicas);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -241,4 +241,36 @@ public class UpdateNumberOfReplicasTests extends AbstractNodesTests {
|
|||
assertThat(clusterHealth.indices().get("test").numberOfReplicas(), equalTo(1));
|
||||
assertThat(clusterHealth.indices().get("test").activeShards(), equalTo(2));
|
||||
}
|
||||
|
||||
@Test public void testAutoExpandNumberReplicas2() {
|
||||
logger.info("--> add another node");
|
||||
startNode("node3");
|
||||
logger.info("--> creating index test with auto expand replicas set to 0-2");
|
||||
client1.admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("number_of_shards", 2).put("auto_expand_replicas", "0-2")).execute().actionGet();
|
||||
|
||||
logger.info("--> running cluster health");
|
||||
ClusterHealthResponse clusterHealth = client1.admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForActiveShards(6).execute().actionGet();
|
||||
logger.info("--> done cluster health, status " + clusterHealth.status());
|
||||
assertThat(clusterHealth.timedOut(), equalTo(false));
|
||||
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
|
||||
assertThat(clusterHealth.indices().get("test").activePrimaryShards(), equalTo(2));
|
||||
assertThat(clusterHealth.indices().get("test").numberOfReplicas(), equalTo(2));
|
||||
assertThat(clusterHealth.indices().get("test").activeShards(), equalTo(6));
|
||||
|
||||
logger.info("--> add two more nodes");
|
||||
startNode("node4");
|
||||
startNode("node5");
|
||||
|
||||
logger.info("--> update the auto expand replicas to 0-3");
|
||||
client1.admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put("auto_expand_replicas", "0-3")).execute().actionGet();
|
||||
|
||||
logger.info("--> running cluster health");
|
||||
clusterHealth = client1.admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForActiveShards(8).execute().actionGet();
|
||||
logger.info("--> done cluster health, status " + clusterHealth.status());
|
||||
assertThat(clusterHealth.timedOut(), equalTo(false));
|
||||
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
|
||||
assertThat(clusterHealth.indices().get("test").activePrimaryShards(), equalTo(2));
|
||||
assertThat(clusterHealth.indices().get("test").numberOfReplicas(), equalTo(3));
|
||||
assertThat(clusterHealth.indices().get("test").activeShards(), equalTo(8));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue