use index iteration over iterator
This commit is contained in:
parent
f36d89c554
commit
18f15f0a6f
|
@ -176,7 +176,9 @@ public class RoutingNodes implements Iterable<RoutingNode> {
|
|||
public MutableShardRouting findPrimaryForReplica(ShardRouting shard) {
|
||||
assert !shard.primary();
|
||||
for (RoutingNode routingNode : nodesToShards.values()) {
|
||||
for (MutableShardRouting shardRouting : routingNode) {
|
||||
List<MutableShardRouting> shards = routingNode.shards();
|
||||
for (int i = 0; i < shards.size(); i++) {
|
||||
MutableShardRouting shardRouting = shards.get(i);
|
||||
if (shardRouting.shardId().equals(shard.shardId()) && shardRouting.primary()) {
|
||||
return shardRouting;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ClusterRebalanceAllocationDecider extends AllocationDecider {
|
||||
|
||||
public static enum ClusterRebalanceType {
|
||||
|
@ -49,7 +51,7 @@ public class ClusterRebalanceAllocationDecider extends AllocationDecider {
|
|||
logger.warn("[cluster.routing.allocation.allow_rebalance] has a wrong value {}, defaulting to 'indices_all_active'", allowRebalance);
|
||||
type = ClusterRebalanceType.INDICES_ALL_ACTIVE;
|
||||
}
|
||||
logger.debug("using [allow_rebalance] with [{}]", type.toString().toLowerCase());
|
||||
logger.debug("using [cluster.routing.allocation.allow_rebalance] with [{}]", type.toString().toLowerCase());
|
||||
}
|
||||
|
||||
@Override public boolean canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
|
||||
|
@ -60,7 +62,9 @@ public class ClusterRebalanceAllocationDecider extends AllocationDecider {
|
|||
}
|
||||
}
|
||||
for (RoutingNode node : allocation.routingNodes()) {
|
||||
for (MutableShardRouting shard : node) {
|
||||
List<MutableShardRouting> shards = node.shards();
|
||||
for (int i = 0; i < shards.size(); i++) {
|
||||
MutableShardRouting shard = shards.get(i);
|
||||
if (shard.primary() && !shard.active()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -73,7 +77,9 @@ public class ClusterRebalanceAllocationDecider extends AllocationDecider {
|
|||
return false;
|
||||
}
|
||||
for (RoutingNode node : allocation.routingNodes()) {
|
||||
for (MutableShardRouting shard : node) {
|
||||
List<MutableShardRouting> shards = node.shards();
|
||||
for (int i = 0; i < shards.size(); i++) {
|
||||
MutableShardRouting shard = shards.get(i);
|
||||
if (!shard.active()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.elasticsearch.common.inject.Inject;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConcurrentRebalanceAllocationDecider extends AllocationDecider {
|
||||
|
||||
static {
|
||||
|
@ -62,8 +64,9 @@ public class ConcurrentRebalanceAllocationDecider extends AllocationDecider {
|
|||
}
|
||||
int rebalance = 0;
|
||||
for (RoutingNode node : allocation.routingNodes()) {
|
||||
for (MutableShardRouting shard : node) {
|
||||
if (shard.state() == ShardRoutingState.RELOCATING) {
|
||||
List<MutableShardRouting> shards = node.shards();
|
||||
for (int i = 0; i < shards.size(); i++) {
|
||||
if (shards.get(i).state() == ShardRoutingState.RELOCATING) {
|
||||
rebalance++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ public class RebalanceOnlyWhenActiveAllocationDecider extends AllocationDecider
|
|||
List<MutableShardRouting> shards = allocation.routingNodes().shardsRoutingFor(shardRouting);
|
||||
// its ok to check for active here, since in relocation, a shard is split into two in routing
|
||||
// nodes, once relocating, and one initializing
|
||||
for (ShardRouting allShard : shards) {
|
||||
if (!allShard.active()) {
|
||||
for (int i = 0; i < shards.size(); i++) {
|
||||
if (!shards.get(i).active()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.elasticsearch.common.inject.Inject;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ThrottlingAllocationDecider extends AllocationDecider {
|
||||
|
@ -65,7 +67,9 @@ public class ThrottlingAllocationDecider extends AllocationDecider {
|
|||
// primary is unassigned, means we are going to do recovery from gateway
|
||||
// count *just the primary* currently doing recovery on the node and check against concurrent_recoveries
|
||||
int primariesInRecovery = 0;
|
||||
for (MutableShardRouting shard : node) {
|
||||
List<MutableShardRouting> shards = node.shards();
|
||||
for (int i = 0; i < shards.size(); i++) {
|
||||
MutableShardRouting shard = shards.get(i);
|
||||
if (shard.state() == ShardRoutingState.INITIALIZING && shard.primary()) {
|
||||
primariesInRecovery++;
|
||||
}
|
||||
|
@ -82,7 +86,9 @@ public class ThrottlingAllocationDecider extends AllocationDecider {
|
|||
|
||||
// count the number of recoveries on the node, its for both target (INITIALIZING) and source (RELOCATING)
|
||||
int currentRecoveries = 0;
|
||||
for (MutableShardRouting shard : node) {
|
||||
List<MutableShardRouting> shards = node.shards();
|
||||
for (int i = 0; i < shards.size(); i++) {
|
||||
MutableShardRouting shard = shards.get(i);
|
||||
if (shard.state() == ShardRoutingState.INITIALIZING || shard.state() == ShardRoutingState.RELOCATING) {
|
||||
currentRecoveries++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue