{"action":"created","comment":{"url":"https://api.github.com/repos/coreos/etcd/pulls/comments/61517513","id":61517513,"diff_hunk":"@@ -0,0 +1,191 @@\n+// Copyright 2016 CoreOS, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+package main\n+\n+import (\n+\t\"flag\"\n+\t\"fmt\"\n+\t\"log\"\n+\t\"math/rand\"\n+\t\"os\"\n+\t\"strings\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\t\"google.golang.org/grpc\"\n+\t\"google.golang.org/grpc/codes\"\n+\n+\t\"github.com/coreos/etcd/clientv3\"\n+\t\"github.com/coreos/etcd/clientv3/concurrency\"\n+\t\"golang.org/x/net/context\"\n+)\n+\n+func main() {\n+\tlog.SetFlags(log.Lmicroseconds)\n+\n+\tendpointStr := flag.String(\"endpoints\", \"localhost:2379\", \"endpoints of etcd cluster\")\n+\tmode := flag.String(\"mode\", \"lock-racer\", \"test mode (lock-racer)\")\n+\tround := flag.Int(\"rounds\", 100, \"number of rounds to run\")\n+\tflag.Parse()\n+\teps := strings.Split(*endpointStr, \",\")\n+\n+\tswitch *mode {\n+\tcase \"lock-racer\":\n+\t\trunRacer(eps, *round)\n+\tcase \"lease-renewer\":\n+\t\trunLeaseRenewer(eps)\n+\tdefault:\n+\t\tfmt.Fprintf(os.Stderr, \"unsupported mode %v\\n\", *mode)\n+\t}\n+}\n+\n+func runLeaseRenewer(eps []string) {\n+\tc := randClient(eps)\n+\tctx := context.Background()\n+\n+\tfor {\n+\t\tvar (\n+\t\t\tl   *clientv3.LeaseGrantResponse\n+\t\t\tlk  *clientv3.LeaseKeepAliveResponse\n+\t\t\terr error\n+\t\t)\n+\t\tfor {\n+\t\t\tl, err = c.Lease.Grant(ctx, 5)\n+\t\t\tif err == nil {\n+\t\t\t\tfmt.Printf(\"grant lease %d\\n\", l.ID)\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t\tfmt.Println(\"grant err\", err)\n+\t\t}\n+\t\texpire := time.Now().Add(time.Duration(l.TTL-1) * time.Second)\n+\n+\t\tfor {\n+\t\t\tlog.Printf(\"about to renew lease\")\n+\t\t\tlk, err = c.Lease.KeepAliveOnce(ctx, l.ID)\n+\t\t\tif grpc.Code(err) == codes.NotFound {\n+\t\t\t\tif time.Now().Sub(expire) < 0 {\n+\t\t\t\t\tlog.Printf(\"bad renew! exceeded: %v\", time.Now().Sub(expire))\n+\t\t\t\t\tfor {\n+\t\t\t\t\t\tlk, err = c.Lease.KeepAliveOnce(ctx, l.ID)\n+\t\t\t\t\t\tfmt.Println(lk, err)\n+\t\t\t\t\t\ttime.Sleep(time.Second)\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t\tlog.Printf(\"lost lease %d, expire: %v\\n\", l.ID, expire)\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t\tif err != nil {\n+\t\t\t\tfmt.Println(\"renew err\", err)\n+\t\t\t\tcontinue\n+\t\t\t}\n+\t\t\texpire = time.Now().Add(time.Duration(lk.TTL-1) * time.Second)\n+\t\t\tlog.Printf(\"renewed lease %d, expire: %v\\n\", lk.ID, expire)\n+\t\t\ttime.Sleep(time.Duration(lk.TTL-2) * time.Second)\n+\t\t}\n+\t}\n+}\n+\n+func runRacer(eps []string, round int) {\n+\tnrace := 15\n+\tprefix := \"racers\"\n+\tracers := make([]*concurrency.Mutex, nrace)\n+\tprogress := make([]int, nrace)\n+\tfinished := make(chan struct{}, 0)\n+\n+\tvar (\n+\t\tmu  sync.Mutex\n+\t\tcnt int\n+\t)\n+\tctx := context.Background()\n+\n+\tvar wg sync.WaitGroup\n+\n+\tfor i := range racers {\n+\t\tracers[i] = concurrency.NewMutex(randClient(eps), prefix)","path":"tools/functional-tester/etcd-runner/main.go","position":116,"original_position":116,"commit_id":"281246c2d82d916f6e3d1878fdf2c7623a888e86","original_commit_id":"b9953ddf926cd4d900af3c3a337532883e7189b5","user":{"login":"xiang90","id":4479947,"avatar_url":"https://avatars.githubusercontent.com/u/4479947?v=3","gravatar_id":"","url":"https://api.github.com/users/xiang90","html_url":"https://github.com/xiang90","followers_url":"https://api.github.com/users/xiang90/followers","following_url":"https://api.github.com/users/xiang90/following{/other_user}","gists_url":"https://api.github.com/users/xiang90/gists{/gist_id}","starred_url":"https://api.github.com/users/xiang90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiang90/subscriptions","organizations_url":"https://api.github.com/users/xiang90/orgs","repos_url":"https://api.github.com/users/xiang90/repos","events_url":"https://api.github.com/users/xiang90/events{/privacy}","received_events_url":"https://api.github.com/users/xiang90/received_events","type":"User","site_admin":false},"body":"i think it is not? We are creating N racers and each racer should have its own client, right?","created_at":"2016-04-28T23:16:00Z","updated_at":"2016-04-28T23:16:00Z","html_url":"https://github.com/coreos/etcd/pull/5171#discussion_r61517513","pull_request_url":"https://api.github.com/repos/coreos/etcd/pulls/5171","_links":{"self":{"href":"https://api.github.com/repos/coreos/etcd/pulls/comments/61517513"},"html":{"href":"https://github.com/coreos/etcd/pull/5171#discussion_r61517513"},"pull_request":{"href":"https://api.github.com/repos/coreos/etcd/pulls/5171"}}},"pull_request":{"url":"https://api.github.com/repos/coreos/etcd/pulls/5171","id":67597736,"html_url":"https://github.com/coreos/etcd/pull/5171","diff_url":"https://github.com/coreos/etcd/pull/5171.diff","patch_url":"https://github.com/coreos/etcd/pull/5171.patch","issue_url":"https://api.github.com/repos/coreos/etcd/issues/5171","number":5171,"state":"open","locked":false,"title":"etcd-runner: initial commit","user":{"login":"xiang90","id":4479947,"avatar_url":"https://avatars.githubusercontent.com/u/4479947?v=3","gravatar_id":"","url":"https://api.github.com/users/xiang90","html_url":"https://github.com/xiang90","followers_url":"https://api.github.com/users/xiang90/followers","following_url":"https://api.github.com/users/xiang90/following{/other_user}","gists_url":"https://api.github.com/users/xiang90/gists{/gist_id}","starred_url":"https://api.github.com/users/xiang90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiang90/subscriptions","organizations_url":"https://api.github.com/users/xiang90/orgs","repos_url":"https://api.github.com/users/xiang90/repos","events_url":"https://api.github.com/users/xiang90/events{/privacy}","received_events_url":"https://api.github.com/users/xiang90/received_events","type":"User","site_admin":false},"body":"/cc @heyitsanthony @gyuho \r\n\r\nWe plan to run this against a no consistency checking failure injection cluster. Interesting!","created_at":"2016-04-23T06:01:40Z","updated_at":"2016-04-28T23:16:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b6ac2a1f2da45457628cf11bdee36c900443c80f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/coreos/etcd/pulls/5171/commits","review_comments_url":"https://api.github.com/repos/coreos/etcd/pulls/5171/comments","review_comment_url":"https://api.github.com/repos/coreos/etcd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coreos/etcd/issues/5171/comments","statuses_url":"https://api.github.com/repos/coreos/etcd/statuses/281246c2d82d916f6e3d1878fdf2c7623a888e86","head":{"label":"xiang90:runner","ref":"runner","sha":"281246c2d82d916f6e3d1878fdf2c7623a888e86","user":{"login":"xiang90","id":4479947,"avatar_url":"https://avatars.githubusercontent.com/u/4479947?v=3","gravatar_id":"","url":"https://api.github.com/users/xiang90","html_url":"https://github.com/xiang90","followers_url":"https://api.github.com/users/xiang90/followers","following_url":"https://api.github.com/users/xiang90/following{/other_user}","gists_url":"https://api.github.com/users/xiang90/gists{/gist_id}","starred_url":"https://api.github.com/users/xiang90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiang90/subscriptions","organizations_url":"https://api.github.com/users/xiang90/orgs","repos_url":"https://api.github.com/users/xiang90/repos","events_url":"https://api.github.com/users/xiang90/events{/privacy}","received_events_url":"https://api.github.com/users/xiang90/received_events","type":"User","site_admin":false},"repo":{"id":11245678,"name":"etcd","full_name":"xiang90/etcd","owner":{"login":"xiang90","id":4479947,"avatar_url":"https://avatars.githubusercontent.com/u/4479947?v=3","gravatar_id":"","url":"https://api.github.com/users/xiang90","html_url":"https://github.com/xiang90","followers_url":"https://api.github.com/users/xiang90/followers","following_url":"https://api.github.com/users/xiang90/following{/other_user}","gists_url":"https://api.github.com/users/xiang90/gists{/gist_id}","starred_url":"https://api.github.com/users/xiang90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiang90/subscriptions","organizations_url":"https://api.github.com/users/xiang90/orgs","repos_url":"https://api.github.com/users/xiang90/repos","events_url":"https://api.github.com/users/xiang90/events{/privacy}","received_events_url":"https://api.github.com/users/xiang90/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xiang90/etcd","description":null,"fork":true,"url":"https://api.github.com/repos/xiang90/etcd","forks_url":"https://api.github.com/repos/xiang90/etcd/forks","keys_url":"https://api.github.com/repos/xiang90/etcd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xiang90/etcd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xiang90/etcd/teams","hooks_url":"https://api.github.com/repos/xiang90/etcd/hooks","issue_events_url":"https://api.github.com/repos/xiang90/etcd/issues/events{/number}","events_url":"https://api.github.com/repos/xiang90/etcd/events","assignees_url":"https://api.github.com/repos/xiang90/etcd/assignees{/user}","branches_url":"https://api.github.com/repos/xiang90/etcd/branches{/branch}","tags_url":"https://api.github.com/repos/xiang90/etcd/tags","blobs_url":"https://api.github.com/repos/xiang90/etcd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xiang90/etcd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xiang90/etcd/git/refs{/sha}","trees_url":"https://api.github.com/repos/xiang90/etcd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xiang90/etcd/statuses/{sha}","languages_url":"https://api.github.com/repos/xiang90/etcd/languages","stargazers_url":"https://api.github.com/repos/xiang90/etcd/stargazers","contributors_url":"https://api.github.com/repos/xiang90/etcd/contributors","subscribers_url":"https://api.github.com/repos/xiang90/etcd/subscribers","subscription_url":"https://api.github.com/repos/xiang90/etcd/subscription","commits_url":"https://api.github.com/repos/xiang90/etcd/commits{/sha}","git_commits_url":"https://api.github.com/repos/xiang90/etcd/git/commits{/sha}","comments_url":"https://api.github.com/repos/xiang90/etcd/comments{/number}","issue_comment_url":"https://api.github.com/repos/xiang90/etcd/issues/comments{/number}","contents_url":"https://api.github.com/repos/xiang90/etcd/contents/{+path}","compare_url":"https://api.github.com/repos/xiang90/etcd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xiang90/etcd/merges","archive_url":"https://api.github.com/repos/xiang90/etcd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xiang90/etcd/downloads","issues_url":"https://api.github.com/repos/xiang90/etcd/issues{/number}","pulls_url":"https://api.github.com/repos/xiang90/etcd/pulls{/number}","milestones_url":"https://api.github.com/repos/xiang90/etcd/milestones{/number}","notifications_url":"https://api.github.com/repos/xiang90/etcd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xiang90/etcd/labels{/name}","releases_url":"https://api.github.com/repos/xiang90/etcd/releases{/id}","deployments_url":"https://api.github.com/repos/xiang90/etcd/deployments","created_at":"2013-07-08T04:17:14Z","updated_at":"2015-06-09T18:06:32Z","pushed_at":"2016-04-28T16:25:10Z","git_url":"git://github.com/xiang90/etcd.git","ssh_url":"git@github.com:xiang90/etcd.git","clone_url":"https://github.com/xiang90/etcd.git","svn_url":"https://github.com/xiang90/etcd","homepage":null,"size":24003,"stargazers_count":3,"watchers_count":3,"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":3,"default_branch":"master"}},"base":{"label":"coreos:master","ref":"master","sha":"c8ab6c348aa4ccec6e6d31e79839869af7312171","user":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"repo":{"id":11225014,"name":"etcd","full_name":"coreos/etcd","owner":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coreos/etcd","description":"Distributed reliable key-value store for the most critical data of a distributed system","fork":false,"url":"https://api.github.com/repos/coreos/etcd","forks_url":"https://api.github.com/repos/coreos/etcd/forks","keys_url":"https://api.github.com/repos/coreos/etcd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coreos/etcd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coreos/etcd/teams","hooks_url":"https://api.github.com/repos/coreos/etcd/hooks","issue_events_url":"https://api.github.com/repos/coreos/etcd/issues/events{/number}","events_url":"https://api.github.com/repos/coreos/etcd/events","assignees_url":"https://api.github.com/repos/coreos/etcd/assignees{/user}","branches_url":"https://api.github.com/repos/coreos/etcd/branches{/branch}","tags_url":"https://api.github.com/repos/coreos/etcd/tags","blobs_url":"https://api.github.com/repos/coreos/etcd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coreos/etcd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coreos/etcd/git/refs{/sha}","trees_url":"https://api.github.com/repos/coreos/etcd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coreos/etcd/statuses/{sha}","languages_url":"https://api.github.com/repos/coreos/etcd/languages","stargazers_url":"https://api.github.com/repos/coreos/etcd/stargazers","contributors_url":"https://api.github.com/repos/coreos/etcd/contributors","subscribers_url":"https://api.github.com/repos/coreos/etcd/subscribers","subscription_url":"https://api.github.com/repos/coreos/etcd/subscription","commits_url":"https://api.github.com/repos/coreos/etcd/commits{/sha}","git_commits_url":"https://api.github.com/repos/coreos/etcd/git/commits{/sha}","comments_url":"https://api.github.com/repos/coreos/etcd/comments{/number}","issue_comment_url":"https://api.github.com/repos/coreos/etcd/issues/comments{/number}","contents_url":"https://api.github.com/repos/coreos/etcd/contents/{+path}","compare_url":"https://api.github.com/repos/coreos/etcd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coreos/etcd/merges","archive_url":"https://api.github.com/repos/coreos/etcd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coreos/etcd/downloads","issues_url":"https://api.github.com/repos/coreos/etcd/issues{/number}","pulls_url":"https://api.github.com/repos/coreos/etcd/pulls{/number}","milestones_url":"https://api.github.com/repos/coreos/etcd/milestones{/number}","notifications_url":"https://api.github.com/repos/coreos/etcd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coreos/etcd/labels{/name}","releases_url":"https://api.github.com/repos/coreos/etcd/releases{/id}","deployments_url":"https://api.github.com/repos/coreos/etcd/deployments","created_at":"2013-07-06T21:57:21Z","updated_at":"2016-04-28T22:54:20Z","pushed_at":"2016-04-28T22:58:48Z","git_url":"git://github.com/coreos/etcd.git","ssh_url":"git@github.com:coreos/etcd.git","clone_url":"https://github.com/coreos/etcd.git","svn_url":"https://github.com/coreos/etcd","homepage":"https://coreos.com/etcd/docs/latest/","size":30750,"stargazers_count":9425,"watchers_count":9425,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1572,"mirror_url":null,"open_issues_count":124,"forks":1572,"open_issues":124,"watchers":9425,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coreos/etcd/pulls/5171"},"html":{"href":"https://github.com/coreos/etcd/pull/5171"},"issue":{"href":"https://api.github.com/repos/coreos/etcd/issues/5171"},"comments":{"href":"https://api.github.com/repos/coreos/etcd/issues/5171/comments"},"review_comments":{"href":"https://api.github.com/repos/coreos/etcd/pulls/5171/comments"},"review_comment":{"href":"https://api.github.com/repos/coreos/etcd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coreos/etcd/pulls/5171/commits"},"statuses":{"href":"https://api.github.com/repos/coreos/etcd/statuses/281246c2d82d916f6e3d1878fdf2c7623a888e86"}}}}