{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/29543499","id":29543499,"diff_hunk":"@@ -93,18 +96,84 @@ func (bank *Bank) moveMoney(from, to []byte, amount int64) bool {\n \t\t\treturn errRead\n \t\t}\n \t\t// Update both accounts.\n-\t\ttxn.Prepare(client.Put(proto.Key(from), []byte(fmt.Sprintf(\"%d\", fromValue-amount))))\n-\t\ttxn.Prepare(client.Put(proto.Key(to), []byte(fmt.Sprintf(\"%d\", toValue+amount))))\n+\t\ttxn.Prepare(client.Put(proto.Key(from), []byte(fmt.Sprintf(\"%d\", fromValue-amount))),\n+\t\t\tclient.Put(proto.Key(to), []byte(fmt.Sprintf(\"%d\", toValue+amount))))\n \t\treturn nil\n \t})\n \tif err != nil {\n \t\tlog.Fatal(err)\n \t}\n-\tatomic.AddInt32(&bank.numTransactions, 1)\n+\tatomic.AddInt32(&bank.numTransfers, 1)\n+\treturn true\n+}\n+\n+// moveMoneyWithoutTransaction() moves an amount between two accounts without the\n+// use of a transaction, if the amount is available in the from account.\n+// Returns true on success.\n+func (bank *Bank) moveMoney(from, to []byte, amount int64) bool {\n+\t// Early exit when from == to\n+\tif bytes.Compare(from, to) == 0 {\n+\t\treturn true\n+\t}\n+\tfromGet := client.Get(proto.Key(from))\n+\ttoGet := client.Get(proto.Key(to))\n+\tif err := bank.kvClient.Run(fromGet, toGet); err != nil {\n+\t\tlog.Fatal(err)\n+\t\treturn false\n+\t}\n+\t// Read from value.\n+\tfromValue, err := readInt64(fromGet)\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t\treturn false\n+\t}\n+\t// Ensure there is enough cash.\n+\tif fromValue < amount {\n+\t\treturn false\n+\t}\n+\t// Read to value.\n+\ttoValue, errRead := readInt64(toGet)\n+\tif errRead != nil {\n+\t\tlog.Fatal(errRead)\n+\t\treturn false\n+\t}\n+\t// Update both accounts.\n+\tbank.kvClient.Run(client.Put(proto.Key(from), []byte(fmt.Sprintf(\"%d\", fromValue-amount))),\n+\t\tclient.Put(proto.Key(to), []byte(fmt.Sprintf(\"%d\", toValue+amount))))\n+\tatomic.AddInt32(&bank.numTransfers, 1)\n \treturn true\n }\n \n // Read the balances in all the accounts and return them.\n+func (bank *Bank) readAllAccountsWithScan() []int64 {\n+\tbalances := make([]int64, bank.numAccounts)\n+\ttxnOpts := &client.TransactionOptions{Name: \"Reading all balances\"}\n+\terr := bank.kvClient.RunTransaction(txnOpts, func(txn *client.Txn) error {\n+\t\tcall := client.Scan(proto.Key(makeAccountID(0)), proto.Key(makeAccountID(bank.numAccounts)), int64(bank.numAccounts))\n+\t\tif err := txn.Run(call); err != nil {\n+\t\t\tlog.Fatal(err)\n+\t\t}\n+\t\t// Copy responses into balances.\n+\t\tscan := call.Reply.(*proto.ScanResponse)\n+\t\tif len(scan.Rows) != bank.numAccounts {\n+\t\t\tlog.Fatal(fmt.Errorf(\"Could only read %d of %d rows of the database.\\n\", len(scan.Rows), bank.numAccounts))","path":"examples/bank/bank.go","position":110,"original_position":110,"commit_id":"adc26257cc7bc8a523fe215c04760b31af09b212","original_commit_id":"adc26257cc7bc8a523fe215c04760b31af09b212","user":{"login":"petermattis","id":6201335,"avatar_url":"https://avatars.githubusercontent.com/u/6201335?v=3","gravatar_id":"","url":"https://api.github.com/users/petermattis","html_url":"https://github.com/petermattis","followers_url":"https://api.github.com/users/petermattis/followers","following_url":"https://api.github.com/users/petermattis/following{/other_user}","gists_url":"https://api.github.com/users/petermattis/gists{/gist_id}","starred_url":"https://api.github.com/users/petermattis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermattis/subscriptions","organizations_url":"https://api.github.com/users/petermattis/orgs","repos_url":"https://api.github.com/users/petermattis/repos","events_url":"https://api.github.com/users/petermattis/events{/privacy}","received_events_url":"https://api.github.com/users/petermattis/received_events","type":"User","site_admin":false},"body":"It's a bit strange to generate an error (`fmt.Errorf`) only to log it. Better to just use `log.Fatalf`.","created_at":"2015-05-02T01:12:09Z","updated_at":"2015-05-02T01:12:09Z","html_url":"https://github.com/cockroachdb/cockroach/pull/881#discussion_r29543499","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/881","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/29543499"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/881#discussion_r29543499"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/881"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/881","id":34551470,"html_url":"https://github.com/cockroachdb/cockroach/pull/881","diff_url":"https://github.com/cockroachdb/cockroach/pull/881.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/881.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/881","number":881,"state":"open","locked":false,"title":"Vivek/banktransfer","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":"@petermattis I've added in a flag to disable the use of a transaction in the account transfers.\r\n\r\nI also tried to change the readAllAccounts implementation to use a Scan() but it surprisingly didn't work. Doesn't the Scan() read the database at a timestamp?","created_at":"2015-05-01T17:21:44Z","updated_at":"2015-05-02T01:12:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d1380255a1c1afa15fbe0ffad170a305668219d0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/881/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/881/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/881/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/adc26257cc7bc8a523fe215c04760b31af09b212","head":{"label":"cockroachdb:vivek/banktransfer","ref":"vivek/banktransfer","sha":"adc26257cc7bc8a523fe215c04760b31af09b212","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-05-02T01:09:57Z","pushed_at":"2015-05-02T01:09:57Z","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":30179,"stargazers_count":3359,"watchers_count":3359,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":261,"mirror_url":null,"open_issues_count":63,"forks":261,"open_issues":63,"watchers":3359,"default_branch":"master"}},"base":{"label":"cockroachdb:master","ref":"master","sha":"4bcff675a17e2c768e257580522ded5b33883da0","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-05-02T01:09:57Z","pushed_at":"2015-05-02T01:09:57Z","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":30179,"stargazers_count":3359,"watchers_count":3359,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":261,"mirror_url":null,"open_issues_count":63,"forks":261,"open_issues":63,"watchers":3359,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/881"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/881"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/881"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/881/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/881/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/881/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/adc26257cc7bc8a523fe215c04760b31af09b212"}}}}