when providing explicit routing in index/delete operation, and working against an alias with routing, fail the index operation
This commit is contained in:
parent
00e010a52a
commit
7c67f11e7c
|
@ -50,7 +50,7 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static org.elasticsearch.common.collect.Lists.*;
|
import static org.elasticsearch.common.collect.Lists.*;
|
||||||
import static org.elasticsearch.common.collect.MapBuilder.*;
|
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.collect.Sets.*;
|
||||||
import static org.elasticsearch.common.settings.ImmutableSettings.*;
|
import static org.elasticsearch.common.settings.ImmutableSettings.*;
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
return routing;
|
return routing;
|
||||||
}
|
}
|
||||||
if (indexAliases.size() > 1) {
|
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();
|
AliasMetaData aliasMd = indexAliases.values().iterator().next();
|
||||||
if (aliasMd.indexRouting() != null) {
|
if (aliasMd.indexRouting() != null) {
|
||||||
|
@ -239,7 +239,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
||||||
if (routing.equals(aliasMd.indexRouting())) {
|
if (routing.equals(aliasMd.indexRouting())) {
|
||||||
return routing;
|
return routing;
|
||||||
} else {
|
} 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();
|
return aliasMd.indexRouting();
|
||||||
|
|
|
@ -30,12 +30,11 @@ import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
|
|
||||||
import static org.elasticsearch.cluster.metadata.AliasAction.newAddAliasAction;
|
import static org.elasticsearch.cluster.metadata.AliasAction.*;
|
||||||
import static org.elasticsearch.common.collect.Maps.newHashMap;
|
import static org.elasticsearch.common.collect.Maps.*;
|
||||||
import static org.elasticsearch.common.collect.Sets.newHashSet;
|
import static org.elasticsearch.common.collect.Sets.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
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(null, "alias21"), equalTo("1"));
|
||||||
assertThat(clusterService.state().metaData().resolveIndexRouting("3", "test1"), equalTo("3"));
|
assertThat(clusterService.state().metaData().resolveIndexRouting("3", "test1"), equalTo("3"));
|
||||||
assertThat(clusterService.state().metaData().resolveIndexRouting("0", "alias10"), equalTo("0"));
|
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 {
|
try {
|
||||||
clusterService.state().metaData().resolveIndexRouting(null, "alias0");
|
clusterService.state().metaData().resolveIndexRouting(null, "alias0");
|
||||||
|
|
Loading…
Reference in New Issue