associate a DiscoveryNode instance with RoutingNode, so there is no need to look it up based on node id
This commit is contained in:
parent
60933b0f1e
commit
4180a7f73a
|
@ -28,7 +28,11 @@ import org.elasticsearch.cluster.routing.RoutingTable;
|
|||
import org.elasticsearch.cluster.routing.allocation.AllocationExplanation;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.io.stream.*;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamInput;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.CachedStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -98,7 +102,7 @@ public class ClusterState {
|
|||
}
|
||||
|
||||
public RoutingNodes routingNodes() {
|
||||
return routingTable.routingNodes(metaData, blocks);
|
||||
return routingTable.routingNodes(this);
|
||||
}
|
||||
|
||||
public RoutingNodes getRoutingNodes() {
|
||||
|
@ -129,7 +133,7 @@ public class ClusterState {
|
|||
if (routingNodes != null) {
|
||||
return routingNodes;
|
||||
}
|
||||
routingNodes = routingTable.routingNodes(metaData, blocks);
|
||||
routingNodes = routingTable.routingNodes(this);
|
||||
return routingNodes;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.elasticsearch.cluster.routing;
|
||||
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -26,20 +28,19 @@ import java.util.List;
|
|||
import static org.elasticsearch.common.collect.Lists.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class RoutingNode implements Iterable<MutableShardRouting> {
|
||||
|
||||
private final String nodeId;
|
||||
private final DiscoveryNode node;
|
||||
|
||||
private final List<MutableShardRouting> shards;
|
||||
|
||||
public RoutingNode(String nodeId) {
|
||||
this(nodeId, new ArrayList<MutableShardRouting>());
|
||||
public RoutingNode(DiscoveryNode node) {
|
||||
this(node, new ArrayList<MutableShardRouting>());
|
||||
}
|
||||
|
||||
public RoutingNode(String nodeId, List<MutableShardRouting> shards) {
|
||||
this.nodeId = nodeId;
|
||||
public RoutingNode(DiscoveryNode node, List<MutableShardRouting> shards) {
|
||||
this.node = node;
|
||||
this.shards = shards;
|
||||
}
|
||||
|
||||
|
@ -47,8 +48,12 @@ public class RoutingNode implements Iterable<MutableShardRouting> {
|
|||
return shards.iterator();
|
||||
}
|
||||
|
||||
public DiscoveryNode node() {
|
||||
return this.node;
|
||||
}
|
||||
|
||||
public String nodeId() {
|
||||
return this.nodeId;
|
||||
return this.node.id();
|
||||
}
|
||||
|
||||
public List<MutableShardRouting> shards() {
|
||||
|
@ -57,11 +62,11 @@ public class RoutingNode implements Iterable<MutableShardRouting> {
|
|||
|
||||
public void add(MutableShardRouting shard) {
|
||||
shards.add(shard);
|
||||
shard.assignToNode(nodeId);
|
||||
shard.assignToNode(node.id());
|
||||
}
|
||||
|
||||
public void removeByShardId(int shardId) {
|
||||
for (Iterator<MutableShardRouting> it = shards.iterator(); it.hasNext();) {
|
||||
for (Iterator<MutableShardRouting> it = shards.iterator(); it.hasNext(); ) {
|
||||
MutableShardRouting shard = it.next();
|
||||
if (shard.id() == shardId) {
|
||||
it.remove();
|
||||
|
@ -134,7 +139,7 @@ public class RoutingNode implements Iterable<MutableShardRouting> {
|
|||
|
||||
public String prettyPrint() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("-----node_id[").append(nodeId).append("]\n");
|
||||
sb.append("-----node_id[").append(node.id()).append("]\n");
|
||||
for (MutableShardRouting entry : shards) {
|
||||
sb.append("--------").append(entry.shortSummary()).append('\n');
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.cluster.routing;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
|
@ -52,10 +53,10 @@ public class RoutingNodes implements Iterable<RoutingNode> {
|
|||
|
||||
private final List<MutableShardRouting> ignoredUnassigned = newArrayList();
|
||||
|
||||
public RoutingNodes(MetaData metaData, ClusterBlocks blocks, RoutingTable routingTable) {
|
||||
this.metaData = metaData;
|
||||
this.blocks = blocks;
|
||||
this.routingTable = routingTable;
|
||||
public RoutingNodes(ClusterState clusterState) {
|
||||
this.metaData = clusterState.metaData();
|
||||
this.blocks = clusterState.blocks();
|
||||
this.routingTable = clusterState.routingTable();
|
||||
Map<String, List<MutableShardRouting>> nodesToShards = newHashMap();
|
||||
for (IndexRoutingTable indexRoutingTable : routingTable.indicesRouting().values()) {
|
||||
for (IndexShardRoutingTable indexShard : indexRoutingTable) {
|
||||
|
@ -86,7 +87,7 @@ public class RoutingNodes implements Iterable<RoutingNode> {
|
|||
}
|
||||
for (Map.Entry<String, List<MutableShardRouting>> entry : nodesToShards.entrySet()) {
|
||||
String nodeId = entry.getKey();
|
||||
this.nodesToShards.put(nodeId, new RoutingNode(nodeId, entry.getValue()));
|
||||
this.nodesToShards.put(nodeId, new RoutingNode(clusterState.nodes().get(nodeId), entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.cluster.routing;
|
||||
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
|
@ -84,11 +83,7 @@ public class RoutingTable implements Iterable<IndexRoutingTable> {
|
|||
}
|
||||
|
||||
public RoutingNodes routingNodes(ClusterState state) {
|
||||
return routingNodes(state.metaData(), state.blocks());
|
||||
}
|
||||
|
||||
public RoutingNodes routingNodes(MetaData metaData, ClusterBlocks blocks) {
|
||||
return new RoutingNodes(metaData, blocks, this);
|
||||
return new RoutingNodes(state);
|
||||
}
|
||||
|
||||
public RoutingTable validateRaiseException(MetaData metaData) throws RoutingValidationException {
|
||||
|
|
|
@ -209,7 +209,7 @@ public class AllocationService extends AbstractComponent {
|
|||
private void applyNewNodes(RoutingNodes routingNodes, Iterable<DiscoveryNode> liveNodes) {
|
||||
for (DiscoveryNode node : liveNodes) {
|
||||
if (!routingNodes.nodesToShards().containsKey(node.id())) {
|
||||
RoutingNode routingNode = new RoutingNode(node.id());
|
||||
RoutingNode routingNode = new RoutingNode(node);
|
||||
routingNodes.nodesToShards().put(node.id(), routingNode);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue