Skip to content

Commit

Permalink
Make index.warmer.enabled setting dynamic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
spinscale committed Jun 28, 2013
1 parent 0114fb0 commit 71d5148
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Expand Up @@ -39,6 +39,7 @@
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;

/**
*/
Expand Down Expand Up @@ -113,6 +114,7 @@ public IndexDynamicSettingsModule() {
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) {
Expand Down
Expand Up @@ -38,6 +38,8 @@
*/
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;
Expand Down Expand Up @@ -69,7 +71,7 @@ public void warm(final WarmerContext context) {
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());
Expand Down
Expand Up @@ -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;
Expand All @@ -32,6 +33,8 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;

/**
*/
Expand Down Expand Up @@ -175,4 +178,33 @@ public void deleteNonExistentIndexWarmerTest() {
}
}

@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();
}
}

0 comments on commit 71d5148

Please sign in to comment.