Make index.warmer.enabled setting dynamic

Even though proposed in the documentation, the realtime enabling/disabling of
index warmers was not supported. This commit adds support for
index.warmer.enabled as a dynamic setting.

Closes #3246
This commit is contained in:
Alexander Reelsen 2013-06-27 10:47:55 +02:00
parent 0114fb0f58
commit 71d5148b1c
3 changed files with 37 additions and 1 deletions

View File

@ -39,6 +39,7 @@ import org.elasticsearch.index.store.support.AbstractIndexStore;
import org.elasticsearch.index.translog.TranslogService;
import org.elasticsearch.index.translog.fs.FsTranslog;
import org.elasticsearch.indices.ttl.IndicesTTLService;
import org.elasticsearch.indices.warmer.InternalIndicesWarmer;
/**
*/
@ -113,6 +114,7 @@ public class IndexDynamicSettingsModule extends AbstractModule {
indexDynamicSettings.addDynamicSetting(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, Validator.BYTES_SIZE);
indexDynamicSettings.addDynamicSetting(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_PERIOD, Validator.TIME);
indexDynamicSettings.addDynamicSetting(TranslogService.INDEX_TRANSLOG_DISABLE_FLUSH);
indexDynamicSettings.addDynamicSetting(InternalIndicesWarmer.INDEX_WARMER_ENABLED);
}
public void addDynamicSettings(String... settings) {

View File

@ -38,6 +38,8 @@ import java.util.concurrent.TimeUnit;
*/
public class InternalIndicesWarmer extends AbstractComponent implements IndicesWarmer {
public static final String INDEX_WARMER_ENABLED = "index.warmer.enabled";
private final ThreadPool threadPool;
private final ClusterService clusterService;
@ -69,7 +71,7 @@ public class InternalIndicesWarmer extends AbstractComponent implements IndicesW
if (indexMetaData == null) {
return;
}
if (!indexMetaData.settings().getAsBoolean("index.warmer.enabled", settings.getAsBoolean("index.warmer.enabled", true))) {
if (!indexMetaData.settings().getAsBoolean(INDEX_WARMER_ENABLED, settings.getAsBoolean(INDEX_WARMER_ENABLED, true))) {
return;
}
IndexService indexService = indicesService.indexService(context.shardId().index().name());

View File

@ -19,6 +19,7 @@
package org.elasticsearch.test.integration.indices.wamer;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.Priority;
@ -32,6 +33,8 @@ import org.testng.annotations.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
/**
*/
@ -175,4 +178,33 @@ public class SimpleIndicesWarmerTests extends AbstractSharedClusterTest {
}
}
@Test // issue 3246
public void ensureThatIndexWarmersCanBeChangedOnRuntime() throws Exception {
client().admin().indices().prepareDelete().execute().actionGet();
client().admin().indices().prepareCreate("test")
.setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1))
.execute().actionGet();
client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
client().admin().indices().preparePutWarmer("custom_warmer")
.setSearchRequest(client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery()))
.execute().actionGet();
client().prepareIndex("test", "test", "1").setSource("{ \"foo\" : \"bar\"}").setRefresh(true).execute().actionGet();
client().admin().indices().prepareUpdateSettings("test").setSettings("{ \"index.warmer.enabled\": false}").execute().actionGet();
long warmerRunsAfterDisabling = getWarmerRuns();
assertThat(warmerRunsAfterDisabling, is(greaterThan(1L)));
client().prepareIndex("test", "test", "2").setSource("{ \"foo2\" : \"bar2\"}").setRefresh(true).execute().actionGet();
assertThat(warmerRunsAfterDisabling, is(getWarmerRuns()));
}
private long getWarmerRuns() {
IndicesStatsResponse indicesStatsResponse = client().admin().indices().prepareStats("test").clear().setWarmer(true).execute().actionGet();
return indicesStatsResponse.getIndex("test").getPrimaries().warmer.total();
}
}