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;
|
||||
|
@ -68,7 +70,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
|
|||
public static final String SETTING_PRIMARY_BALANCE_FACTOR = "cluster.routing.allocation.balance.primary";
|
||||
|
||||
private static final float DEFAULT_INDEX_BALANCE_FACTOR = 0.5f;
|
||||
private static final float DEFAULT_SHARD_BALANCE_FACTOR = 0.45f;
|
||||
private static final float DEFAULT_SHARD_BALANCE_FACTOR = 0.45f;
|
||||
private static final float DEFAULT_PRIMARY_BALANCE_FACTOR = 0.05f;
|
||||
|
||||
class ApplySettings implements NodeSettingsService.Listener {
|
||||
|
@ -194,23 +196,23 @@ 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) {
|
||||
case THRESHOLD_CHECK:
|
||||
sum = indexBalance + shardBalance;
|
||||
if (sum <= 0.0f) {
|
||||
thetaMap.put(operation, defaultTheta);
|
||||
}
|
||||
thetaMap.put(operation, new float[] { shardBalance / sum, indexBalance / sum, 0});
|
||||
break;
|
||||
case BALANCE:
|
||||
case ALLOCATE:
|
||||
case MOVE:
|
||||
thetaMap.put(operation, defaultTheta);
|
||||
break;
|
||||
default:
|
||||
assert false;
|
||||
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});
|
||||
break;
|
||||
case BALANCE:
|
||||
case ALLOCATE:
|
||||
case MOVE:
|
||||
thetaMap.put(operation, defaultTheta);
|
||||
break;
|
||||
default:
|
||||
assert false;
|
||||
}
|
||||
}
|
||||
this.indexBalance = indexBalance;
|
||||
|
@ -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;
|
||||
|
@ -622,15 +617,15 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
|
|||
ModelNode minNode = null;
|
||||
Decision decision = null;
|
||||
for (ModelNode node : nodes.values()) {
|
||||
/*
|
||||
* The shard we add is removed below to simulate the
|
||||
/*
|
||||
* The shard we add is removed below to simulate the
|
||||
* addition for weight calculation we use Decision.ALWAYS to
|
||||
* not violate the not null condition.
|
||||
*/
|
||||
if (!node.containsShard(shard)) {
|
||||
node.addShard(shard, Decision.ALWAYS);
|
||||
float currentWeight = weight.weight(Operation.ALLOCATE, this, node, shard.index());
|
||||
/*
|
||||
/*
|
||||
* Remove the shard from the node again this is only a
|
||||
* simulation
|
||||
*/
|
||||
|
|
|
@ -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