Permalink
Browse files

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

  • Loading branch information...
1 parent bd87f8d commit bb9d8fe3424ec2f29a69cce45fcce7fff55c5f75 @kimchy kimchy committed Oct 12, 2011
@@ -239,6 +239,18 @@ public ShardIterator preferNodeShardsIt(String nodeId) {
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.
*/
@@ -172,7 +172,7 @@
}
}
- 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 @@ private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable index
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();

0 comments on commit bb9d8fe

Please sign in to comment.