when providing explicit routing in index/delete operation, and working against an alias with routing, fail the index operation

This commit is contained in:
kimchy 2011-06-13 00:41:32 +03:00
parent 00e010a52a
commit 7c67f11e7c
2 changed files with 12 additions and 9 deletions

View File

@ -50,7 +50,7 @@ import java.util.regex.Pattern;
import static org.elasticsearch.common.collect.Lists.*;
import static org.elasticsearch.common.collect.MapBuilder.*;
import static org.elasticsearch.common.collect.Maps.newHashMap;
import static org.elasticsearch.common.collect.Maps.*;
import static org.elasticsearch.common.collect.Sets.*;
import static org.elasticsearch.common.settings.ImmutableSettings.*;
@ -231,7 +231,7 @@ public class MetaData implements Iterable<IndexMetaData> {
return routing;
}
if (indexAliases.size() > 1) {
throw new ElasticSearchIllegalArgumentException("Alias [" + aliasOrIndex + "] has more than one indices associated with it [" + indexAliases.keySet() + "], can't execute a single index op");
throw new ElasticSearchIllegalArgumentException("Alias [" + aliasOrIndex + "] has more than one index associated with it [" + indexAliases.keySet() + "], can't execute a single index op");
}
AliasMetaData aliasMd = indexAliases.values().iterator().next();
if (aliasMd.indexRouting() != null) {
@ -239,7 +239,7 @@ public class MetaData implements Iterable<IndexMetaData> {
if (routing.equals(aliasMd.indexRouting())) {
return routing;
} else {
return null;
throw new ElasticSearchIllegalArgumentException("Alias [" + aliasOrIndex + "] has index routing associated with it [" + aliasMd.indexRouting() + "], and was provided with routing value [" + routing + "], rejecting operation");
}
}
return aliasMd.indexRouting();

View File

@ -30,12 +30,11 @@ import org.testng.annotations.Test;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import static org.elasticsearch.cluster.metadata.AliasAction.newAddAliasAction;
import static org.elasticsearch.common.collect.Maps.newHashMap;
import static org.elasticsearch.common.collect.Sets.newHashSet;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.elasticsearch.cluster.metadata.AliasAction.*;
import static org.elasticsearch.common.collect.Maps.*;
import static org.elasticsearch.common.collect.Sets.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**
@ -92,7 +91,11 @@ public class AliasResolveRoutingTests extends AbstractNodesTests {
assertThat(clusterService.state().metaData().resolveIndexRouting(null, "alias21"), equalTo("1"));
assertThat(clusterService.state().metaData().resolveIndexRouting("3", "test1"), equalTo("3"));
assertThat(clusterService.state().metaData().resolveIndexRouting("0", "alias10"), equalTo("0"));
assertThat(clusterService.state().metaData().resolveIndexRouting("1", "alias10"), nullValue());
try {
clusterService.state().metaData().resolveIndexRouting("1", "alias10");
} catch (ElasticSearchIllegalArgumentException e) {
// all is well, we can't have two mappings, one provided, and one in the alias
}
try {
clusterService.state().metaData().resolveIndexRouting(null, "alias0");