{"action":"created","comment":{"url":"https://api.github.com/repos/coreos/etcd/pulls/comments/82046271","pull_request_review_id":2981110,"id":82046271,"diff_hunk":"@@ -0,0 +1,373 @@\n+// Copyright 2015 The etcd Authors\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+package main\n+\n+import (\n+\t\"fmt\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\t\"github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes\"\n+\tpb \"github.com/coreos/etcd/etcdserver/etcdserverpb\"\n+\t\"golang.org/x/net/context\"\n+\t\"google.golang.org/grpc\"\n+\t\"google.golang.org/grpc/grpclog\"\n+)\n+\n+func init() {\n+\tgrpclog.SetLogger(plog)\n+}\n+\n+// time to live for lease\n+const TTL = 10\n+\n+type LeaseStresser interface {\n+\t// Stress starts to stress lease on the etcd cluster\n+\tStress() error\n+\t// Cancel cancels the lease stress test on the etcd cluster\n+\tCancel()\n+\t// Report reports the success and failure of the lease stress test\n+\tReport() (success int, failure int)\n+\n+\tInvariantCheck(ctx context.Context) error\n+\n+\tSetup() error\n+}\n+\n+type leaseStresser struct {\n+\tEndpoint string\n+\tcancel   func()\n+\tconn     *grpc.ClientConn\n+\tid       int\n+\tkvc      pb.KVClient\n+\tlc       pb.LeaseClient\n+\n+\tsuccess           int\n+\tfailure           int\n+\tnumOfLeases       int\n+\tnumOfKeysPerLease int\n+\n+\taliveLeases   map[int64]struct{}\n+\trevokedLeases map[int64]struct{}\n+\n+\twg *sync.WaitGroup\n+\tmu sync.Mutex\n+}\n+type leaseStresserBuilder func(m *member, i int) LeaseStresser\n+\n+func newLeaseStressBuilder(m int, n int) leaseStresserBuilder {\n+\treturn func(mem *member, i int) LeaseStresser {\n+\t\treturn &leaseStresser{\n+\t\t\tEndpoint:          mem.grpcAddr(),\n+\t\t\tnumOfLeases:       m,\n+\t\t\tnumOfKeysPerLease: n,\n+\t\t\tid:                i,\n+\t\t}\n+\t}\n+}\n+\n+func (ls *leaseStresser) Setup() error {\n+\tif ls.numOfLeases == 0 {\n+\t\tpanic(\"expect numOfLeases to be set\")\n+\t}\n+\n+\tif ls.numOfKeysPerLease == 0 {\n+\t\tpanic(\"expect numOfKeysPerLease to be set\")\n+\t}\n+\n+\tconn, err := grpc.Dial(ls.Endpoint, grpc.WithInsecure())\n+\tif err != nil {\n+\t\treturn fmt.Errorf(\"%v (%s)\", err, ls.Endpoint)\n+\t}\n+\tls.kvc = pb.NewKVClient(conn)\n+\tls.lc = pb.NewLeaseClient(conn)\n+\tls.conn = conn\n+\tls.aliveLeases = make(map[int64]struct{})\n+\tls.revokedLeases = make(map[int64]struct{})\n+\n+\treturn nil\n+}\n+\n+func (ls *leaseStresser) Stress() error {\n+\tplog.Printf(\"lease Stresser %v starting ...\", ls)\n+\tctx, cancel := context.WithCancel(context.Background())\n+\tls.cancel = cancel\n+\tls.run(ctx)\n+\treturn nil\n+}\n+\n+func (ls *leaseStresser) run(ctx context.Context) {\n+\n+\tls.createLeases(ctx)\n+\tls.randomlyDropLeases(ctx)\n+\n+}\n+\n+func (ls *leaseStresser) createLeases(ctx context.Context) {\n+\tnumOfLeasesToCreate := ls.numOfLeases - len(ls.aliveLeases)\n+\tvar wg sync.WaitGroup\n+\twg.Add(numOfLeasesToCreate)\n+\tfor i := 0; i < numOfLeasesToCreate; i++ {\n+\t\tgo func() {\n+\t\t\tdefer wg.Done()\n+\t\t\tleaseID, err := ls.createLeaseAndKeepAlive(ctx)\n+\n+\t\t\tif err != nil {\n+\t\t\t\treturn\n+\t\t\t}\n+\t\t\tplog.Printf(\"Lease %v created\", leaseID)\n+\t\t\tls.attachKeysWithLease(ctx, leaseID)\n+\t\t\tls.mu.Lock()\n+\t\t\tls.aliveLeases[leaseID] = struct{}{}\n+\t\t\tplog.Printf(\"Alive leases %v\", ls.aliveLeases)\n+\t\t\tls.mu.Unlock()\n+\n+\t\t}()\n+\t}\n+\twg.Wait()\n+}\n+\n+func (ls *leaseStresser) randomlyDropLeases(ctx context.Context) {\n+\tvar wg sync.WaitGroup\n+\twg.Add(len(ls.aliveLeases))\n+\tfor l := range ls.aliveLeases {\n+\t\tgo func(leaseID int64) {\n+\t\t\tdefer wg.Done()\n+\t\t\tisLeaseDropped := ls.randomlyDropLease(ctx, leaseID)\n+\t\t\tif isLeaseDropped {\n+\t\t\t\tls.mu.Lock()\n+\t\t\t\tplog.Printf(\"Lease %v dropped\", leaseID)\n+\t\t\t\tls.revokedLeases[leaseID] = struct{}{}\n+\t\t\t\tdelete(ls.aliveLeases, leaseID)\n+\t\t\t\tls.mu.Unlock()\n+\t\t\t}\n+\t\t}(l)\n+\t}\n+\twg.Wait()\n+\n+}\n+\n+func (ls *leaseStresser) InvariantCheck(ctx context.Context) error {\n+\tplog.Printf(\"Revoked Leases %+v \", ls.revokedLeases)\n+\tfor leaseID := range ls.revokedLeases {\n+\t\tplog.Printf(\"Revoked Lease %v \", leaseID)\n+\t\tkeysExpired, err := ls.hasKeysExpired(ctx, leaseID)\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\tleaseExpired, err := ls.hasLeaseExpired(ctx, leaseID)\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\tif !keysExpired || !leaseExpired {","path":"tools/functional-tester/etcd-tester/lease_stresser.go","position":175,"original_position":175,"commit_id":"bba80da819c282a62d988d019ec3a7c15e4dfc1f","original_commit_id":"bba80da819c282a62d988d019ec3a7c15e4dfc1f","user":{"login":"fanminshi","id":4983345,"avatar_url":"https://avatars.githubusercontent.com/u/4983345?v=3","gravatar_id":"","url":"https://api.github.com/users/fanminshi","html_url":"https://github.com/fanminshi","followers_url":"https://api.github.com/users/fanminshi/followers","following_url":"https://api.github.com/users/fanminshi/following{/other_user}","gists_url":"https://api.github.com/users/fanminshi/gists{/gist_id}","starred_url":"https://api.github.com/users/fanminshi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fanminshi/subscriptions","organizations_url":"https://api.github.com/users/fanminshi/orgs","repos_url":"https://api.github.com/users/fanminshi/repos","events_url":"https://api.github.com/users/fanminshi/events{/privacy}","received_events_url":"https://api.github.com/users/fanminshi/received_events","type":"User","site_admin":false},"body":"I'll do that!","created_at":"2016-10-05T19:02:08Z","updated_at":"2016-10-05T19:02:08Z","html_url":"https://github.com/coreos/etcd/pull/6588#discussion_r82046271","pull_request_url":"https://api.github.com/repos/coreos/etcd/pulls/6588","_links":{"self":{"href":"https://api.github.com/repos/coreos/etcd/pulls/comments/82046271"},"html":{"href":"https://github.com/coreos/etcd/pull/6588#discussion_r82046271"},"pull_request":{"href":"https://api.github.com/repos/coreos/etcd/pulls/6588"}}},"pull_request":{"url":"https://api.github.com/repos/coreos/etcd/pulls/6588","id":88121277,"html_url":"https://github.com/coreos/etcd/pull/6588","diff_url":"https://github.com/coreos/etcd/pull/6588.diff","patch_url":"https://github.com/coreos/etcd/pull/6588.patch","issue_url":"https://api.github.com/repos/coreos/etcd/issues/6588","number":6588,"state":"open","locked":false,"title":"functional-tester: add lease stresser","user":{"login":"fanminshi","id":4983345,"avatar_url":"https://avatars.githubusercontent.com/u/4983345?v=3","gravatar_id":"","url":"https://api.github.com/users/fanminshi","html_url":"https://github.com/fanminshi","followers_url":"https://api.github.com/users/fanminshi/followers","following_url":"https://api.github.com/users/fanminshi/following{/other_user}","gists_url":"https://api.github.com/users/fanminshi/gists{/gist_id}","starred_url":"https://api.github.com/users/fanminshi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fanminshi/subscriptions","organizations_url":"https://api.github.com/users/fanminshi/orgs","repos_url":"https://api.github.com/users/fanminshi/repos","events_url":"https://api.github.com/users/fanminshi/events{/privacy}","received_events_url":"https://api.github.com/users/fanminshi/received_events","type":"User","site_admin":false},"body":"Add lease stresser to test lease code under stress and etcd failtures\r\n\r\nresolve #6380\r\n","created_at":"2016-10-05T17:26:52Z","updated_at":"2016-10-05T19:02:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0338b711a2e9e95980d9474e40888dd3545aad5f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/coreos/etcd/pulls/6588/commits","review_comments_url":"https://api.github.com/repos/coreos/etcd/pulls/6588/comments","review_comment_url":"https://api.github.com/repos/coreos/etcd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coreos/etcd/issues/6588/comments","statuses_url":"https://api.github.com/repos/coreos/etcd/statuses/bba80da819c282a62d988d019ec3a7c15e4dfc1f","head":{"label":"fanminshi:lease_stressor","ref":"lease_stressor","sha":"bba80da819c282a62d988d019ec3a7c15e4dfc1f","user":{"login":"fanminshi","id":4983345,"avatar_url":"https://avatars.githubusercontent.com/u/4983345?v=3","gravatar_id":"","url":"https://api.github.com/users/fanminshi","html_url":"https://github.com/fanminshi","followers_url":"https://api.github.com/users/fanminshi/followers","following_url":"https://api.github.com/users/fanminshi/following{/other_user}","gists_url":"https://api.github.com/users/fanminshi/gists{/gist_id}","starred_url":"https://api.github.com/users/fanminshi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fanminshi/subscriptions","organizations_url":"https://api.github.com/users/fanminshi/orgs","repos_url":"https://api.github.com/users/fanminshi/repos","events_url":"https://api.github.com/users/fanminshi/events{/privacy}","received_events_url":"https://api.github.com/users/fanminshi/received_events","type":"User","site_admin":false},"repo":{"id":67535590,"name":"etcd","full_name":"fanminshi/etcd","owner":{"login":"fanminshi","id":4983345,"avatar_url":"https://avatars.githubusercontent.com/u/4983345?v=3","gravatar_id":"","url":"https://api.github.com/users/fanminshi","html_url":"https://github.com/fanminshi","followers_url":"https://api.github.com/users/fanminshi/followers","following_url":"https://api.github.com/users/fanminshi/following{/other_user}","gists_url":"https://api.github.com/users/fanminshi/gists{/gist_id}","starred_url":"https://api.github.com/users/fanminshi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fanminshi/subscriptions","organizations_url":"https://api.github.com/users/fanminshi/orgs","repos_url":"https://api.github.com/users/fanminshi/repos","events_url":"https://api.github.com/users/fanminshi/events{/privacy}","received_events_url":"https://api.github.com/users/fanminshi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fanminshi/etcd","description":"Distributed reliable key-value store for the most critical data of a distributed system","fork":true,"url":"https://api.github.com/repos/fanminshi/etcd","forks_url":"https://api.github.com/repos/fanminshi/etcd/forks","keys_url":"https://api.github.com/repos/fanminshi/etcd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fanminshi/etcd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fanminshi/etcd/teams","hooks_url":"https://api.github.com/repos/fanminshi/etcd/hooks","issue_events_url":"https://api.github.com/repos/fanminshi/etcd/issues/events{/number}","events_url":"https://api.github.com/repos/fanminshi/etcd/events","assignees_url":"https://api.github.com/repos/fanminshi/etcd/assignees{/user}","branches_url":"https://api.github.com/repos/fanminshi/etcd/branches{/branch}","tags_url":"https://api.github.com/repos/fanminshi/etcd/tags","blobs_url":"https://api.github.com/repos/fanminshi/etcd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fanminshi/etcd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fanminshi/etcd/git/refs{/sha}","trees_url":"https://api.github.com/repos/fanminshi/etcd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fanminshi/etcd/statuses/{sha}","languages_url":"https://api.github.com/repos/fanminshi/etcd/languages","stargazers_url":"https://api.github.com/repos/fanminshi/etcd/stargazers","contributors_url":"https://api.github.com/repos/fanminshi/etcd/contributors","subscribers_url":"https://api.github.com/repos/fanminshi/etcd/subscribers","subscription_url":"https://api.github.com/repos/fanminshi/etcd/subscription","commits_url":"https://api.github.com/repos/fanminshi/etcd/commits{/sha}","git_commits_url":"https://api.github.com/repos/fanminshi/etcd/git/commits{/sha}","comments_url":"https://api.github.com/repos/fanminshi/etcd/comments{/number}","issue_comment_url":"https://api.github.com/repos/fanminshi/etcd/issues/comments{/number}","contents_url":"https://api.github.com/repos/fanminshi/etcd/contents/{+path}","compare_url":"https://api.github.com/repos/fanminshi/etcd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fanminshi/etcd/merges","archive_url":"https://api.github.com/repos/fanminshi/etcd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fanminshi/etcd/downloads","issues_url":"https://api.github.com/repos/fanminshi/etcd/issues{/number}","pulls_url":"https://api.github.com/repos/fanminshi/etcd/pulls{/number}","milestones_url":"https://api.github.com/repos/fanminshi/etcd/milestones{/number}","notifications_url":"https://api.github.com/repos/fanminshi/etcd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fanminshi/etcd/labels{/name}","releases_url":"https://api.github.com/repos/fanminshi/etcd/releases{/id}","deployments_url":"https://api.github.com/repos/fanminshi/etcd/deployments","created_at":"2016-09-06T18:28:06Z","updated_at":"2016-09-06T18:28:10Z","pushed_at":"2016-10-05T17:25:41Z","git_url":"git://github.com/fanminshi/etcd.git","ssh_url":"git@github.com:fanminshi/etcd.git","clone_url":"https://github.com/fanminshi/etcd.git","svn_url":"https://github.com/fanminshi/etcd","homepage":"https://coreos.com/etcd/docs/latest/","size":25029,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"coreos:master","ref":"master","sha":"d5cd563ce79b8d536d699121b3ac38fa3ccdb3cd","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-10-05T18:30:01Z","pushed_at":"2016-10-05T17:56:57Z","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":32586,"stargazers_count":11000,"watchers_count":11000,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1942,"mirror_url":null,"open_issues_count":131,"forks":1942,"open_issues":131,"watchers":11000,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coreos/etcd/pulls/6588"},"html":{"href":"https://github.com/coreos/etcd/pull/6588"},"issue":{"href":"https://api.github.com/repos/coreos/etcd/issues/6588"},"comments":{"href":"https://api.github.com/repos/coreos/etcd/issues/6588/comments"},"review_comments":{"href":"https://api.github.com/repos/coreos/etcd/pulls/6588/comments"},"review_comment":{"href":"https://api.github.com/repos/coreos/etcd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coreos/etcd/pulls/6588/commits"},"statuses":{"href":"https://api.github.com/repos/coreos/etcd/statuses/bba80da819c282a62d988d019ec3a7c15e4dfc1f"}}}}
{"actor":{"display_login":"fanminshi"}}