optimize reroute
- optimize initialization of building the all the assigned shards state - optimize iteration in throttling allocation decider
This commit is contained in:
parent
cc1173b58f
commit
759a13f1de
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.cluster.routing;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import gnu.trove.map.hash.TObjectIntHashMap;
|
||||
|
@ -247,6 +248,20 @@ public class RoutingNodes implements Iterable<RoutingNode> {
|
|||
return count;
|
||||
}
|
||||
|
||||
public List<MutableShardRouting> shards(Predicate<MutableShardRouting> predicate) {
|
||||
List<MutableShardRouting> shards = newArrayList();
|
||||
for (RoutingNode routingNode : this) {
|
||||
List<MutableShardRouting> nodeShards = routingNode.shards();
|
||||
for (int i = 0; i < nodeShards.size(); i++) {
|
||||
MutableShardRouting shardRouting = nodeShards.get(i);
|
||||
if (predicate.apply(shardRouting)) {
|
||||
shards.add(shardRouting);
|
||||
}
|
||||
}
|
||||
}
|
||||
return shards;
|
||||
}
|
||||
|
||||
public List<MutableShardRouting> shardsWithState(ShardRoutingState... state) {
|
||||
List<MutableShardRouting> shards = newArrayList();
|
||||
for (RoutingNode routingNode : this) {
|
||||
|
|
|
@ -20,11 +20,13 @@
|
|||
package org.elasticsearch.cluster.routing.allocation.allocator;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.apache.lucene.util.SorterTemplate;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.routing.*;
|
||||
import org.elasticsearch.cluster.routing.MutableShardRouting;
|
||||
import org.elasticsearch.cluster.routing.RoutingNode;
|
||||
import org.elasticsearch.cluster.routing.RoutingNodes;
|
||||
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
||||
import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.routing.allocation.StartedRerouteAllocation;
|
||||
|
@ -194,15 +196,15 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
|
|||
if (sum <= 0.0f) {
|
||||
throw new ElasticSearchIllegalArgumentException("Balance factors must sum to a value > 0 but was: " + sum);
|
||||
}
|
||||
final float[] defaultTheta = new float[] { shardBalance / sum, indexBalance / sum, primaryBalance / sum };
|
||||
for(Operation operation : Operation.values()) {
|
||||
switch(operation) {
|
||||
final float[] defaultTheta = new float[]{shardBalance / sum, indexBalance / sum, primaryBalance / sum};
|
||||
for (Operation operation : Operation.values()) {
|
||||
switch (operation) {
|
||||
case THRESHOLD_CHECK:
|
||||
sum = indexBalance + shardBalance;
|
||||
if (sum <= 0.0f) {
|
||||
thetaMap.put(operation, defaultTheta);
|
||||
}
|
||||
thetaMap.put(operation, new float[] { shardBalance / sum, indexBalance / sum, 0});
|
||||
thetaMap.put(operation, new float[]{shardBalance / sum, indexBalance / sum, 0});
|
||||
break;
|
||||
case BALANCE:
|
||||
case ALLOCATE:
|
||||
|
@ -325,27 +327,20 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
|
|||
/**
|
||||
* Returns a new {@link NodeSorter} that sorts the nodes based on their
|
||||
* current weight with respect to the index passed to the sorter. The
|
||||
* returned sorter is not sorted. Use {@link NodeSorter#reset(String)}
|
||||
* returned sorter is not sorted. Use {@link NodeSorter#reset(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.Operation, String)}
|
||||
* to sort based on an index.
|
||||
*/
|
||||
private NodeSorter newNodeSorter() {
|
||||
final NodeSorter sorter = new NodeSorter(nodesArray(), weight, this);
|
||||
return sorter;
|
||||
return new NodeSorter(nodesArray(), weight, this);
|
||||
}
|
||||
|
||||
private boolean initialize(RoutingNodes routing) {
|
||||
Collection<MutableShardRouting> shards = new ArrayList<MutableShardRouting>();
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Start distributing Shards");
|
||||
}
|
||||
|
||||
for (IndexRoutingTable index : allocation.routingTable().indicesRouting().values()) {
|
||||
indices.add(index.index());
|
||||
for (IndexShardRoutingTable shard : index.getShards().values()) {
|
||||
shards.addAll(routing.shardsRoutingFor(index.index(), shard.shardId().id()));
|
||||
}
|
||||
}
|
||||
buildModelFromAssigned(Iterables.filter(shards, assignedFilter));
|
||||
indices.addAll(allocation.routingTable().indicesRouting().keySet());
|
||||
buildModelFromAssigned(routing.shards(assignedFilter));
|
||||
return allocateUnassigned(allocation.routingNodes().unassigned(), allocation.routingNodes().ignoredUnassigned());
|
||||
}
|
||||
|
||||
|
@ -376,7 +371,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
|
|||
NodeSorter sorter = newNodeSorter();
|
||||
if (nodes.size() > 1) { /* skip if we only have one node */
|
||||
for (String index : buildWeightOrderedIndidces(Operation.BALANCE, sorter)) {
|
||||
sorter.reset(Operation.BALANCE,index);
|
||||
sorter.reset(Operation.BALANCE, index);
|
||||
final float[] weights = sorter.weights;
|
||||
final ModelNode[] modelNodes = sorter.modelNodes;
|
||||
int lowIdx = 0;
|
||||
|
|
|
@ -75,9 +75,12 @@ public class ThrottlingAllocationDecider extends AllocationDecider {
|
|||
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
|
||||
if (shardRouting.primary()) {
|
||||
boolean primaryUnassigned = false;
|
||||
for (MutableShardRouting shard : allocation.routingNodes().unassigned()) {
|
||||
List<MutableShardRouting> unassigned = allocation.routingNodes().unassigned();
|
||||
for (int i1 = 0; i1 < unassigned.size(); i1++) {
|
||||
MutableShardRouting shard = unassigned.get(i1);
|
||||
if (shard.shardId().equals(shardRouting.shardId())) {
|
||||
primaryUnassigned = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (primaryUnassigned) {
|
||||
|
|
Loading…
Reference in New Issue