Deleting a non-existent warmer shouldn't cause request to hang

Fixes #2363
This commit is contained in:
Igor Motov 2012-10-29 11:35:07 -04:00 committed by Shay Banon
parent 7aa3f51b6e
commit 23f7b0002a
2 changed files with 63 additions and 40 deletions

View File

@ -94,43 +94,10 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeOperationAct
clusterService.submitStateUpdateTask("delete_warmer [" + request.name() + "]", new ProcessedClusterStateUpdateTask() {
@Override
public ClusterState execute(ClusterState currentState) {
MetaData.Builder mdBuilder = MetaData.builder().metaData(currentState.metaData());
try {
MetaData.Builder mdBuilder = MetaData.builder().metaData(currentState.metaData());
boolean globalFoundAtLeastOne = false;
for (String index : request.indices()) {
IndexMetaData indexMetaData = currentState.metaData().index(index);
if (indexMetaData == null) {
throw new IndexMissingException(new Index(index));
}
IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE);
if (warmers != null) {
List<IndexWarmersMetaData.Entry> entries = Lists.newArrayList();
for (IndexWarmersMetaData.Entry entry : warmers.entries()) {
if (request.name() == null || Regex.simpleMatch(request.name(), entry.name())) {
globalFoundAtLeastOne = true;
// don't add it...
} else {
entries.add(entry);
}
}
// a change, update it...
if (entries.size() != warmers.entries().size()) {
warmers = new IndexWarmersMetaData(entries.toArray(new IndexWarmersMetaData.Entry[entries.size()]));
IndexMetaData.Builder indexBuilder = IndexMetaData.newIndexMetaDataBuilder(indexMetaData).putCustom(IndexWarmersMetaData.TYPE, warmers);
mdBuilder.put(indexBuilder);
}
}
}
if (!globalFoundAtLeastOne) {
if (request.name() == null) {
// full match, just return with no failure
return currentState;
}
throw new IndexWarmerMissingException(request.name());
}
if (logger.isInfoEnabled()) {
boolean globalFoundAtLeastOne = false;
for (String index : request.indices()) {
IndexMetaData indexMetaData = currentState.metaData().index(index);
if (indexMetaData == null) {
@ -138,16 +105,55 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeOperationAct
}
IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE);
if (warmers != null) {
List<IndexWarmersMetaData.Entry> entries = Lists.newArrayList();
for (IndexWarmersMetaData.Entry entry : warmers.entries()) {
if (Regex.simpleMatch(request.name(), entry.name())) {
logger.info("[{}] delete warmer [{}]", index, entry.name());
if (request.name() == null || Regex.simpleMatch(request.name(), entry.name())) {
globalFoundAtLeastOne = true;
// don't add it...
} else {
entries.add(entry);
}
}
// a change, update it...
if (entries.size() != warmers.entries().size()) {
warmers = new IndexWarmersMetaData(entries.toArray(new IndexWarmersMetaData.Entry[entries.size()]));
IndexMetaData.Builder indexBuilder = IndexMetaData.newIndexMetaDataBuilder(indexMetaData).putCustom(IndexWarmersMetaData.TYPE, warmers);
mdBuilder.put(indexBuilder);
}
}
}
if (!globalFoundAtLeastOne) {
if (request.name() == null) {
// full match, just return with no failure
return currentState;
}
throw new IndexWarmerMissingException(request.name());
}
if (logger.isInfoEnabled()) {
for (String index : request.indices()) {
IndexMetaData indexMetaData = currentState.metaData().index(index);
if (indexMetaData == null) {
throw new IndexMissingException(new Index(index));
}
IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE);
if (warmers != null) {
for (IndexWarmersMetaData.Entry entry : warmers.entries()) {
if (Regex.simpleMatch(request.name(), entry.name())) {
logger.info("[{}] delete warmer [{}]", index, entry.name());
}
}
}
}
}
}
return ClusterState.builder().state(currentState).metaData(mdBuilder).build();
return ClusterState.builder().state(currentState).metaData(mdBuilder).build();
} catch (Exception ex) {
failureRef.set(ex);
latch.countDown();
return currentState;
}
}
@Override

View File

@ -23,6 +23,7 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.warmer.IndexWarmerMissingException;
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.hamcrest.Matchers;
@ -142,4 +143,20 @@ public class SimpleIndicesWarmerTests extends AbstractNodesTests {
client.prepareIndex("test", "type1", "1").setSource("field", "value1").setRefresh(true).execute().actionGet();
client.prepareIndex("test", "type1", "2").setSource("field", "value2").setRefresh(true).execute().actionGet();
}
@Test
public void deleteNonExistentIndexWarmerTest() {
client.admin().indices().prepareDelete().execute().actionGet();
client.admin().indices().prepareCreate("test").execute().actionGet();
try {
client.admin().indices().prepareDeleteWarmer().setIndices("test").setName("foo").execute().actionGet(1000);
assert false : "warmer foo should not exist";
}
catch(IndexWarmerMissingException ex) {
assertThat(ex.name(), equalTo("foo"));
}
}
}