simplify searchShard selection when routing is present
This commit is contained in:
parent
09f20e3d4c
commit
e9ba98913b
|
@ -42,6 +42,7 @@ import org.elasticsearch.index.shard.ShardId;
|
||||||
import org.elasticsearch.indices.IndexMissingException;
|
import org.elasticsearch.indices.IndexMissingException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -144,18 +145,19 @@ public class PlainOperationRouting extends AbstractComponent implements Operatio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Map<String, Set<String>> EMPTY_ROUTING = Collections.emptyMap();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupShardsIterator searchShards(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException {
|
public GroupShardsIterator searchShards(ClusterState clusterState, String[] indices, String[] concreteIndices, @Nullable Map<String, Set<String>> routing, @Nullable String preference) throws IndexMissingException {
|
||||||
if (concreteIndices == null || concreteIndices.length == 0) {
|
if (concreteIndices == null || concreteIndices.length == 0) {
|
||||||
concreteIndices = clusterState.metaData().concreteAllOpenIndices();
|
concreteIndices = clusterState.metaData().concreteAllOpenIndices();
|
||||||
}
|
}
|
||||||
|
routing = routing == null ? EMPTY_ROUTING : routing; // just use an empty map
|
||||||
if (routing != null) {
|
final Set<ShardIterator> set = new HashSet<ShardIterator>();
|
||||||
// we use set here and not list since we might get duplicates
|
// we use set here and not list since we might get duplicates
|
||||||
HashSet<ShardIterator> set = new HashSet<ShardIterator>();
|
|
||||||
for (String index : concreteIndices) {
|
for (String index : concreteIndices) {
|
||||||
IndexRoutingTable indexRouting = indexRoutingTable(clusterState, index);
|
final IndexRoutingTable indexRouting = indexRoutingTable(clusterState, index);
|
||||||
Set<String> effectiveRouting = routing.get(index);
|
final Set<String> effectiveRouting = routing.get(index);
|
||||||
if (effectiveRouting != null) {
|
if (effectiveRouting != null) {
|
||||||
for (String r : effectiveRouting) {
|
for (String r : effectiveRouting) {
|
||||||
int shardId = shardId(clusterState, index, null, null, r);
|
int shardId = shardId(clusterState, index, null, null, r);
|
||||||
|
@ -178,21 +180,7 @@ public class PlainOperationRouting extends AbstractComponent implements Operatio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new GroupShardsIterator(set);
|
return new GroupShardsIterator(set);
|
||||||
} else {
|
|
||||||
// we use list here since we know we are not going to create duplicates
|
|
||||||
ArrayList<ShardIterator> set = new ArrayList<ShardIterator>();
|
|
||||||
for (String index : concreteIndices) {
|
|
||||||
IndexRoutingTable indexRouting = indexRoutingTable(clusterState, index);
|
|
||||||
for (IndexShardRoutingTable indexShard : indexRouting) {
|
|
||||||
ShardIterator iterator = preferenceActiveShardIterator(indexShard, clusterState.nodes().localNodeId(), clusterState.nodes(), preference);
|
|
||||||
if (iterator != null) {
|
|
||||||
set.add(iterator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new GroupShardsIterator(set);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable indexShard, String localNodeId, DiscoveryNodes nodes, @Nullable String preference) {
|
private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable indexShard, String localNodeId, DiscoveryNodes nodes, @Nullable String preference) {
|
||||||
|
|
Loading…
Reference in New Issue