Skip to content

Commit

Permalink
Treat empty prefrence as a not set in Plain Operation Routing
Browse files Browse the repository at this point in the history
An empty preference was causing a AIOOB exception in
PlainOperationRouting. We now check for `null` or `empty` instead of
just `null`

Closes #3591
  • Loading branch information
s1monw committed Aug 28, 2013
1 parent 1219113 commit 383b77e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Expand Up @@ -161,7 +161,7 @@ private Set<IndexShardRoutingTable> computeTargetedShards(ClusterState clusterSt
}

private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable indexShard, String localNodeId, DiscoveryNodes nodes, @Nullable String preference) {
if (preference == null) {
if (preference == null || preference.isEmpty()) {
String[] awarenessAttributes = awarenessAllocationDecider.awarenessAttributes();
if (awarenessAttributes.length == 0) {
return indexShard.activeInitializingShardsRandomIt();
Expand Down
Expand Up @@ -27,6 +27,8 @@
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.junit.Test;

import java.util.concurrent.ExecutionException;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
Expand All @@ -51,11 +53,28 @@ public void testSearchNullIndex() {

}
}

@Test
public void testSearchRandomPreference() throws InterruptedException, ExecutionException {
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", between(1,3))).get();
indexRandom("test", true,
client().prepareIndex("test", "type", "1").setSource("field", "value"),
client().prepareIndex("test", "type", "2").setSource("field", "value"),
client().prepareIndex("test", "type", "3").setSource("field", "value"),
client().prepareIndex("test", "type", "4").setSource("field", "value"),
client().prepareIndex("test", "type", "5").setSource("field", "value"),
client().prepareIndex("test", "type", "6").setSource("field", "value"));

int iters = atLeast(10);
for (int i = 0; i < iters; i++) {
// id is not indexed, but lets see that we automatically convert to
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).setPreference(randomUnicodeOfLengthBetween(0, 4)).get();
assertThat(searchResponse.getHits().totalHits(), equalTo(6l));
}
}

@Test
public void simpleIpTests() throws Exception {
client().admin().indices().prepareDelete().execute().actionGet();

client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();

client().admin().indices().preparePutMapping("test").setType("type1")
Expand All @@ -76,7 +95,6 @@ public void simpleIpTests() throws Exception {

@Test
public void simpleIdTests() {
client().admin().indices().prepareDelete().execute().actionGet();
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();

client().prepareIndex("test", "type", "XXX1").setSource("field", "value").setRefresh(true).execute().actionGet();
Expand Down

0 comments on commit 383b77e

Please sign in to comment.