From adbe0565f104ee4b128acb849fedce67a8f7dcff Mon Sep 17 00:00:00 2001 From: kimchy Date: Mon, 13 Jun 2011 01:21:03 +0300 Subject: [PATCH] validate when setting aliases that index routing does not resolve into several routing values --- .../cluster/metadata/MetaDataIndexAliasesService.java | 4 ++++ .../integration/routing/AliasResolveRoutingTests.java | 8 +------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java index 981ac6bc08b..a6725b04cc2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java @@ -73,6 +73,10 @@ public class MetaDataIndexAliasesService extends AbstractComponent { listener.onFailure(new InvalidAliasNameException(new Index(aliasAction.index()), aliasAction.alias(), "an index exists with the same name as the alias")); return currentState; } + if (aliasAction.indexRouting() != null && aliasAction.indexRouting().indexOf(',') != -1) { + listener.onFailure(new ElasticSearchIllegalArgumentException("alias [" + aliasAction.alias() + "] has several routing values associated with it")); + return currentState; + } } List indicesToClose = Lists.newArrayList(); diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/routing/AliasResolveRoutingTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/routing/AliasResolveRoutingTests.java index acfe4da181f..e4783986bc0 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/routing/AliasResolveRoutingTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/routing/AliasResolveRoutingTests.java @@ -74,7 +74,7 @@ public class AliasResolveRoutingTests extends AbstractNodesTests { client.admin().indices().prepareAliases().addAliasAction(newAddAliasAction("test1", "alias")).execute().actionGet(); client.admin().indices().prepareAliases().addAliasAction(newAddAliasAction("test1", "alias10").routing("0")).execute().actionGet(); - client.admin().indices().prepareAliases().addAliasAction(newAddAliasAction("test1", "alias110").routing("1,0")).execute().actionGet(); + client.admin().indices().prepareAliases().addAliasAction(newAddAliasAction("test1", "alias110").searchRouting("1,0")).execute().actionGet(); client.admin().indices().prepareAliases().addAliasAction(newAddAliasAction("test1", "alias12").routing("2")).execute().actionGet(); client.admin().indices().prepareAliases().addAliasAction(newAddAliasAction("test2", "alias20").routing("0")).execute().actionGet(); client.admin().indices().prepareAliases().addAliasAction(newAddAliasAction("test2", "alias21").routing("1")).execute().actionGet(); @@ -97,12 +97,6 @@ public class AliasResolveRoutingTests extends AbstractNodesTests { } 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 - } try { clusterService.state().metaData().resolveIndexRouting(null, "alias0");