{"action":"created","comment":{"url":"https://api.github.com/repos/Flipkart/chihaya/pulls/comments/202613630","pull_request_review_id":137345143,"id":202613630,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMjYxMzYzMA==","diff_hunk":"@@ -0,0 +1,234 @@\n+package etcdfailover\n+\n+import (\n+\t\"github.com/coreos/etcd/clientv3\"\n+\t\"github.com/coreos/etcd/clientv3/concurrency\"\n+\t\"context\"\n+\t\"sync\"\n+\t\"fmt\"\n+\t\"time\"\n+)\n+\n+// NOTE\n+// Known Issues:\n+// 1. \tIf etcd cluster becomes unavailable, tracker nodes will take 2 * session_timeout_secs to shutdown cleanly\n+\n+\n+type ElectionState string\n+const (\n+\tNotParticipant    ElectionState = \"NotParticipant\"\n+\tParticipant       ElectionState = \"Participant\"\n+\tLeader            ElectionState = \"Leader\"\n+)\n+\n+type ElectionManager struct {\n+\tcfg            Config\n+\tcli            *clientv3.Client\n+\tcliCreated     bool\n+\tsession        *concurrency.Session\n+\tsessionCreated bool\n+\telection       *concurrency.Election\n+\tcancel         context.CancelFunc\n+\tmu             sync.Mutex\n+\tstate          ElectionState\n+\tevtChan        *SafeSendChan\n+}\n+\n+type ElectionManagerOption func(*ElectionManager)\n+\n+func WithEtcdClient(cli *clientv3.Client) ElectionManagerOption {\n+\treturn func(em *ElectionManager) {\n+\t\tem.cli = cli\n+\t}\n+}\n+\n+func WithEtcdSession(session *concurrency.Session) ElectionManagerOption {\n+\treturn func(em *ElectionManager) {\n+\t\tem.session = session\n+\t}\n+}\n+\n+func NewElectionManager(provided Config, opts ...ElectionManagerOption) *ElectionManager {\n+\tcfg := provided.Validate()\n+\tem := &ElectionManager{\n+\t\tcfg:    cfg,\n+\t\tcancel: func () {},\n+\t\tstate:  NotParticipant,\n+\t}\n+\tfor _, opt := range opts {\n+\t\topt(em)\n+\t}\n+\n+\t//if session is provided, etcd client is not required, hence etcd config not required\n+\t//if client is provided, etcd config is not required, session can be created from provided etcd client\n+\t//when session and client both are not provided, etcd config is required\n+\tif em.session == nil && em.cli == nil {\n+\t\tcfg.Logger.Warn(\"etcd client not provided, falling back to config.Etcd which will be used to create etcd client and session later\")\n+\t\tem.cfg = em.cfg.ValidateEtcdConfig()\n+\t}\n+\n+\treturn em\n+}\n+\n+func (em *ElectionManager) Start() (<-chan ElectionState, error) {\n+\tem.mu.Lock()\n+\tdefer em.mu.Unlock()\n+\n+\tif em.state == NotParticipant {\n+\t\tem.evtChan = NewSafeSendChan()\n+\t\tvar err error\n+\t\t//ensure consecutive start-ups don't happen\n+\t\tdefer func() {\n+\t\t\tem.setState(Participant)","path":"availability/etcdfailover/electionmanager.go","position":null,"original_position":82,"commit_id":"fbcb596aa25fd1e972b222017adc984cebbba252","original_commit_id":"81ae18cc7bb281e2e40f65c09dd19e22a338fd6e","user":{"login":"yashpal1995","id":4785467,"node_id":"MDQ6VXNlcjQ3ODU0Njc=","avatar_url":"https://avatars2.githubusercontent.com/u/4785467?v=4","gravatar_id":"","url":"https://api.github.com/users/yashpal1995","html_url":"https://github.com/yashpal1995","followers_url":"https://api.github.com/users/yashpal1995/followers","following_url":"https://api.github.com/users/yashpal1995/following{/other_user}","gists_url":"https://api.github.com/users/yashpal1995/gists{/gist_id}","starred_url":"https://api.github.com/users/yashpal1995/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yashpal1995/subscriptions","organizations_url":"https://api.github.com/users/yashpal1995/orgs","repos_url":"https://api.github.com/users/yashpal1995/repos","events_url":"https://api.github.com/users/yashpal1995/events{/privacy}","received_events_url":"https://api.github.com/users/yashpal1995/received_events","type":"User","site_admin":false},"body":"Yeah, though it works for chihaya, but in general does the start expected to be called once only(like with no retries)? So one can't call start again if previous start call fails with some error, as the state is not `NotParticipant`.","created_at":"2018-07-16T09:03:12Z","updated_at":"2018-07-16T09:03:13Z","html_url":"https://github.com/Flipkart/chihaya/pull/2#discussion_r202613630","pull_request_url":"https://api.github.com/repos/Flipkart/chihaya/pulls/2","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/Flipkart/chihaya/pulls/comments/202613630"},"html":{"href":"https://github.com/Flipkart/chihaya/pull/2#discussion_r202613630"},"pull_request":{"href":"https://api.github.com/repos/Flipkart/chihaya/pulls/2"}},"in_reply_to_id":199602483},"pull_request":{"url":"https://api.github.com/repos/Flipkart/chihaya/pulls/2","id":193273903,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzMjczOTAz","html_url":"https://github.com/Flipkart/chihaya/pull/2","diff_url":"https://github.com/Flipkart/chihaya/pull/2.diff","patch_url":"https://github.com/Flipkart/chihaya/pull/2.patch","issue_url":"https://api.github.com/repos/Flipkart/chihaya/issues/2","number":2,"state":"open","locked":false,"title":"Automatic failover using etcd","user":{"login":"anvinjain","id":8705790,"node_id":"MDQ6VXNlcjg3MDU3OTA=","avatar_url":"https://avatars1.githubusercontent.com/u/8705790?v=4","gravatar_id":"","url":"https://api.github.com/users/anvinjain","html_url":"https://github.com/anvinjain","followers_url":"https://api.github.com/users/anvinjain/followers","following_url":"https://api.github.com/users/anvinjain/following{/other_user}","gists_url":"https://api.github.com/users/anvinjain/gists{/gist_id}","starred_url":"https://api.github.com/users/anvinjain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anvinjain/subscriptions","organizations_url":"https://api.github.com/users/anvinjain/orgs","repos_url":"https://api.github.com/users/anvinjain/repos","events_url":"https://api.github.com/users/anvinjain/events{/privacy}","received_events_url":"https://api.github.com/users/anvinjain/received_events","type":"User","site_admin":false},"body":"Multiple trackers can be started behind a load balancer. Ensures only one tracker is active at a time. Ensures that when the active tracker goes down, a passive tracker is promoted to be active.\r\nUses etcd for leader election","created_at":"2018-06-07T10:27:35Z","updated_at":"2018-07-16T09:03:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5ca1c77937f869f5cf00ae476844c2485c32aa74","assignee":{"login":"anvinjain","id":8705790,"node_id":"MDQ6VXNlcjg3MDU3OTA=","avatar_url":"https://avatars1.githubusercontent.com/u/8705790?v=4","gravatar_id":"","url":"https://api.github.com/users/anvinjain","html_url":"https://github.com/anvinjain","followers_url":"https://api.github.com/users/anvinjain/followers","following_url":"https://api.github.com/users/anvinjain/following{/other_user}","gists_url":"https://api.github.com/users/anvinjain/gists{/gist_id}","starred_url":"https://api.github.com/users/anvinjain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anvinjain/subscriptions","organizations_url":"https://api.github.com/users/anvinjain/orgs","repos_url":"https://api.github.com/users/anvinjain/repos","events_url":"https://api.github.com/users/anvinjain/events{/privacy}","received_events_url":"https://api.github.com/users/anvinjain/received_events","type":"User","site_admin":false},"assignees":[{"login":"anvinjain","id":8705790,"node_id":"MDQ6VXNlcjg3MDU3OTA=","avatar_url":"https://avatars1.githubusercontent.com/u/8705790?v=4","gravatar_id":"","url":"https://api.github.com/users/anvinjain","html_url":"https://github.com/anvinjain","followers_url":"https://api.github.com/users/anvinjain/followers","following_url":"https://api.github.com/users/anvinjain/following{/other_user}","gists_url":"https://api.github.com/users/anvinjain/gists{/gist_id}","starred_url":"https://api.github.com/users/anvinjain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anvinjain/subscriptions","organizations_url":"https://api.github.com/users/anvinjain/orgs","repos_url":"https://api.github.com/users/anvinjain/repos","events_url":"https://api.github.com/users/anvinjain/events{/privacy}","received_events_url":"https://api.github.com/users/anvinjain/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":881217826,"node_id":"MDU6TGFiZWw4ODEyMTc4MjY=","url":"https://api.github.com/repos/Flipkart/chihaya/labels/enhancement","name":"enhancement","color":"a2eeef","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/Flipkart/chihaya/pulls/2/commits","review_comments_url":"https://api.github.com/repos/Flipkart/chihaya/pulls/2/comments","review_comment_url":"https://api.github.com/repos/Flipkart/chihaya/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Flipkart/chihaya/issues/2/comments","statuses_url":"https://api.github.com/repos/Flipkart/chihaya/statuses/fbcb596aa25fd1e972b222017adc984cebbba252","head":{"label":"Flipkart:etcd-failover","ref":"etcd-failover","sha":"fbcb596aa25fd1e972b222017adc984cebbba252","user":{"login":"Flipkart","id":1179997,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNzk5OTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1179997?v=4","gravatar_id":"","url":"https://api.github.com/users/Flipkart","html_url":"https://github.com/Flipkart","followers_url":"https://api.github.com/users/Flipkart/followers","following_url":"https://api.github.com/users/Flipkart/following{/other_user}","gists_url":"https://api.github.com/users/Flipkart/gists{/gist_id}","starred_url":"https://api.github.com/users/Flipkart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Flipkart/subscriptions","organizations_url":"https://api.github.com/users/Flipkart/orgs","repos_url":"https://api.github.com/users/Flipkart/repos","events_url":"https://api.github.com/users/Flipkart/events{/privacy}","received_events_url":"https://api.github.com/users/Flipkart/received_events","type":"Organization","site_admin":false},"repo":{"id":126980471,"node_id":"MDEwOlJlcG9zaXRvcnkxMjY5ODA0NzE=","name":"chihaya","full_name":"Flipkart/chihaya","owner":{"login":"Flipkart","id":1179997,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNzk5OTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1179997?v=4","gravatar_id":"","url":"https://api.github.com/users/Flipkart","html_url":"https://github.com/Flipkart","followers_url":"https://api.github.com/users/Flipkart/followers","following_url":"https://api.github.com/users/Flipkart/following{/other_user}","gists_url":"https://api.github.com/users/Flipkart/gists{/gist_id}","starred_url":"https://api.github.com/users/Flipkart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Flipkart/subscriptions","organizations_url":"https://api.github.com/users/Flipkart/orgs","repos_url":"https://api.github.com/users/Flipkart/repos","events_url":"https://api.github.com/users/Flipkart/events{/privacy}","received_events_url":"https://api.github.com/users/Flipkart/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Flipkart/chihaya","description":"A customizable, multi-protocol BitTorrent Tracker","fork":true,"url":"https://api.github.com/repos/Flipkart/chihaya","forks_url":"https://api.github.com/repos/Flipkart/chihaya/forks","keys_url":"https://api.github.com/repos/Flipkart/chihaya/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Flipkart/chihaya/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Flipkart/chihaya/teams","hooks_url":"https://api.github.com/repos/Flipkart/chihaya/hooks","issue_events_url":"https://api.github.com/repos/Flipkart/chihaya/issues/events{/number}","events_url":"https://api.github.com/repos/Flipkart/chihaya/events","assignees_url":"https://api.github.com/repos/Flipkart/chihaya/assignees{/user}","branches_url":"https://api.github.com/repos/Flipkart/chihaya/branches{/branch}","tags_url":"https://api.github.com/repos/Flipkart/chihaya/tags","blobs_url":"https://api.github.com/repos/Flipkart/chihaya/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Flipkart/chihaya/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Flipkart/chihaya/git/refs{/sha}","trees_url":"https://api.github.com/repos/Flipkart/chihaya/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Flipkart/chihaya/statuses/{sha}","languages_url":"https://api.github.com/repos/Flipkart/chihaya/languages","stargazers_url":"https://api.github.com/repos/Flipkart/chihaya/stargazers","contributors_url":"https://api.github.com/repos/Flipkart/chihaya/contributors","subscribers_url":"https://api.github.com/repos/Flipkart/chihaya/subscribers","subscription_url":"https://api.github.com/repos/Flipkart/chihaya/subscription","commits_url":"https://api.github.com/repos/Flipkart/chihaya/commits{/sha}","git_commits_url":"https://api.github.com/repos/Flipkart/chihaya/git/commits{/sha}","comments_url":"https://api.github.com/repos/Flipkart/chihaya/comments{/number}","issue_comment_url":"https://api.github.com/repos/Flipkart/chihaya/issues/comments{/number}","contents_url":"https://api.github.com/repos/Flipkart/chihaya/contents/{+path}","compare_url":"https://api.github.com/repos/Flipkart/chihaya/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Flipkart/chihaya/merges","archive_url":"https://api.github.com/repos/Flipkart/chihaya/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Flipkart/chihaya/downloads","issues_url":"https://api.github.com/repos/Flipkart/chihaya/issues{/number}","pulls_url":"https://api.github.com/repos/Flipkart/chihaya/pulls{/number}","milestones_url":"https://api.github.com/repos/Flipkart/chihaya/milestones{/number}","notifications_url":"https://api.github.com/repos/Flipkart/chihaya/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Flipkart/chihaya/labels{/name}","releases_url":"https://api.github.com/repos/Flipkart/chihaya/releases{/id}","deployments_url":"https://api.github.com/repos/Flipkart/chihaya/deployments","created_at":"2018-03-27T12:07:20Z","updated_at":"2018-04-20T07:22:24Z","pushed_at":"2018-07-14T08:43:05Z","git_url":"git://github.com/Flipkart/chihaya.git","ssh_url":"git@github.com:Flipkart/chihaya.git","clone_url":"https://github.com/Flipkart/chihaya.git","svn_url":"https://github.com/Flipkart/chihaya","homepage":"","size":3304,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"Flipkart:memetcd","ref":"memetcd","sha":"671429bb3aecb738c51cf962c69d564f2e7d4abb","user":{"login":"Flipkart","id":1179997,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNzk5OTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1179997?v=4","gravatar_id":"","url":"https://api.github.com/users/Flipkart","html_url":"https://github.com/Flipkart","followers_url":"https://api.github.com/users/Flipkart/followers","following_url":"https://api.github.com/users/Flipkart/following{/other_user}","gists_url":"https://api.github.com/users/Flipkart/gists{/gist_id}","starred_url":"https://api.github.com/users/Flipkart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Flipkart/subscriptions","organizations_url":"https://api.github.com/users/Flipkart/orgs","repos_url":"https://api.github.com/users/Flipkart/repos","events_url":"https://api.github.com/users/Flipkart/events{/privacy}","received_events_url":"https://api.github.com/users/Flipkart/received_events","type":"Organization","site_admin":false},"repo":{"id":126980471,"node_id":"MDEwOlJlcG9zaXRvcnkxMjY5ODA0NzE=","name":"chihaya","full_name":"Flipkart/chihaya","owner":{"login":"Flipkart","id":1179997,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNzk5OTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1179997?v=4","gravatar_id":"","url":"https://api.github.com/users/Flipkart","html_url":"https://github.com/Flipkart","followers_url":"https://api.github.com/users/Flipkart/followers","following_url":"https://api.github.com/users/Flipkart/following{/other_user}","gists_url":"https://api.github.com/users/Flipkart/gists{/gist_id}","starred_url":"https://api.github.com/users/Flipkart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Flipkart/subscriptions","organizations_url":"https://api.github.com/users/Flipkart/orgs","repos_url":"https://api.github.com/users/Flipkart/repos","events_url":"https://api.github.com/users/Flipkart/events{/privacy}","received_events_url":"https://api.github.com/users/Flipkart/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Flipkart/chihaya","description":"A customizable, multi-protocol BitTorrent Tracker","fork":true,"url":"https://api.github.com/repos/Flipkart/chihaya","forks_url":"https://api.github.com/repos/Flipkart/chihaya/forks","keys_url":"https://api.github.com/repos/Flipkart/chihaya/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Flipkart/chihaya/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Flipkart/chihaya/teams","hooks_url":"https://api.github.com/repos/Flipkart/chihaya/hooks","issue_events_url":"https://api.github.com/repos/Flipkart/chihaya/issues/events{/number}","events_url":"https://api.github.com/repos/Flipkart/chihaya/events","assignees_url":"https://api.github.com/repos/Flipkart/chihaya/assignees{/user}","branches_url":"https://api.github.com/repos/Flipkart/chihaya/branches{/branch}","tags_url":"https://api.github.com/repos/Flipkart/chihaya/tags","blobs_url":"https://api.github.com/repos/Flipkart/chihaya/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Flipkart/chihaya/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Flipkart/chihaya/git/refs{/sha}","trees_url":"https://api.github.com/repos/Flipkart/chihaya/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Flipkart/chihaya/statuses/{sha}","languages_url":"https://api.github.com/repos/Flipkart/chihaya/languages","stargazers_url":"https://api.github.com/repos/Flipkart/chihaya/stargazers","contributors_url":"https://api.github.com/repos/Flipkart/chihaya/contributors","subscribers_url":"https://api.github.com/repos/Flipkart/chihaya/subscribers","subscription_url":"https://api.github.com/repos/Flipkart/chihaya/subscription","commits_url":"https://api.github.com/repos/Flipkart/chihaya/commits{/sha}","git_commits_url":"https://api.github.com/repos/Flipkart/chihaya/git/commits{/sha}","comments_url":"https://api.github.com/repos/Flipkart/chihaya/comments{/number}","issue_comment_url":"https://api.github.com/repos/Flipkart/chihaya/issues/comments{/number}","contents_url":"https://api.github.com/repos/Flipkart/chihaya/contents/{+path}","compare_url":"https://api.github.com/repos/Flipkart/chihaya/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Flipkart/chihaya/merges","archive_url":"https://api.github.com/repos/Flipkart/chihaya/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Flipkart/chihaya/downloads","issues_url":"https://api.github.com/repos/Flipkart/chihaya/issues{/number}","pulls_url":"https://api.github.com/repos/Flipkart/chihaya/pulls{/number}","milestones_url":"https://api.github.com/repos/Flipkart/chihaya/milestones{/number}","notifications_url":"https://api.github.com/repos/Flipkart/chihaya/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Flipkart/chihaya/labels{/name}","releases_url":"https://api.github.com/repos/Flipkart/chihaya/releases{/id}","deployments_url":"https://api.github.com/repos/Flipkart/chihaya/deployments","created_at":"2018-03-27T12:07:20Z","updated_at":"2018-04-20T07:22:24Z","pushed_at":"2018-07-14T08:43:05Z","git_url":"git://github.com/Flipkart/chihaya.git","ssh_url":"git@github.com:Flipkart/chihaya.git","clone_url":"https://github.com/Flipkart/chihaya.git","svn_url":"https://github.com/Flipkart/chihaya","homepage":"","size":3304,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Flipkart/chihaya/pulls/2"},"html":{"href":"https://github.com/Flipkart/chihaya/pull/2"},"issue":{"href":"https://api.github.com/repos/Flipkart/chihaya/issues/2"},"comments":{"href":"https://api.github.com/repos/Flipkart/chihaya/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/Flipkart/chihaya/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/Flipkart/chihaya/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Flipkart/chihaya/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/Flipkart/chihaya/statuses/fbcb596aa25fd1e972b222017adc984cebbba252"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"yashpal1995"}}