improve prefer local execution
This commit is contained in:
parent
180f83828a
commit
5e78f14f04
|
@ -165,15 +165,12 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
int index = Math.abs(counter.getAndIncrement());
|
int index = Math.abs(counter.getAndIncrement());
|
||||||
for (int i = 0; i < this.shards.size(); i++) {
|
for (int i = 0; i < this.shards.size(); i++) {
|
||||||
int loc = (index + i) % this.shards.size();
|
int loc = (index + i) % this.shards.size();
|
||||||
ordered.add(this.shards.get(loc));
|
ShardRouting shardRouting = this.shards.get(loc);
|
||||||
}
|
ordered.add(shardRouting);
|
||||||
// find the local one, and push it upfront
|
if (nodeId.equals(shardRouting.currentNodeId())) {
|
||||||
for (int i = 0; i < ordered.size(); i++) {
|
// switch, its the matching node id
|
||||||
ShardRouting current = ordered.get(i);
|
|
||||||
if (nodeId.equals(current.currentNodeId())) {
|
|
||||||
ordered.set(i, ordered.get(0));
|
ordered.set(i, ordered.get(0));
|
||||||
ordered.set(0, current);
|
ordered.set(0, shardRouting);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new PlainShardIterator(shardId, ordered);
|
return new PlainShardIterator(shardId, ordered);
|
||||||
|
|
|
@ -82,11 +82,17 @@ public class SearchPreferenceTests extends AbstractNodesTests {
|
||||||
|
|
||||||
SearchResponse searchResponse = client.prepareSearch().setQuery(matchAllQuery()).setPreference("_local").execute().actionGet();
|
SearchResponse searchResponse = client.prepareSearch().setQuery(matchAllQuery()).setPreference("_local").execute().actionGet();
|
||||||
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
||||||
|
searchResponse = client.prepareSearch().setQuery(matchAllQuery()).setPreference("_local").execute().actionGet();
|
||||||
|
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
||||||
|
|
||||||
|
searchResponse = client.prepareSearch().setQuery(matchAllQuery()).setPreference("_primary").execute().actionGet();
|
||||||
|
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
||||||
searchResponse = client.prepareSearch().setQuery(matchAllQuery()).setPreference("_primary").execute().actionGet();
|
searchResponse = client.prepareSearch().setQuery(matchAllQuery()).setPreference("_primary").execute().actionGet();
|
||||||
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
||||||
|
|
||||||
searchResponse = client.prepareSearch().setQuery(matchAllQuery()).setPreference("1234").execute().actionGet();
|
searchResponse = client.prepareSearch().setQuery(matchAllQuery()).setPreference("1234").execute().actionGet();
|
||||||
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
||||||
|
searchResponse = client.prepareSearch().setQuery(matchAllQuery()).setPreference("1234").execute().actionGet();
|
||||||
|
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue