{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/31562297","id":31562297,"diff_hunk":"@@ -1271,33 +1280,78 @@ func (s *Store) resolveWriteIntentError(ctx context.Context, wiErr *proto.WriteI\n \t\t\tRangeLookup: args.Method() == proto.InternalRangeLookup,\n \t\t}\n \t\tbArgs.Add(pushArgs)\n+\t\tpushReply := &proto.InternalPushTxnResponse{}\n+\n+\t\t// Check the txn cache first.\n+\t\tif s.pushedTxnCache.processPushedTxn(pushArgs, pushReply) {\n+\n+\t\t\tcachedPushTxns = append(cachedPushTxns, &cachedPushTxn{\n+\t\t\t\tkey:   intent.Key,\n+\t\t\t\treply: pushReply,\n+\t\t\t})\n+\n+\t\t} else {\n+\t\t\tbArgs.Add(pushArgs)\n+\t\t\tneedPushIntents = append(needPushIntents, intent)\n+\t\t}\n+\n \t}\n \tb := &client.Batch{}\n \tb.InternalAddCall(client.Call{Args: bArgs, Reply: bReply})\n \n-\t// Run all pushes in parallel.\n-\tif pushErr := s.kvDB.Run(b); pushErr != nil {\n-\t\tif log.V(1) {\n-\t\t\tlog.Infoc(ctx, \"push for write intent %s failed: %s\", wiErr, pushErr)\n-\t\t}\n+\tif len(needPushIntents) != 0 {\n+\t\tb := &client.Batch{}\n+\t\tb.InternalAddCall(client.Call{Args: bArgs, Reply: bReply})\n \n-\t\t// For write/write conflicts within a transaction, propagate the\n-\t\t// push failure, not the original write intent error. The push\n-\t\t// failure will instruct the client to restart the transaction\n-\t\t// with a backoff.\n-\t\tif args.Header().Txn != nil && proto.IsWrite(args) {\n-\t\t\treturn pushErr\n+\t\t// Run all pushes in parallel.\n+\t\tif pushErr := s.kvDB.Run(b); pushErr != nil {\n+\t\t\tif log.V(1) {\n+\t\t\t\tlog.Infoc(ctx, \"push for write intent %s failed: %s\", wiErr, pushErr)\n+\t\t\t}\n+\n+\t\t\t// For write/write conflicts within a transaction, propagate the\n+\t\t\t// push failure, not the original write intent error. The push\n+\t\t\t// failure will instruct the client to restart the transaction\n+\t\t\t// with a backoff.\n+\t\t\tif args.Header().Txn != nil && proto.IsWrite(args) {\n+\t\t\t\treturn pushErr\n+\t\t\t}\n+\t\t\t// For read/write conflicts, return the write intent error which\n+\t\t\t// engages backoff/retry (with !Resolved). We don't need to\n+\t\t\t// restart the txn, only resend the read with a backoff.\n+\t\t\treturn wiErr\n \t\t}\n-\t\t// For read/write conflicts, return the write intent error which\n-\t\t// engages backoff/retry (with !Resolved). We don't need to\n-\t\t// restart the txn, only resend the read with a backoff.\n-\t\treturn wiErr\n \t}\n \twiErr.Resolved = true // success!\n \n \t// We pushed the transaction(s) successfully, so resolve the intent(s).\n-\tfor i, intent := range wiErr.Intents {\n+\tfor i, cache := range cachedPushTxns {","path":"storage/store.go","position":107,"original_position":107,"commit_id":"5f519650574e284069f45ea2bcf63987410e98a8","original_commit_id":"5f519650574e284069f45ea2bcf63987410e98a8","user":{"login":"bdarnell","id":160562,"avatar_url":"https://avatars.githubusercontent.com/u/160562?v=3","gravatar_id":"","url":"https://api.github.com/users/bdarnell","html_url":"https://github.com/bdarnell","followers_url":"https://api.github.com/users/bdarnell/followers","following_url":"https://api.github.com/users/bdarnell/following{/other_user}","gists_url":"https://api.github.com/users/bdarnell/gists{/gist_id}","starred_url":"https://api.github.com/users/bdarnell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdarnell/subscriptions","organizations_url":"https://api.github.com/users/bdarnell/orgs","repos_url":"https://api.github.com/users/bdarnell/repos","events_url":"https://api.github.com/users/bdarnell/events{/privacy}","received_events_url":"https://api.github.com/users/bdarnell/received_events","type":"User","site_admin":false},"body":"This loop and the next one are nearly identical. Can we combine them somehow? Maybe process `needPushIntents` first, updating the cache and `cachedPushTxns`, then issue all the resolve intent calls based on `cachedPushTxns`.","created_at":"2015-06-02T19:40:07Z","updated_at":"2015-06-02T19:40:07Z","html_url":"https://github.com/cockroachdb/cockroach/pull/1041#discussion_r31562297","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1041","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/31562297"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/1041#discussion_r31562297"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1041"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1041","id":35515194,"html_url":"https://github.com/cockroachdb/cockroach/pull/1041","diff_url":"https://github.com/cockroachdb/cockroach/pull/1041.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/1041.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/1041","number":1041,"state":"open","locked":false,"title":"Keep a cache of pushed transactions on the store","user":{"login":"yananzhi","id":11538969,"avatar_url":"https://avatars.githubusercontent.com/u/11538969?v=3","gravatar_id":"","url":"https://api.github.com/users/yananzhi","html_url":"https://github.com/yananzhi","followers_url":"https://api.github.com/users/yananzhi/followers","following_url":"https://api.github.com/users/yananzhi/following{/other_user}","gists_url":"https://api.github.com/users/yananzhi/gists{/gist_id}","starred_url":"https://api.github.com/users/yananzhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yananzhi/subscriptions","organizations_url":"https://api.github.com/users/yananzhi/orgs","repos_url":"https://api.github.com/users/yananzhi/repos","events_url":"https://api.github.com/users/yananzhi/events{/privacy}","received_events_url":"https://api.github.com/users/yananzhi/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-15T13:58:38Z","updated_at":"2015-06-02T19:40:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"50a9cc5e584bba7eca2b324010d58778355616e5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1041/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1041/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/1041/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/5f519650574e284069f45ea2bcf63987410e98a8","head":{"label":"yananzhi:push_txn_cache","ref":"push_txn_cache","sha":"5f519650574e284069f45ea2bcf63987410e98a8","user":{"login":"yananzhi","id":11538969,"avatar_url":"https://avatars.githubusercontent.com/u/11538969?v=3","gravatar_id":"","url":"https://api.github.com/users/yananzhi","html_url":"https://github.com/yananzhi","followers_url":"https://api.github.com/users/yananzhi/followers","following_url":"https://api.github.com/users/yananzhi/following{/other_user}","gists_url":"https://api.github.com/users/yananzhi/gists{/gist_id}","starred_url":"https://api.github.com/users/yananzhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yananzhi/subscriptions","organizations_url":"https://api.github.com/users/yananzhi/orgs","repos_url":"https://api.github.com/users/yananzhi/repos","events_url":"https://api.github.com/users/yananzhi/events{/privacy}","received_events_url":"https://api.github.com/users/yananzhi/received_events","type":"User","site_admin":false},"repo":{"id":34190198,"name":"cockroach","full_name":"yananzhi/cockroach","owner":{"login":"yananzhi","id":11538969,"avatar_url":"https://avatars.githubusercontent.com/u/11538969?v=3","gravatar_id":"","url":"https://api.github.com/users/yananzhi","html_url":"https://github.com/yananzhi","followers_url":"https://api.github.com/users/yananzhi/followers","following_url":"https://api.github.com/users/yananzhi/following{/other_user}","gists_url":"https://api.github.com/users/yananzhi/gists{/gist_id}","starred_url":"https://api.github.com/users/yananzhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yananzhi/subscriptions","organizations_url":"https://api.github.com/users/yananzhi/orgs","repos_url":"https://api.github.com/users/yananzhi/repos","events_url":"https://api.github.com/users/yananzhi/events{/privacy}","received_events_url":"https://api.github.com/users/yananzhi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yananzhi/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":true,"url":"https://api.github.com/repos/yananzhi/cockroach","forks_url":"https://api.github.com/repos/yananzhi/cockroach/forks","keys_url":"https://api.github.com/repos/yananzhi/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yananzhi/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yananzhi/cockroach/teams","hooks_url":"https://api.github.com/repos/yananzhi/cockroach/hooks","issue_events_url":"https://api.github.com/repos/yananzhi/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/yananzhi/cockroach/events","assignees_url":"https://api.github.com/repos/yananzhi/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/yananzhi/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/yananzhi/cockroach/tags","blobs_url":"https://api.github.com/repos/yananzhi/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yananzhi/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yananzhi/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/yananzhi/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yananzhi/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/yananzhi/cockroach/languages","stargazers_url":"https://api.github.com/repos/yananzhi/cockroach/stargazers","contributors_url":"https://api.github.com/repos/yananzhi/cockroach/contributors","subscribers_url":"https://api.github.com/repos/yananzhi/cockroach/subscribers","subscription_url":"https://api.github.com/repos/yananzhi/cockroach/subscription","commits_url":"https://api.github.com/repos/yananzhi/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/yananzhi/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/yananzhi/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/yananzhi/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/yananzhi/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/yananzhi/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yananzhi/cockroach/merges","archive_url":"https://api.github.com/repos/yananzhi/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yananzhi/cockroach/downloads","issues_url":"https://api.github.com/repos/yananzhi/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/yananzhi/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/yananzhi/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/yananzhi/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yananzhi/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/yananzhi/cockroach/releases{/id}","created_at":"2015-04-19T02:08:47Z","updated_at":"2015-05-01T02:36:15Z","pushed_at":"2015-05-31T11:27:49Z","git_url":"git://github.com/yananzhi/cockroach.git","ssh_url":"git@github.com:yananzhi/cockroach.git","clone_url":"https://github.com/yananzhi/cockroach.git","svn_url":"https://github.com/yananzhi/cockroach","homepage":null,"size":19194,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"cockroachdb:master","ref":"master","sha":"3b31223d98260fea970e48a68b472b5f6c5bace9","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, Geo-Replicated, Transactional Datastore","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}","created_at":"2014-02-06T00:18:47Z","updated_at":"2015-06-02T19:36:00Z","pushed_at":"2015-06-02T19:06:05Z","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":null,"size":42027,"stargazers_count":3476,"watchers_count":3476,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":278,"mirror_url":null,"open_issues_count":76,"forks":278,"open_issues":76,"watchers":3476,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1041"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/1041"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/1041"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/1041/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1041/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/1041/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/5f519650574e284069f45ea2bcf63987410e98a8"}}}}