{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/37761102","id":37761102,"diff_hunk":"@@ -227,3 +229,96 @@ func TestInsecure(t *testing.T) {\n \t\tt.Fatal(err)\n \t}\n }\n+\n+// Start a transaction to update a row. After updating the row and\n+// before committing the transaction, start another transaction in\n+// another thread to update the same row. The other transaction succeeds,\n+// resulting in the first transaction failing.\n+func TestOverlappingTransactions(t *testing.T) {\n+\tdefer leaktest.AfterTest(t)\n+\ts, db := setup(t)\n+\tdefer cleanup(s, db)\n+\n+\t// Prepare DB\n+\tif _, err := db.Exec(`CREATE DATABASE t`); err != nil {\n+\t\tt.Fatal(err)\n+\t}\n+\tif _, err := db.Exec(`CREATE TABLE t.kv (k CHAR PRIMARY KEY, v char)`); err != nil {\n+\t\tt.Fatal(err)\n+\t}\n+\tif _, err := db.Exec(`INSERT INTO t.kv VALUES ($1, $2)`, \"a\", \"b\"); err != nil {\n+\t\tt.Fatal(err)\n+\t}\n+\n+\t// Start first transaction\n+\ttxn, err := db.Begin()\n+\tif err != nil {\n+\t\tt.Fatal(err)\n+\t}\n+\tif _, err := txn.Exec(`UPDATE t.kv SET v = $2 WHERE k IN ($1)`, \"a\", \"c\"); err != nil {\n+\t\tt.Fatal(err)\n+\t}\n+\n+\tvar wg sync.WaitGroup\n+\twg.Add(1)\n+\t// Run another transaction in parallel that succeeds.\n+\tgo func() {\n+\t\ttxn2, err := db.Begin()\n+\t\tif err != nil {\n+\t\t\tt.Fatal(err)\n+\t\t}\n+\t\tif rows, err := txn2.Query(`SELECT v FROM t.kv WHERE k IN ($1)`, \"a\"); err != nil {\n+\t\t\tt.Fatal(err)\n+\t\t} else {\n+\t\t\tresults := readAll(t, rows)\n+\t\t\texpectedResults := asResultSlice([][]string{\n+\t\t\t\t{\"v\"},\n+\t\t\t\t{\"b\"},\n+\t\t\t})\n+\t\t\tif err := verifyResults(expectedResults, results); err != nil {\n+\t\t\t\tt.Fatal(err)\n+\t\t\t}\n+\t\t}\n+\t\tif _, err := txn2.Exec(`UPDATE t.kv SET v = $2 WHERE k IN ($1)`, \"a\", \"d\"); err != nil {\n+\t\t\tlog.Fatal(err)\n+\t\t}\n+\t\tif err := txn2.Commit(); err != nil {\n+\t\t\tlog.Fatal(err)\n+\t\t}\n+\t\twg.Done()\n+\t}()\n+\t// Wait for the other transaction to complete.\n+\twg.Wait()\n+\n+\tif rows, err := txn.Query(`SELECT v FROM t.kv WHERE k IN ($1)`, \"a\"); err != nil {\n+\t\tlog.Fatal(err)\n+\t} else {\n+\t\tresults := readAll(t, rows)\n+\t\t// The first update is not visible!","path":"sql/driver/driver_test.go","position":null,"original_position":83,"commit_id":"0b6363806834638019fdaa45e03211fb651a7543","original_commit_id":"fbc883eebf28bcd9c1eef7b8444679e4ded81b21","user":{"login":"vivekmenezes","id":11774212,"avatar_url":"https://avatars.githubusercontent.com/u/11774212?v=3","gravatar_id":"","url":"https://api.github.com/users/vivekmenezes","html_url":"https://github.com/vivekmenezes","followers_url":"https://api.github.com/users/vivekmenezes/followers","following_url":"https://api.github.com/users/vivekmenezes/following{/other_user}","gists_url":"https://api.github.com/users/vivekmenezes/gists{/gist_id}","starred_url":"https://api.github.com/users/vivekmenezes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vivekmenezes/subscriptions","organizations_url":"https://api.github.com/users/vivekmenezes/orgs","repos_url":"https://api.github.com/users/vivekmenezes/repos","events_url":"https://api.github.com/users/vivekmenezes/events{/privacy}","received_events_url":"https://api.github.com/users/vivekmenezes/received_events","type":"User","site_admin":false},"body":"See \"Writer encounters uncommitted write intent\" in https://github.com/cockroachdb/cockroach/blob/master/docs/design.md\r\n\r\nThe second writer upgrades its priority and then succeeds marking the first transaction as aborted.","created_at":"2015-08-24T15:05:44Z","updated_at":"2015-08-24T15:05:44Z","html_url":"https://github.com/cockroachdb/cockroach/pull/2049#discussion_r37761102","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2049","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/37761102"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2049#discussion_r37761102"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2049"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2049","id":42090731,"html_url":"https://github.com/cockroachdb/cockroach/pull/2049","diff_url":"https://github.com/cockroachdb/cockroach/pull/2049.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/2049.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2049","number":2049,"state":"open","locked":false,"title":"Add support for multi-statement transactions.","user":{"login":"vivekmenezes","id":11774212,"avatar_url":"https://avatars.githubusercontent.com/u/11774212?v=3","gravatar_id":"","url":"https://api.github.com/users/vivekmenezes","html_url":"https://github.com/vivekmenezes","followers_url":"https://api.github.com/users/vivekmenezes/followers","following_url":"https://api.github.com/users/vivekmenezes/following{/other_user}","gists_url":"https://api.github.com/users/vivekmenezes/gists{/gist_id}","starred_url":"https://api.github.com/users/vivekmenezes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vivekmenezes/subscriptions","organizations_url":"https://api.github.com/users/vivekmenezes/orgs","repos_url":"https://api.github.com/users/vivekmenezes/repos","events_url":"https://api.github.com/users/vivekmenezes/events{/privacy}","received_events_url":"https://api.github.com/users/vivekmenezes/received_events","type":"User","site_admin":false},"body":"for subsequent operations.\r\n\r\nImplement COMMIT and ROLLBACK transaction.\r\nImplement implicit BEGIN transaction.","created_at":"2015-08-11T04:00:45Z","updated_at":"2015-08-24T15:05:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9928071aed8563436b5f7cfef5c5d354651065a1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2049/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2049/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2049/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/0b6363806834638019fdaa45e03211fb651a7543","head":{"label":"cockroachdb:vivek/trans","ref":"vivek/trans","sha":"0b6363806834638019fdaa45e03211fb651a7543","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-08-24T11:06:07Z","pushed_at":"2015-08-24T15:04:21Z","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":50394,"stargazers_count":5038,"watchers_count":5038,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":397,"mirror_url":null,"open_issues_count":153,"forks":397,"open_issues":153,"watchers":5038,"default_branch":"master"}},"base":{"label":"cockroachdb:master","ref":"master","sha":"eb808e5762758981f33e45b030194453cb44f01d","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-08-24T11:06:07Z","pushed_at":"2015-08-24T15:04:21Z","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":50394,"stargazers_count":5038,"watchers_count":5038,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":397,"mirror_url":null,"open_issues_count":153,"forks":397,"open_issues":153,"watchers":5038,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2049"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2049"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2049"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2049/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2049/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2049/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/0b6363806834638019fdaa45e03211fb651a7543"}}}}