{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/212660815","pull_request_review_id":149313525,"id":212660815,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMjY2MDgxNQ==","diff_hunk":"@@ -500,15 +503,21 @@ public void updateShardState(final ShardRouting newRouting,\n                                  * numbers. To ensure that this is not the case, we restore the state of the local checkpoint tracker by\n                                  * replaying the translog and marking any operations there are completed.\n                                  */\n-                                final Engine engine = getEngine();\n-                                engine.restoreLocalCheckpointFromTranslog();\n+                                if (seqNoStats().getLocalCheckpoint() < maxSeqNoOfResettingEngine) {\n+                                    // The engine was reset before but hasn't restored all existing operations yet.\n+                                    // We need to reset the engine again with all the local history.\n+                                    getEngine().flush();\n+                                    resetEngineUpToSeqNo(Long.MAX_VALUE);\n+                                } else {\n+                                    getEngine().restoreLocalCheckpointFromTranslog();\n+                                }\n                                 /* Rolling the translog generation is not strictly needed here (as we will never have collisions between\n                                  * sequence numbers in a translog generation in a new primary as it takes the last known sequence number\n                                  * as a starting point), but it simplifies reasoning about the relationship between primary terms and\n                                  * translog generations.\n                                  */\n-                                engine.rollTranslogGeneration();\n-                                engine.fillSeqNoGaps(newPrimaryTerm);\n+                                getEngine().rollTranslogGeneration();","path":"server/src/main/java/org/elasticsearch/index/shard/IndexShard.java","position":45,"original_position":45,"commit_id":"607535df70bc2585dd08339e5bc02375b797f0aa","original_commit_id":"607535df70bc2585dd08339e5bc02375b797f0aa","user":{"login":"s1monw","id":973334,"node_id":"MDQ6VXNlcjk3MzMzNA==","avatar_url":"https://avatars0.githubusercontent.com/u/973334?v=4","gravatar_id":"","url":"https://api.github.com/users/s1monw","html_url":"https://github.com/s1monw","followers_url":"https://api.github.com/users/s1monw/followers","following_url":"https://api.github.com/users/s1monw/following{/other_user}","gists_url":"https://api.github.com/users/s1monw/gists{/gist_id}","starred_url":"https://api.github.com/users/s1monw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s1monw/subscriptions","organizations_url":"https://api.github.com/users/s1monw/orgs","repos_url":"https://api.github.com/users/s1monw/repos","events_url":"https://api.github.com/users/s1monw/events{/privacy}","received_events_url":"https://api.github.com/users/s1monw/received_events","type":"User","site_admin":false},"body":"can we fetch the engine only once in this method?","created_at":"2018-08-24T15:10:50Z","updated_at":"2018-08-24T15:11:21Z","html_url":"https://github.com/elastic/elasticsearch/pull/32867#discussion_r212660815","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/32867","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/212660815"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/32867#discussion_r212660815"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/32867"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/32867","id":208461941,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA4NDYxOTQx","html_url":"https://github.com/elastic/elasticsearch/pull/32867","diff_url":"https://github.com/elastic/elasticsearch/pull/32867.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/32867.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/32867","number":32867,"state":"open","locked":false,"title":"Reset replica engine before primary-replica resync","user":{"login":"dnhatn","id":13474362,"node_id":"MDQ6VXNlcjEzNDc0MzYy","avatar_url":"https://avatars3.githubusercontent.com/u/13474362?v=4","gravatar_id":"","url":"https://api.github.com/users/dnhatn","html_url":"https://github.com/dnhatn","followers_url":"https://api.github.com/users/dnhatn/followers","following_url":"https://api.github.com/users/dnhatn/following{/other_user}","gists_url":"https://api.github.com/users/dnhatn/gists{/gist_id}","starred_url":"https://api.github.com/users/dnhatn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnhatn/subscriptions","organizations_url":"https://api.github.com/users/dnhatn/orgs","repos_url":"https://api.github.com/users/dnhatn/repos","events_url":"https://api.github.com/users/dnhatn/events{/privacy}","received_events_url":"https://api.github.com/users/dnhatn/received_events","type":"User","site_admin":false},"body":"When a replica starts following a newly promoted primary, it may have\r\nsome operations which don't exist on the new primary. We need to reset\r\nreplicas to the global checkpoint before executing primary-replica\r\nresync. These two steps will align replicas to the primary.\r\n\r\nThis change resets an engine of a replica to the safe commit when\r\ndetecting a new primary term, then reindex operations from the local\r\ntranslog up to the global checkpoint.\r\n","created_at":"2018-08-15T03:04:25Z","updated_at":"2018-08-24T15:11:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"40423fa9ab6236863849f543c08dc0887301ad59","assignee":null,"assignees":[],"requested_reviewers":[{"login":"bleskes","id":1006375,"node_id":"MDQ6VXNlcjEwMDYzNzU=","avatar_url":"https://avatars1.githubusercontent.com/u/1006375?v=4","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},{"login":"ywelsch","id":3718355,"node_id":"MDQ6VXNlcjM3MTgzNTU=","avatar_url":"https://avatars3.githubusercontent.com/u/3718355?v=4","gravatar_id":"","url":"https://api.github.com/users/ywelsch","html_url":"https://github.com/ywelsch","followers_url":"https://api.github.com/users/ywelsch/followers","following_url":"https://api.github.com/users/ywelsch/following{/other_user}","gists_url":"https://api.github.com/users/ywelsch/gists{/gist_id}","starred_url":"https://api.github.com/users/ywelsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ywelsch/subscriptions","organizations_url":"https://api.github.com/users/ywelsch/orgs","repos_url":"https://api.github.com/users/ywelsch/repos","events_url":"https://api.github.com/users/ywelsch/events{/privacy}","received_events_url":"https://api.github.com/users/ywelsch/received_events","type":"User","site_admin":false},{"login":"jasontedor","id":4744941,"node_id":"MDQ6VXNlcjQ3NDQ5NDE=","avatar_url":"https://avatars3.githubusercontent.com/u/4744941?v=4","gravatar_id":"","url":"https://api.github.com/users/jasontedor","html_url":"https://github.com/jasontedor","followers_url":"https://api.github.com/users/jasontedor/followers","following_url":"https://api.github.com/users/jasontedor/following{/other_user}","gists_url":"https://api.github.com/users/jasontedor/gists{/gist_id}","starred_url":"https://api.github.com/users/jasontedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasontedor/subscriptions","organizations_url":"https://api.github.com/users/jasontedor/orgs","repos_url":"https://api.github.com/users/jasontedor/repos","events_url":"https://api.github.com/users/jasontedor/events{/privacy}","received_events_url":"https://api.github.com/users/jasontedor/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":152510590,"node_id":"MDU6TGFiZWwxNTI1MTA1OTA=","url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Distributed/Recovery","name":":Distributed/Recovery","color":"0e8a16","default":false},{"id":23174,"node_id":"MDU6TGFiZWwyMzE3NA==","url":"https://api.github.com/repos/elastic/elasticsearch/labels/%3Eenhancement","name":">enhancement","color":"4a4ea8","default":false},{"id":962378555,"node_id":"MDU6TGFiZWw5NjIzNzg1NTU=","url":"https://api.github.com/repos/elastic/elasticsearch/labels/v6.5.0","name":"v6.5.0","color":"Dddddd","default":false},{"id":484855464,"node_id":"MDU6TGFiZWw0ODQ4NTU0NjQ=","url":"https://api.github.com/repos/elastic/elasticsearch/labels/v7.0.0","name":"v7.0.0","color":"dddddd","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/32867/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/32867/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/32867/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/607535df70bc2585dd08339e5bc02375b797f0aa","head":{"label":"dnhatn:rollback-on-resync","ref":"rollback-on-resync","sha":"607535df70bc2585dd08339e5bc02375b797f0aa","user":{"login":"dnhatn","id":13474362,"node_id":"MDQ6VXNlcjEzNDc0MzYy","avatar_url":"https://avatars3.githubusercontent.com/u/13474362?v=4","gravatar_id":"","url":"https://api.github.com/users/dnhatn","html_url":"https://github.com/dnhatn","followers_url":"https://api.github.com/users/dnhatn/followers","following_url":"https://api.github.com/users/dnhatn/following{/other_user}","gists_url":"https://api.github.com/users/dnhatn/gists{/gist_id}","starred_url":"https://api.github.com/users/dnhatn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnhatn/subscriptions","organizations_url":"https://api.github.com/users/dnhatn/orgs","repos_url":"https://api.github.com/users/dnhatn/repos","events_url":"https://api.github.com/users/dnhatn/events{/privacy}","received_events_url":"https://api.github.com/users/dnhatn/received_events","type":"User","site_admin":false},"repo":{"id":94910455,"node_id":"MDEwOlJlcG9zaXRvcnk5NDkxMDQ1NQ==","name":"elasticsearch","full_name":"dnhatn/elasticsearch","owner":{"login":"dnhatn","id":13474362,"node_id":"MDQ6VXNlcjEzNDc0MzYy","avatar_url":"https://avatars3.githubusercontent.com/u/13474362?v=4","gravatar_id":"","url":"https://api.github.com/users/dnhatn","html_url":"https://github.com/dnhatn","followers_url":"https://api.github.com/users/dnhatn/followers","following_url":"https://api.github.com/users/dnhatn/following{/other_user}","gists_url":"https://api.github.com/users/dnhatn/gists{/gist_id}","starred_url":"https://api.github.com/users/dnhatn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnhatn/subscriptions","organizations_url":"https://api.github.com/users/dnhatn/orgs","repos_url":"https://api.github.com/users/dnhatn/repos","events_url":"https://api.github.com/users/dnhatn/events{/privacy}","received_events_url":"https://api.github.com/users/dnhatn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dnhatn/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/dnhatn/elasticsearch","forks_url":"https://api.github.com/repos/dnhatn/elasticsearch/forks","keys_url":"https://api.github.com/repos/dnhatn/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dnhatn/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dnhatn/elasticsearch/teams","hooks_url":"https://api.github.com/repos/dnhatn/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/dnhatn/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/dnhatn/elasticsearch/events","assignees_url":"https://api.github.com/repos/dnhatn/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/dnhatn/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/dnhatn/elasticsearch/tags","blobs_url":"https://api.github.com/repos/dnhatn/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dnhatn/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dnhatn/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/dnhatn/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dnhatn/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/dnhatn/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/dnhatn/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/dnhatn/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/dnhatn/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/dnhatn/elasticsearch/subscription","commits_url":"https://api.github.com/repos/dnhatn/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/dnhatn/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/dnhatn/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/dnhatn/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/dnhatn/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/dnhatn/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dnhatn/elasticsearch/merges","archive_url":"https://api.github.com/repos/dnhatn/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dnhatn/elasticsearch/downloads","issues_url":"https://api.github.com/repos/dnhatn/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/dnhatn/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/dnhatn/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/dnhatn/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dnhatn/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/dnhatn/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/dnhatn/elasticsearch/deployments","created_at":"2017-06-20T16:05:45Z","updated_at":"2018-07-11T01:03:03Z","pushed_at":"2018-08-24T14:06:37Z","git_url":"git://github.com/dnhatn/elasticsearch.git","ssh_url":"git@github.com:dnhatn/elasticsearch.git","clone_url":"https://github.com/dnhatn/elasticsearch.git","svn_url":"https://github.com/dnhatn/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":444807,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"8f16696fe12bd406327b0f715f513a33c642ec37","user":{"login":"elastic","id":6764390,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3NjQzOTA=","avatar_url":"https://avatars0.githubusercontent.com/u/6764390?v=4","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,"node_id":"MDEwOlJlcG9zaXRvcnk1MDc3NzU=","name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3NjQzOTA=","avatar_url":"https://avatars0.githubusercontent.com/u/6764390?v=4","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}","deployments_url":"https://api.github.com/repos/elastic/elasticsearch/deployments","created_at":"2010-02-08T13:20:56Z","updated_at":"2018-08-24T14:49:34Z","pushed_at":"2018-08-24T15:06:13Z","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":505640,"stargazers_count":33732,"watchers_count":33732,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11465,"mirror_url":null,"archived":false,"open_issues_count":1608,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":11465,"open_issues":1608,"watchers":33732,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/32867"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/32867"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/32867"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/32867/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/32867/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/32867/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/607535df70bc2585dd08339e5bc02375b797f0aa"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"s1monw"}}