{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/34886596","id":34886596,"diff_hunk":"@@ -322,50 +321,54 @@ private boolean deassociateDeadNodes(RoutingAllocation allocation) {\n     private boolean applyStartedShards(RoutingNodes routingNodes, Iterable<? extends ShardRouting> startedShardEntries) {\n         boolean dirty = false;\n         // apply shards might be called several times with the same shard, ignore it\n+        STARTED_SHARDS_LOOP:\n         for (ShardRouting startedShard : startedShardEntries) {\n             assert startedShard.initializing();\n \n-            // retrieve the relocating node id before calling startedShard().\n-            String relocatingNodeId = null;\n+            // validate index still exists. strictly speaking this is not needed but it gives clearer logs\n+            if (routingNodes.routingTable().index(startedShard.index()) == null) {\n+                logger.debug(\"{} ignoring shard started, unknown index (routing: {})\", startedShard.shardId(), startedShard);\n+                continue;\n+            }\n+\n \n             RoutingNodes.RoutingNodeIterator currentRoutingNode = routingNodes.routingNodeIter(startedShard.currentNodeId());\n-            if (currentRoutingNode != null) {\n-                for (ShardRouting shard : currentRoutingNode) {\n-                    if (shard.shardId().equals(startedShard.shardId())) {\n-                        if (shard.equals(startedShard)) {\n-                            relocatingNodeId = shard.relocatingNodeId();\n-                            dirty = true;\n-                            routingNodes.started(shard);\n-                            logger.trace(\"{} marked as started\", shard);\n-                        } else {\n-                            logger.debug(\"failed to find shard [{}] in order to start it [no matching shard on node], ignoring\", startedShard);\n-                        }\n+            if (currentRoutingNode == null) {\n+                logger.debug(\"{} failed to find shard in order to start it [failed to find node], ignoring (routing: {})\", startedShard.shardId(), startedShard);\n+                continue;\n+            }\n+\n+            for (ShardRouting shard : currentRoutingNode) {\n+                if (shard.allocationId().getId().equals(startedShard.allocationId().getId())) {\n+                    if (shard.active()) {\n+                        logger.trace(\"{} shard is already started, ignoring (routing: {})\", startedShard.shardId(), startedShard);\n+                    } else {\n+                        dirty = true;\n+                        // override started shard with the latest copy. Capture it now , before starting the shard destroys it...\n+                        startedShard = new ShardRouting(shard);\n+                        routingNodes.started(shard);\n+                        logger.trace(\"{} marked shard as started (routing: {})\", startedShard.shardId(), startedShard);\n                         break;","path":"core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java","position":52,"original_position":52,"commit_id":"e7b05464850fe2d5e9dfcf52e8d925adc73f6560","original_commit_id":"e7b05464850fe2d5e9dfcf52e8d925adc73f6560","user":{"login":"bleskes","id":1006375,"avatar_url":"https://avatars.githubusercontent.com/u/1006375?v=3","gravatar_id":"","url":"https://api.github.com/users/bleskes","html_url":"https://github.com/bleskes","followers_url":"https://api.github.com/users/bleskes/followers","following_url":"https://api.github.com/users/bleskes/following{/other_user}","gists_url":"https://api.github.com/users/bleskes/gists{/gist_id}","starred_url":"https://api.github.com/users/bleskes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bleskes/subscriptions","organizations_url":"https://api.github.com/users/bleskes/orgs","repos_url":"https://api.github.com/users/bleskes/repos","events_url":"https://api.github.com/users/bleskes/events{/privacy}","received_events_url":"https://api.github.com/users/bleskes/received_events","type":"User","site_admin":false},"body":"yeah.. will cahnged.","created_at":"2015-07-17T13:02:37Z","updated_at":"2015-07-17T13:02:37Z","html_url":"https://github.com/elastic/elasticsearch/pull/12299#discussion_r34886596","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/12299","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/34886596"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/12299#discussion_r34886596"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/12299"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/12299","id":40172449,"html_url":"https://github.com/elastic/elasticsearch/pull/12299","diff_url":"https://github.com/elastic/elasticsearch/pull/12299.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/12299.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/12299","number":12299,"state":"open","locked":false,"title":"Use recently added allocation ids for shard started/failed","user":{"login":"bleskes","id":1006375,"avatar_url":"https://avatars.githubusercontent.com/u/1006375?v=3","gravatar_id":"","url":"https://api.github.com/users/bleskes","html_url":"https://github.com/bleskes","followers_url":"https://api.github.com/users/bleskes/followers","following_url":"https://api.github.com/users/bleskes/following{/other_user}","gists_url":"https://api.github.com/users/bleskes/gists{/gist_id}","starred_url":"https://api.github.com/users/bleskes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bleskes/subscriptions","organizations_url":"https://api.github.com/users/bleskes/orgs","repos_url":"https://api.github.com/users/bleskes/repos","events_url":"https://api.github.com/users/bleskes/events{/privacy}","received_events_url":"https://api.github.com/users/bleskes/received_events","type":"User","site_admin":false},"body":"#12242 introduced the notion of allocation id - a unique identifier that is changed every time a shard is assigned to a node. This new id is a much utility to do the shard matching needed when processing shard started/failed messages. No need to match index uuid, node id and shard state. This change simplifies the matching logic to use these allocation ids.\r\n\r\n On top of that:\r\n 1) A relocation target shards' allocation id is changed to include the allocation id of the source shard under relocatingId (similar to shard routing semantics)\r\n 2) The logic around state change for finalize shard relocation is simplified - one simple start the target shard (we previously had unused logic around relocating state)","created_at":"2015-07-16T20:31:42Z","updated_at":"2015-07-17T13:02:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"56f835aa017ea0693827ffc19016e8b234e79656","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/12299/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/12299/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/12299/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/e7b05464850fe2d5e9dfcf52e8d925adc73f6560","head":{"label":"bleskes:allocation_use_alloc_id_for_matching","ref":"allocation_use_alloc_id_for_matching","sha":"e7b05464850fe2d5e9dfcf52e8d925adc73f6560","user":{"login":"bleskes","id":1006375,"avatar_url":"https://avatars.githubusercontent.com/u/1006375?v=3","gravatar_id":"","url":"https://api.github.com/users/bleskes","html_url":"https://github.com/bleskes","followers_url":"https://api.github.com/users/bleskes/followers","following_url":"https://api.github.com/users/bleskes/following{/other_user}","gists_url":"https://api.github.com/users/bleskes/gists{/gist_id}","starred_url":"https://api.github.com/users/bleskes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bleskes/subscriptions","organizations_url":"https://api.github.com/users/bleskes/orgs","repos_url":"https://api.github.com/users/bleskes/repos","events_url":"https://api.github.com/users/bleskes/events{/privacy}","received_events_url":"https://api.github.com/users/bleskes/received_events","type":"User","site_admin":false},"repo":{"id":9219509,"name":"elasticsearch","full_name":"bleskes/elasticsearch","owner":{"login":"bleskes","id":1006375,"avatar_url":"https://avatars.githubusercontent.com/u/1006375?v=3","gravatar_id":"","url":"https://api.github.com/users/bleskes","html_url":"https://github.com/bleskes","followers_url":"https://api.github.com/users/bleskes/followers","following_url":"https://api.github.com/users/bleskes/following{/other_user}","gists_url":"https://api.github.com/users/bleskes/gists{/gist_id}","starred_url":"https://api.github.com/users/bleskes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bleskes/subscriptions","organizations_url":"https://api.github.com/users/bleskes/orgs","repos_url":"https://api.github.com/users/bleskes/repos","events_url":"https://api.github.com/users/bleskes/events{/privacy}","received_events_url":"https://api.github.com/users/bleskes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bleskes/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/bleskes/elasticsearch","forks_url":"https://api.github.com/repos/bleskes/elasticsearch/forks","keys_url":"https://api.github.com/repos/bleskes/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bleskes/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bleskes/elasticsearch/teams","hooks_url":"https://api.github.com/repos/bleskes/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/bleskes/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/bleskes/elasticsearch/events","assignees_url":"https://api.github.com/repos/bleskes/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/bleskes/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/bleskes/elasticsearch/tags","blobs_url":"https://api.github.com/repos/bleskes/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bleskes/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bleskes/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/bleskes/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bleskes/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/bleskes/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/bleskes/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/bleskes/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/bleskes/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/bleskes/elasticsearch/subscription","commits_url":"https://api.github.com/repos/bleskes/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/bleskes/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/bleskes/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/bleskes/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/bleskes/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/bleskes/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bleskes/elasticsearch/merges","archive_url":"https://api.github.com/repos/bleskes/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bleskes/elasticsearch/downloads","issues_url":"https://api.github.com/repos/bleskes/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/bleskes/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/bleskes/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/bleskes/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bleskes/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/bleskes/elasticsearch/releases{/id}","created_at":"2013-04-04T14:06:17Z","updated_at":"2015-04-24T10:42:15Z","pushed_at":"2015-07-17T09:12:13Z","git_url":"git://github.com/bleskes/elasticsearch.git","ssh_url":"git@github.com:bleskes/elasticsearch.git","clone_url":"https://github.com/bleskes/elasticsearch.git","svn_url":"https://github.com/bleskes/elasticsearch","homepage":"http://elasticsearch.org","size":147984,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"b7107663d171df9ffdde3f5cbf148d015e4b6241","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","created_at":"2010-02-08T13:20:56Z","updated_at":"2015-07-17T12:18:44Z","pushed_at":"2015-07-17T12:35:41Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":1903754,"stargazers_count":12033,"watchers_count":12033,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3832,"mirror_url":null,"open_issues_count":1119,"forks":3832,"open_issues":1119,"watchers":12033,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/12299"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/12299"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/12299"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/12299/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/12299/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/12299/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/e7b05464850fe2d5e9dfcf52e8d925adc73f6560"}}}}