{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/223580219","pull_request_review_id":162739933,"id":223580219,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyMzU4MDIxOQ==","diff_hunk":"@@ -111,36 +114,63 @@ public TransportBulkShardOperationsAction(\n                     throw new IllegalStateException(\"unexpected operation type [\" + operation.opType() + \"]\");\n             }\n             return operationWithPrimaryTerm;\n-        }).collect(Collectors.toList());\n+        };\n+\n         assert maxSeqNoOfUpdatesOrDeletes >= SequenceNumbers.NO_OPS_PERFORMED : \"invalid msu [\" + maxSeqNoOfUpdatesOrDeletes + \"]\";\n         primary.advanceMaxSeqNoOfUpdatesOrDeletes(maxSeqNoOfUpdatesOrDeletes);\n-        final Translog.Location location = applyTranslogOperations(targetOperations, primary, Engine.Operation.Origin.PRIMARY);\n+\n+        final List<Translog.Operation> appliedOperations = new ArrayList<>(sourceOperations.size());\n+        Translog.Location location = null;\n+        long waitingForGlobalCheckpoint = SequenceNumbers.UNASSIGNED_SEQ_NO;\n+        for (Translog.Operation sourceOp : sourceOperations) {\n+            final Translog.Operation targetOp = rewriteWithTerm.apply(sourceOp);\n+            final Engine.Result result = primary.applyTranslogOperation(targetOp, Engine.Operation.Origin.PRIMARY);\n+            if (result.getResultType() == Engine.Result.Type.SUCCESS) {\n+                assert result.getSeqNo() == targetOp.seqNo();\n+                appliedOperations.add(targetOp);\n+                location = locationToSync(location, result.getTranslogLocation());\n+            } else {\n+                if (result.getFailure() instanceof AlreadyProcessedFollowingEngineException) {\n+                    // Skipped operations will be delivered to replicas via primary-replica resync or peer-recovery.\n+                    // The primary must not acknowledge this request until the global checkpoint is at least the highest\n+                    // seqno of all skipped operations (i.e., all skipped operations have been processed on every replica).\n+                    waitingForGlobalCheckpoint = SequenceNumbers.max(waitingForGlobalCheckpoint, targetOp.seqNo());\n+                } else {\n+                    assert false : \"Only already-processed error should happen; op=[\" + targetOp + \"] error=[\" + result.getFailure() + \"]\";\n+                    throw ExceptionsHelper.convertToElastic(result.getFailure());\n+                }\n+            }\n+        }\n+        assert appliedOperations.size() == sourceOperations.size() || waitingForGlobalCheckpoint != SequenceNumbers.UNASSIGNED_SEQ_NO;","path":"x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/bulk/TransportBulkShardOperationsAction.java","position":73,"original_position":73,"commit_id":"85844a625ffe9526a3cef2ef78ddcaf06798041c","original_commit_id":"85844a625ffe9526a3cef2ef78ddcaf06798041c","user":{"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},"body":"can you add a message?","created_at":"2018-10-09T07:03:07Z","updated_at":"2018-10-09T07:50:42Z","html_url":"https://github.com/elastic/elasticsearch/pull/34288#discussion_r223580219","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/34288","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/223580219"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/34288#discussion_r223580219"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/34288"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/34288","id":220237859,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIwMjM3ODU5","html_url":"https://github.com/elastic/elasticsearch/pull/34288","diff_url":"https://github.com/elastic/elasticsearch/pull/34288.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/34288.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/34288","number":34288,"state":"open","locked":false,"title":"CCR: Following primary should process operations once","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":"Today we rewrite the operations from the leader with the term of the\r\nfollowing primary because the follower should own its history. The\r\nproblem is that a newly promoted primary may re-assign its term to\r\noperations which were replicated to replicas before by the previous\r\nprimary. If this happens, some operations with the same seq_no may be\r\nassigned different terms. This is not good for the future optimistic\r\nlocking using a combination of seqno and term.\r\n\r\nThis change ensures that the primary of a follower only processes an\r\noperation if that operation was not processed before. The skipped\r\noperations are guaranteed to be delivered to replicas via either\r\nprimary-replica resync or peer-recovery. However, the primary must not\r\nacknowledge until the global checkpoint is at least the highest seqno of\r\nall skipped ops (i.e., they all have been processed on every replica).\r\n\r\nRelates #31751\r\nRelates #31113","created_at":"2018-10-04T03:15:07Z","updated_at":"2018-10-09T07:50:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2e56cefc76c7931e30a61f0d804ac7cc6fa395d5","assignee":null,"assignees":[],"requested_reviewers":[{"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":912824565,"node_id":"MDU6TGFiZWw5MTI4MjQ1NjU=","url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Distributed/CCR","name":":Distributed/CCR","color":"0e8a16","default":false},{"id":73544,"node_id":"MDU6TGFiZWw3MzU0NA==","url":"https://api.github.com/repos/elastic/elasticsearch/labels/%3Enon-issue","name":">non-issue","color":"cfcfcf","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/34288/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/34288/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/34288/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/85844a625ffe9526a3cef2ef78ddcaf06798041c","head":{"label":"dnhatn:ccr-index-once","ref":"ccr-index-once","sha":"85844a625ffe9526a3cef2ef78ddcaf06798041c","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","private":false,"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},"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-09-21T20:14:06Z","pushed_at":"2018-10-06T01:38:51Z","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":489924,"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":"NOASSERTION","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"c031322c18496883d45d48d9ef15bec277632122","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","private":false,"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},"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-10-09T07:37:53Z","pushed_at":"2018-10-09T07:26:23Z","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":518595,"stargazers_count":34987,"watchers_count":34987,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11855,"mirror_url":null,"archived":false,"open_issues_count":1692,"license":{"key":"other","name":"NOASSERTION","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":11855,"open_issues":1692,"watchers":34987,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/34288"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/34288"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/34288"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/34288/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/34288/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/34288/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/85844a625ffe9526a3cef2ef78ddcaf06798041c"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"bleskes"}}