Skip to content

Commit 6af80d5

Browse files
geidiess1monw
authored andcommitted
Optimizes performance of AllocationDecider execution. Instead of using loops over all ShardRoutings, do accounting in RoutingNodes.
Speeds up recalculating cluster state on large clusters.
1 parent 6a856c8 commit 6af80d5

16 files changed

+973
-150
lines changed

src/main/java/org/elasticsearch/cluster/routing/MutableShardRouting.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ public MutableShardRouting(String index, int shardId, String currentNodeId,
5555
*
5656
* @param nodeId id of the node to assign this shard to
5757
*/
58-
public void assignToNode(String nodeId) {
58+
void assignToNode(String nodeId) {
5959
version++;
60+
6061
if (currentNodeId == null) {
6162
assert state == ShardRoutingState.UNASSIGNED;
6263

@@ -76,7 +77,7 @@ public void assignToNode(String nodeId) {
7677
*
7778
* @param relocatingNodeId id of the node to relocate the shard
7879
*/
79-
public void relocate(String relocatingNodeId) {
80+
void relocate(String relocatingNodeId) {
8081
version++;
8182
assert state == ShardRoutingState.STARTED;
8283
state = ShardRoutingState.RELOCATING;
@@ -87,7 +88,7 @@ public void relocate(String relocatingNodeId) {
8788
* Cancel relocation of a shard. The shards state must be set
8889
* to <code>RELOCATING</code>.
8990
*/
90-
public void cancelRelocation() {
91+
void cancelRelocation() {
9192
version++;
9293
assert state == ShardRoutingState.RELOCATING;
9394
assert assignedToNode();
@@ -101,7 +102,7 @@ public void cancelRelocation() {
101102
* Set the shards state to <code>UNASSIGNED</code>.
102103
* //TODO document the state
103104
*/
104-
public void deassignNode() {
105+
void deassignNode() {
105106
version++;
106107
assert state != ShardRoutingState.UNASSIGNED;
107108

@@ -115,7 +116,7 @@ public void deassignNode() {
115116
* <code>INITIALIZING</code> or <code>RELOCATING</code>. Any relocation will be
116117
* canceled.
117118
*/
118-
public void moveToStarted() {
119+
void moveToStarted() {
119120
version++;
120121
assert state == ShardRoutingState.INITIALIZING || state == ShardRoutingState.RELOCATING;
121122
relocatingNodeId = null;
@@ -127,7 +128,7 @@ public void moveToStarted() {
127128
* Make the shard primary unless it's not Primary
128129
* //TODO: doc exception
129130
*/
130-
public void moveToPrimary() {
131+
void moveToPrimary() {
131132
version++;
132133
if (primary) {
133134
throw new IllegalShardRoutingStateException(this, "Already primary, can't move to primary");
@@ -138,20 +139,13 @@ public void moveToPrimary() {
138139
/**
139140
* Set the primary shard to non-primary
140141
*/
141-
public void moveFromPrimary() {
142+
void moveFromPrimary() {
142143
version++;
143144
if (!primary) {
144145
throw new IllegalShardRoutingStateException(this, "Not primary, can't move to replica");
145146
}
146147
primary = false;
147148
}
148149

149-
public void restoreFrom(RestoreSource restoreSource) {
150-
version++;
151-
if (!primary) {
152-
throw new IllegalShardRoutingStateException(this, "Not primary, can't restore from snapshot to replica");
153-
}
154-
this.restoreSource = restoreSource;
155-
}
156150
}
157151

src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,14 @@ public List<MutableShardRouting> shards() {
8484
* Add a new shard to this node
8585
* @param shard Shard to crate on this Node
8686
*/
87-
public void add(MutableShardRouting shard) {
87+
void add(MutableShardRouting shard) {
88+
// TODO use Set with ShardIds for faster lookup.
8889
for (MutableShardRouting shardRouting : shards) {
8990
if (shardRouting.shardId().equals(shard.shardId())) {
9091
throw new ElasticSearchIllegalStateException("Trying to add a shard [" + shard.shardId().index().name() + "][" + shard.shardId().id() + "] to a node [" + nodeId + "] where it already exists");
9192
}
9293
}
9394
shards.add(shard);
94-
shard.assignToNode(node.id());
95-
}
96-
97-
/**
98-
* Remove a shard from this node
99-
* @param shardId id of the shard to remove
100-
*/
101-
public void removeByShardId(int shardId) {
102-
for (Iterator<MutableShardRouting> it = shards.iterator(); it.hasNext(); ) {
103-
MutableShardRouting shard = it.next();
104-
if (shard.id() == shardId) {
105-
it.remove();
106-
}
107-
}
10895
}
10996

11097
/**

0 commit comments

Comments
 (0)