{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/72372121","id":72372121,"diff_hunk":"@@ -59,12 +57,88 @@ func NewBackoff(retry, base, cap, jitter int) func() error {\n \t\ttime.Sleep(time.Duration(sleep) * time.Millisecond)\n \n \t\tattempts++\n-\t\ttotalSleep += sleep\n \t\tlastSleep = sleep\n-\t\treturn nil\n+\t\treturn lastSleep\n \t}\n }\n \n func expo(base, cap, n int) int {\n \treturn int(math.Min(float64(cap), float64(base)*math.Pow(2.0, float64(n))))\n }\n+\n+type backoffType int\n+\n+const (\n+\tboTiKVRPC backoffType = iota\n+\tboTxnLock\n+\tboPDRPC\n+\tboRegionMiss\n+)\n+\n+func (t backoffType) createFn() func() int {\n+\tswitch t {\n+\tcase boTiKVRPC:\n+\t\treturn NewBackoffFn(100, 2000, EqualJitter)\n+\tcase boTxnLock:\n+\t\treturn NewBackoffFn(300, 3000, EqualJitter)\n+\tcase boPDRPC:\n+\t\treturn NewBackoffFn(500, 3000, EqualJitter)\n+\tcase boRegionMiss:\n+\t\treturn NewBackoffFn(100, 500, NoJitter)\n+\t}\n+\treturn nil\n+}\n+\n+const (\n+\tcopBuildTaskMaxBackoff = 3000\n+\tnewTxnMaxBackoff       = 3000\n+\tstoreVersionMaxBackoff = 3000\n+\tscannerNextMaxBackoff  = 3000\n+\tbatchGetMaxBackoff     = 10000\n+\tcopNextMaxBackoff      = 10000\n+\tgetMaxBackoff          = 10000\n+\tcommitMaxBackoff       = 15000\n+)\n+\n+// Backoff is a utility for retrying queries.\n+type Backoff struct {\n+\tmu         sync.Mutex\n+\tfn         map[backoffType]func() int\n+\tmaxSleep   int\n+\ttotalSleep int\n+\terrors     []string\n+}\n+\n+// NewBackoff creates a Backoff with maximum sleep time(in ms).\n+func NewBackoff(maxSleep int) *Backoff {\n+\treturn &Backoff{\n+\t\tmaxSleep: maxSleep,\n+\t}\n+}\n+\n+// Backoff sleeps a while base on the backoffType and records the error message.\n+// It returns an retryable error if total sleep time exceeds maxSleep.","path":"store/tikv/backoff.go","position":99,"original_position":99,"commit_id":"381b144f5ab0b0d13f743b0f20dfc3b6f36d9e0e","original_commit_id":"381b144f5ab0b0d13f743b0f20dfc3b6f36d9e0e","user":{"login":"zimulala","id":4242506,"avatar_url":"https://avatars.githubusercontent.com/u/4242506?v=3","gravatar_id":"","url":"https://api.github.com/users/zimulala","html_url":"https://github.com/zimulala","followers_url":"https://api.github.com/users/zimulala/followers","following_url":"https://api.github.com/users/zimulala/following{/other_user}","gists_url":"https://api.github.com/users/zimulala/gists{/gist_id}","starred_url":"https://api.github.com/users/zimulala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zimulala/subscriptions","organizations_url":"https://api.github.com/users/zimulala/orgs","repos_url":"https://api.github.com/users/zimulala/repos","events_url":"https://api.github.com/users/zimulala/events{/privacy}","received_events_url":"https://api.github.com/users/zimulala/received_events","type":"User","site_admin":false},"body":"an -> a ?","created_at":"2016-07-27T02:30:51Z","updated_at":"2016-07-27T02:30:51Z","html_url":"https://github.com/pingcap/tidb/pull/1506#discussion_r72372121","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/1506","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/72372121"},"html":{"href":"https://github.com/pingcap/tidb/pull/1506#discussion_r72372121"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1506"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/1506","id":78839482,"html_url":"https://github.com/pingcap/tidb/pull/1506","diff_url":"https://github.com/pingcap/tidb/pull/1506.diff","patch_url":"https://github.com/pingcap/tidb/pull/1506.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/1506","number":1506,"state":"open","locked":false,"title":"store/tikv: udpate backoff.","user":{"login":"disksing","id":12077877,"avatar_url":"https://avatars.githubusercontent.com/u/12077877?v=3","gravatar_id":"","url":"https://api.github.com/users/disksing","html_url":"https://github.com/disksing","followers_url":"https://api.github.com/users/disksing/followers","following_url":"https://api.github.com/users/disksing/following{/other_user}","gists_url":"https://api.github.com/users/disksing/gists{/gist_id}","starred_url":"https://api.github.com/users/disksing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/disksing/subscriptions","organizations_url":"https://api.github.com/users/disksing/orgs","repos_url":"https://api.github.com/users/disksing/repos","events_url":"https://api.github.com/users/disksing/events{/privacy}","received_events_url":"https://api.github.com/users/disksing/received_events","type":"User","site_admin":false},"body":"This PR contains a new approach to do retry. A `Backoff` struct is created with each kv API call, the struct will track every retryable error occurs within the call and throw an error if total sleep time exceeds limit. \r\n\r\n@shenli @zimulala @coocood ","created_at":"2016-07-26T12:03:54Z","updated_at":"2016-07-27T02:30:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cbf6466157a04b1bcca2953b1d49a03ad8a378b6","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/1506/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/1506/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/1506/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/381b144f5ab0b0d13f743b0f20dfc3b6f36d9e0e","head":{"label":"pingcap:disksing/update-backoff","ref":"disksing/update-backoff","sha":"381b144f5ab0b0d13f743b0f20dfc3b6f36d9e0e","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":41986369,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tidb","description":"TiDB is a distributed NewSQL database compatible with MySQL protocol ","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tidb/deployments","created_at":"2015-09-06T04:01:52Z","updated_at":"2016-07-26T21:22:49Z","pushed_at":"2016-07-27T02:30:11Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":21700,"stargazers_count":4353,"watchers_count":4353,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":548,"mirror_url":null,"open_issues_count":104,"forks":548,"open_issues":104,"watchers":4353,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"04da3d2f8b02bcb2b8184f6e25063cd9bd92e8e4","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":41986369,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tidb","description":"TiDB is a distributed NewSQL database compatible with MySQL protocol ","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tidb/deployments","created_at":"2015-09-06T04:01:52Z","updated_at":"2016-07-26T21:22:49Z","pushed_at":"2016-07-27T02:30:11Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":21700,"stargazers_count":4353,"watchers_count":4353,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":548,"mirror_url":null,"open_issues_count":104,"forks":548,"open_issues":104,"watchers":4353,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1506"},"html":{"href":"https://github.com/pingcap/tidb/pull/1506"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/1506"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/1506/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1506/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1506/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/381b144f5ab0b0d13f743b0f20dfc3b6f36d9e0e"}}}}
{"actor":{"display_login":"zimulala"}}