ConcurrentModificationException including patch.

Hi, I got the following exception.

java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
at java.util.HashMap$KeyIterator.next(HashMap.java:828)
at org.elasticsearch.gateway.local.LocalGatewayNodeAllocation.buildShardStores(LocalGatewayNodeAllocation.java:353)
at org.elasticsearch.gateway.local.LocalGatewayNodeAllocation.allocateUnassigned(LocalGatewayNodeAllocation.java:213)
at org.elasticsearch.cluster.routing.allocation.NodeAllocations.allocateUnassigned(NodeAllocations.java:80)
at org.elasticsearch.cluster.routing.allocation.ShardsAllocation.reroute(ShardsAllocation.java:147)
at org.elasticsearch.cluster.routing.allocation.ShardsAllocation.reroute(ShardsAllocation.java:99)
at org.elasticsearch.cluster.routing.RoutingService$RoutingTableUpdater$1.execute(RoutingService.java:124)
at org.elasticsearch.cluster.service.InternalClusterService$2.run(InternalClusterService.java:175)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

I think it should look like this:

--- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGatewayNodeAllocation.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGatewayNodeAllocation.java
@@ -350,9 +350,10 @@ public class LocalGatewayNodeAllocation extends
NodeAllocation {
} else {
nodesIds = Sets.newHashSet();
// clean nodes that have failed

  •        for (DiscoveryNode node : shardStores.keySet()) {
    
  •            if (!nodes.nodeExists(node.id())) {
    
  •                shardStores.remove(node);
    
  •        for (Iterator<DiscoveryNode> i =
    

shardStores.keySet().iterator(); i.hasNext():wink: {

  •    	    DiscoveryNode node = i.next();
    
  •    	    if (!nodes.nodeExists(node.id())) {
    
  •                i.remove();
               }
           }

Heya, yea, it used to be a CHM, but there was no need for a concurrent version, and then this bug was introduced... . Here is the issue: Failure when applying failed shards during local gateway allocation · Issue #903 · elastic/elasticsearch · GitHub, fixed in 0.16 and master.
On Wednesday, May 4, 2011 at 7:52 PM, Michel Conrad wrote:

--- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGatewayNodeAllocation.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGatewayNodeAllocation.java
@@ -350,9 +350,10 @@ public class LocalGatewayNodeAllocation extends
NodeAllocation {
} else {
nodesIds = Sets.newHashSet();
// clean nodes that have failed

  • for (DiscoveryNode node : shardStores.keySet()) {
  • if (!nodes.nodeExists(node.id())) {
  • shardStores.remove(node);
  • for (Iterator i =
    shardStores.keySet().iterator(); i.hasNext():wink: {
  • DiscoveryNode node = i.next();
  • if (!nodes.nodeExists(node.id())) {
  • i.remove();
    }
    }