{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/59217970","id":59217970,"diff_hunk":"@@ -614,6 +540,92 @@ func (r *Replica) EndTransaction(\n \treturn reply, externalIntents, nil\n }\n \n+// resolveExplicitIntents resolve any explicit intents and persists e\n+// transaction record with updated status. All that are local to this\n+// range get resolved synchronously in the same batch. The remainder\n+// are collected and returned so that they can be handed off to\n+// asynchronous processing.\n+func (r *Replica) resolveExplicitIntents(batch engine.Engine, ms *engine.MVCCStats, args roachpb.EndTransactionRequest, txn *roachpb.Transaction) ([]roachpb.Intent, error) {\n+\tdesc := r.Desc()\n+\tvar preMergeDesc *roachpb.RangeDescriptor\n+\tif mergeTrigger := args.InternalCommitTrigger.GetMergeTrigger(); mergeTrigger != nil {\n+\t\t// If this is a merge, then use the post-merge descriptor to determine\n+\t\t// which intents are local (note that for a split, we want to use the\n+\t\t// pre-split one instead because it's larger).\n+\t\tpreMergeDesc = desc\n+\t\tdesc = &mergeTrigger.UpdatedDesc\n+\t}\n+\n+\titerAndBuf := engine.GetIterAndBuf(batch)\n+\tdefer iterAndBuf.Cleanup()\n+\n+\tvar externalIntents []roachpb.Intent\n+\tfor _, span := range args.IntentSpans {\n+\t\tif err := func() error {\n+\t\t\tintent := roachpb.Intent{Span: span, Txn: txn.TxnMeta, Status: txn.Status}\n+\t\t\tif len(span.EndKey) == 0 {\n+\t\t\t\t// For single-key intents, do a KeyAddress-aware check of\n+\t\t\t\t// whether it's contained in our Range.\n+\t\t\t\tif !containsKey(*desc, span.Key) {\n+\t\t\t\t\texternalIntents = append(externalIntents, intent)\n+\t\t\t\t\treturn nil\n+\t\t\t\t}\n+\t\t\t\tresolveMs := ms\n+\t\t\t\tif preMergeDesc != nil && !containsKey(*preMergeDesc, span.Key) {\n+\t\t\t\t\t// If this transaction included a merge and the intents\n+\t\t\t\t\t// are from the subsumed range, ignore the intent resolution\n+\t\t\t\t\t// stats, as they will already be accounted for during the\n+\t\t\t\t\t// merge trigger.\n+\t\t\t\t\tresolveMs = nil\n+\t\t\t\t}\n+\t\t\t\treturn engine.MVCCResolveWriteIntentUsingIter(batch, iterAndBuf, resolveMs, intent)\n+\t\t\t}\n+\t\t\t// For intent ranges, cut into parts inside and outside our key\n+\t\t\t// range. Resolve locally inside, delegate the rest. In particular,\n+\t\t\t// an intent range for range-local data is correctly considered local.\n+\t\t\tinSpan, outSpans := intersectSpan(span, *desc)\n+\t\t\tfor _, span := range outSpans {\n+\t\t\t\toutIntent := intent\n+\t\t\t\toutIntent.Span = span\n+\t\t\t\texternalIntents = append(externalIntents, outIntent)\n+\t\t\t}\n+\t\t\tif inSpan != nil {\n+\t\t\t\tintent.Span = *inSpan\n+\t\t\t\t_, err := engine.MVCCResolveWriteIntentRangeUsingIter(batch, iterAndBuf, ms, intent, 0)\n+\t\t\t\treturn err\n+\t\t\t}\n+\t\t\treturn nil\n+\t\t}(); err != nil {\n+\t\t\t// TODO(tschottdorf): any legitimate reason for this to happen?\n+\t\t\t// Figure that out and if not, should still be ReplicaCorruption\n+\t\t\t// and not a panic.\n+\t\t\tpanic(fmt.Sprintf(\"error resolving intent at %s on end transaction [%s]: %s\", span, txn.Status, err))\n+\t\t}\n+\t}\n+\n+\t// Persist the transaction record with updated status (& possibly timestamp).","path":"storage/replica_command.go","position":171,"original_position":171,"commit_id":"53644ae85b4e5547baa3cb135617117b0a6a9c9b","original_commit_id":"53644ae85b4e5547baa3cb135617117b0a6a9c9b","user":{"login":"tschottdorf","id":5076964,"avatar_url":"https://avatars.githubusercontent.com/u/5076964?v=3","gravatar_id":"","url":"https://api.github.com/users/tschottdorf","html_url":"https://github.com/tschottdorf","followers_url":"https://api.github.com/users/tschottdorf/followers","following_url":"https://api.github.com/users/tschottdorf/following{/other_user}","gists_url":"https://api.github.com/users/tschottdorf/gists{/gist_id}","starred_url":"https://api.github.com/users/tschottdorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tschottdorf/subscriptions","organizations_url":"https://api.github.com/users/tschottdorf/orgs","repos_url":"https://api.github.com/users/tschottdorf/repos","events_url":"https://api.github.com/users/tschottdorf/events{/privacy}","received_events_url":"https://api.github.com/users/tschottdorf/received_events","type":"User","site_admin":false},"body":"It's weird that everything that happens from here on down happens inside of this helper method. Auto-gc'ing can easily move outside. Writing an updated txn entry can maybe stay, but the method name needs to indicate that this is happening (and nobody can write another entry in `EndTransaction` after this one unless it reads the entry from disk first).","created_at":"2016-04-11T14:52:08Z","updated_at":"2016-04-11T14:52:08Z","html_url":"https://github.com/cockroachdb/cockroach/pull/5946#discussion_r59217970","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/5946","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/59217970"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/5946#discussion_r59217970"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/5946"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/5946","id":65792796,"html_url":"https://github.com/cockroachdb/cockroach/pull/5946","diff_url":"https://github.com/cockroachdb/cockroach/pull/5946.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/5946.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/5946","number":5946,"state":"closed","locked":false,"title":"storage: Resolve intents when encountering an aborted txn","user":{"login":"kkaneda","id":8353550,"avatar_url":"https://avatars.githubusercontent.com/u/8353550?v=3","gravatar_id":"","url":"https://api.github.com/users/kkaneda","html_url":"https://github.com/kkaneda","followers_url":"https://api.github.com/users/kkaneda/followers","following_url":"https://api.github.com/users/kkaneda/following{/other_user}","gists_url":"https://api.github.com/users/kkaneda/gists{/gist_id}","starred_url":"https://api.github.com/users/kkaneda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkaneda/subscriptions","organizations_url":"https://api.github.com/users/kkaneda/orgs","repos_url":"https://api.github.com/users/kkaneda/repos","events_url":"https://api.github.com/users/kkaneda/events{/privacy}","received_events_url":"https://api.github.com/users/kkaneda/received_events","type":"User","site_admin":false},"body":"This is a follow-up of #5885. Resolve local intents and update the transaction record when we attempt to roll back the transaction and find that it has already been aborted.\r\n\r\nDefine helper method 1resolveExplicitIntents` and call it.\n\n<!-- Reviewable:start -->\n---\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"35\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/cockroachdb/cockroach/5946)\n<!-- Reviewable:end -->\n","created_at":"2016-04-08T14:17:35Z","updated_at":"2016-04-11T14:52:08Z","closed_at":"2016-04-09T01:23:23Z","merged_at":"2016-04-09T01:23:23Z","merge_commit_sha":"4ac77075268a6957196217197742f6f8e98556fc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/5946/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/5946/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/5946/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/53644ae85b4e5547baa3cb135617117b0a6a9c9b","head":{"label":"cockroachdb:kaneda/resolve_intent_from_rollback","ref":"kaneda/resolve_intent_from_rollback","sha":"53644ae85b4e5547baa3cb135617117b0a6a9c9b","user":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"repo":{"id":16563587,"name":"cockroach","full_name":"cockroachdb/cockroach","owner":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cockroachdb/cockroach","description":"A Scalable, Survivable, Strongly-Consistent SQL Database","fork":false,"url":"https://api.github.com/repos/cockroachdb/cockroach","forks_url":"https://api.github.com/repos/cockroachdb/cockroach/forks","keys_url":"https://api.github.com/repos/cockroachdb/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cockroachdb/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cockroachdb/cockroach/teams","hooks_url":"https://api.github.com/repos/cockroachdb/cockroach/hooks","issue_events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/cockroachdb/cockroach/events","assignees_url":"https://api.github.com/repos/cockroachdb/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/cockroachdb/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/cockroachdb/cockroach/tags","blobs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cockroachdb/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/cockroachdb/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/cockroachdb/cockroach/languages","stargazers_url":"https://api.github.com/repos/cockroachdb/cockroach/stargazers","contributors_url":"https://api.github.com/repos/cockroachdb/cockroach/contributors","subscribers_url":"https://api.github.com/repos/cockroachdb/cockroach/subscribers","subscription_url":"https://api.github.com/repos/cockroachdb/cockroach/subscription","commits_url":"https://api.github.com/repos/cockroachdb/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/cockroachdb/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/cockroachdb/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/cockroachdb/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cockroachdb/cockroach/merges","archive_url":"https://api.github.com/repos/cockroachdb/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cockroachdb/cockroach/downloads","issues_url":"https://api.github.com/repos/cockroachdb/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/cockroachdb/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/cockroachdb/cockroach/releases{/id}","deployments_url":"https://api.github.com/repos/cockroachdb/cockroach/deployments","created_at":"2014-02-06T00:18:47Z","updated_at":"2016-04-11T08:19:06Z","pushed_at":"2016-04-11T14:41:13Z","git_url":"git://github.com/cockroachdb/cockroach.git","ssh_url":"git@github.com:cockroachdb/cockroach.git","clone_url":"https://github.com/cockroachdb/cockroach.git","svn_url":"https://github.com/cockroachdb/cockroach","homepage":"https://www.cockroachlabs.com","size":177933,"stargazers_count":6661,"watchers_count":6661,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":627,"mirror_url":null,"open_issues_count":380,"forks":627,"open_issues":380,"watchers":6661,"default_branch":"master"}},"base":{"label":"cockroachdb:master","ref":"master","sha":"2c321129d6534c9815d79ce420af22dd0b300f47","user":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"repo":{"id":16563587,"name":"cockroach","full_name":"cockroachdb/cockroach","owner":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cockroachdb/cockroach","description":"A Scalable, Survivable, Strongly-Consistent SQL Database","fork":false,"url":"https://api.github.com/repos/cockroachdb/cockroach","forks_url":"https://api.github.com/repos/cockroachdb/cockroach/forks","keys_url":"https://api.github.com/repos/cockroachdb/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cockroachdb/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cockroachdb/cockroach/teams","hooks_url":"https://api.github.com/repos/cockroachdb/cockroach/hooks","issue_events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/cockroachdb/cockroach/events","assignees_url":"https://api.github.com/repos/cockroachdb/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/cockroachdb/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/cockroachdb/cockroach/tags","blobs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cockroachdb/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/cockroachdb/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/cockroachdb/cockroach/languages","stargazers_url":"https://api.github.com/repos/cockroachdb/cockroach/stargazers","contributors_url":"https://api.github.com/repos/cockroachdb/cockroach/contributors","subscribers_url":"https://api.github.com/repos/cockroachdb/cockroach/subscribers","subscription_url":"https://api.github.com/repos/cockroachdb/cockroach/subscription","commits_url":"https://api.github.com/repos/cockroachdb/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/cockroachdb/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/cockroachdb/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/cockroachdb/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cockroachdb/cockroach/merges","archive_url":"https://api.github.com/repos/cockroachdb/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cockroachdb/cockroach/downloads","issues_url":"https://api.github.com/repos/cockroachdb/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/cockroachdb/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/cockroachdb/cockroach/releases{/id}","deployments_url":"https://api.github.com/repos/cockroachdb/cockroach/deployments","created_at":"2014-02-06T00:18:47Z","updated_at":"2016-04-11T08:19:06Z","pushed_at":"2016-04-11T14:41:13Z","git_url":"git://github.com/cockroachdb/cockroach.git","ssh_url":"git@github.com:cockroachdb/cockroach.git","clone_url":"https://github.com/cockroachdb/cockroach.git","svn_url":"https://github.com/cockroachdb/cockroach","homepage":"https://www.cockroachlabs.com","size":177933,"stargazers_count":6661,"watchers_count":6661,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":627,"mirror_url":null,"open_issues_count":380,"forks":627,"open_issues":380,"watchers":6661,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/5946"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/5946"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/5946"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/5946/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/5946/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/5946/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/53644ae85b4e5547baa3cb135617117b0a6a9c9b"}}}}