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) {
|
public MutableShardRouting findPrimaryForReplica(ShardRouting shard) {
|
||||||
assert !shard.primary();
|
assert !shard.primary();
|
||||||
for (RoutingNode routingNode : nodesToShards.values()) {
|
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()) {
|
if (shardRouting.shardId().equals(shard.shardId()) && shardRouting.primary()) {
|
||||||
return shardRouting;
|
return shardRouting;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ClusterRebalanceAllocationDecider extends AllocationDecider {
|
public class ClusterRebalanceAllocationDecider extends AllocationDecider {
|
||||||
|
|
||||||
public static enum ClusterRebalanceType {
|
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);
|
logger.warn("[cluster.routing.allocation.allow_rebalance] has a wrong value {}, defaulting to 'indices_all_active'", allowRebalance);
|
||||||
type = ClusterRebalanceType.INDICES_ALL_ACTIVE;
|
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) {
|
@Override public boolean canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
|
||||||
|
@ -60,7 +62,9 @@ public class ClusterRebalanceAllocationDecider extends AllocationDecider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (RoutingNode node : allocation.routingNodes()) {
|
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()) {
|
if (shard.primary() && !shard.active()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +77,9 @@ public class ClusterRebalanceAllocationDecider extends AllocationDecider {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (RoutingNode node : allocation.routingNodes()) {
|
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()) {
|
if (!shard.active()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ConcurrentRebalanceAllocationDecider extends AllocationDecider {
|
public class ConcurrentRebalanceAllocationDecider extends AllocationDecider {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -62,8 +64,9 @@ public class ConcurrentRebalanceAllocationDecider extends AllocationDecider {
|
||||||
}
|
}
|
||||||
int rebalance = 0;
|
int rebalance = 0;
|
||||||
for (RoutingNode node : allocation.routingNodes()) {
|
for (RoutingNode node : allocation.routingNodes()) {
|
||||||
for (MutableShardRouting shard : node) {
|
List<MutableShardRouting> shards = node.shards();
|
||||||
if (shard.state() == ShardRoutingState.RELOCATING) {
|
for (int i = 0; i < shards.size(); i++) {
|
||||||
|
if (shards.get(i).state() == ShardRoutingState.RELOCATING) {
|
||||||
rebalance++;
|
rebalance++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,8 @@ public class RebalanceOnlyWhenActiveAllocationDecider extends AllocationDecider
|
||||||
List<MutableShardRouting> shards = allocation.routingNodes().shardsRoutingFor(shardRouting);
|
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
|
// its ok to check for active here, since in relocation, a shard is split into two in routing
|
||||||
// nodes, once relocating, and one initializing
|
// nodes, once relocating, and one initializing
|
||||||
for (ShardRouting allShard : shards) {
|
for (int i = 0; i < shards.size(); i++) {
|
||||||
if (!allShard.active()) {
|
if (!shards.get(i).active()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class ThrottlingAllocationDecider extends AllocationDecider {
|
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
|
// 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
|
// count *just the primary* currently doing recovery on the node and check against concurrent_recoveries
|
||||||
int primariesInRecovery = 0;
|
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()) {
|
if (shard.state() == ShardRoutingState.INITIALIZING && shard.primary()) {
|
||||||
primariesInRecovery++;
|
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)
|
// count the number of recoveries on the node, its for both target (INITIALIZING) and source (RELOCATING)
|
||||||
int currentRecoveries = 0;
|
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) {
|
if (shard.state() == ShardRoutingState.INITIALIZING || shard.state() == ShardRoutingState.RELOCATING) {
|
||||||
currentRecoveries++;
|
currentRecoveries++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue