verify that index routing is not, by mistake, composed of several routing values

This commit is contained in:
kimchy 2011-06-13 01:00:34 +03:00
parent 7c67f11e7c
commit fbdf11d3f1
2 changed files with 15 additions and 6 deletions

View File

@ -236,16 +236,18 @@ public class MetaData implements Iterable<IndexMetaData> {
AliasMetaData aliasMd = indexAliases.values().iterator().next();
if (aliasMd.indexRouting() != null) {
if (routing != null) {
if (routing.equals(aliasMd.indexRouting())) {
return routing;
} else {
if (!routing.equals(aliasMd.indexRouting())) {
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();
} else {
return routing;
routing = aliasMd.indexRouting();
}
if (routing != null) {
if (routing.indexOf(',') != -1) {
throw new ElasticSearchIllegalArgumentException("index/alias [" + aliasOrIndex + "] provided with routing value [" + routing + "] that resolved to several routing values, rejecting operation");
}
}
return routing;
}
/**

View File

@ -93,6 +93,13 @@ public class AliasResolveRoutingTests extends AbstractNodesTests {
assertThat(clusterService.state().metaData().resolveIndexRouting("0", "alias10"), equalTo("0"));
try {
clusterService.state().metaData().resolveIndexRouting("1", "alias10");
assert false : "should fail";
} 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, "alias110");
assert false : "should fail";
} catch (ElasticSearchIllegalArgumentException e) {
// all is well, we can't have two mappings, one provided, and one in the alias
}