Search / Get Preference: Add _only_node:[node_id] option, closes #1388.

This commit is contained in:
Shay Banon 2011-10-12 21:11:12 +02:00
parent bd87f8de3a
commit bb9d8fe342
2 changed files with 26 additions and 6 deletions

View File

@ -239,6 +239,18 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
return preferNodeShardsIt(nodeId, shards);
}
public ShardIterator onlyNodeActiveShardsIt(String nodeId) {
ArrayList<ShardRouting> ordered = new ArrayList<ShardRouting>(shards.size());
// fill it in a randomized fashion
for (int i = 0; i < shards.size(); i++) {
ShardRouting shardRouting = shards.get(i);
if (nodeId.equals(shardRouting.currentNodeId())) {
ordered.add(shardRouting);
}
}
return new PlainShardIterator(shardId, ordered);
}
/**
* Prefers execution on the provided node if applicable.
*/

View File

@ -172,7 +172,7 @@ public class PlainOperationRouting extends AbstractComponent implements Operatio
}
}
private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable indexShard, String nodeId, DiscoveryNodes nodes, @Nullable String preference) {
private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable indexShard, String localNodeId, DiscoveryNodes nodes, @Nullable String preference) {
if (preference == null) {
String[] awarenessAttributes = awarenessAllocationDecider.awarenessAttributes();
if (awarenessAttributes.length == 0) {
@ -181,11 +181,19 @@ public class PlainOperationRouting extends AbstractComponent implements Operatio
return indexShard.preferAttributesActiveShardsIt(awarenessAttributes, nodes);
}
}
if ("_local".equals(preference)) {
return indexShard.preferNodeActiveShardsIt(nodeId);
}
if ("_primary".equals(preference)) {
return indexShard.primaryShardIt();
if (preference.charAt(0) == '_') {
if ("_local".equals(preference)) {
return indexShard.preferNodeActiveShardsIt(localNodeId);
}
if ("_primary".equals(preference)) {
return indexShard.primaryShardIt();
}
if ("_only_local".equals(preference) || "_onlyLocal".equals(preference)) {
return indexShard.onlyNodeActiveShardsIt(localNodeId);
}
if (preference.startsWith("_only_node:")) {
return indexShard.onlyNodeActiveShardsIt(preference.substring("_only_node:".length()));
}
}
// if not, then use it as the index
String[] awarenessAttributes = awarenessAllocationDecider.awarenessAttributes();