{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/pd/pulls/comments/73850815","id":73850815,"diff_hunk":"@@ -29,36 +30,118 @@ import (\n const defaultDialTimeout = 30 * time.Second\n \n // TODO: support HTTPS\n-func (cfg *Config) genClientV3Config() clientv3.Config {\n+func genClientV3Config(cfg *Config) clientv3.Config {\n \tendpoints := strings.Split(cfg.Join, \",\")\n \treturn clientv3.Config{\n \t\tEndpoints:   endpoints,\n \t\tDialTimeout: defaultDialTimeout,\n \t}\n }\n \n-// prepareJoinCluster send MemberAdd command to pd cluster,\n-// returns pd initial cluster configuration.\n-func (cfg *Config) prepareJoinCluster() (string, error) {\n+func memberAdd(client *clientv3.Client, urls []string) (*clientv3.MemberAddResponse, error) {\n \tctx, cancel := context.WithTimeout(context.Background(), defaultDialTimeout)\n \tdefer cancel()\n \n-\tclient, err := clientv3.New(cfg.genClientV3Config())\n+\treturn client.MemberAdd(ctx, urls)\n+}\n+\n+func memberList(client *clientv3.Client) (*clientv3.MemberListResponse, error) {\n+\tctx, cancel := context.WithTimeout(context.Background(), defaultDialTimeout)\n+\tdefer cancel()\n+\n+\treturn client.MemberList(ctx)\n+}\n+\n+// prepareJoinCluster send MemberAdd command to pd cluster,\n+// returns pd initial cluster configuration.\n+//\n+// TL;TR: The join functionality is safe. With data, join does nothing, w/o data\n+//        and it is not a member of cluster, join does MemberAdd, otherwise\n+//        return an error.\n+//\n+// Etcd automatically re-join cluster if there is a data dir, so first we check\n+// if there is data dir or not. With data dir, it returns an empty string(etcd\n+// will get correct configurations from data dir.)\n+//\n+// Without data dir, we may have following cases:","path":"server/join.go","position":53,"original_position":53,"commit_id":"d8b01d90a1dc42f03f2bf263f7978e486ffcc629","original_commit_id":"d8b01d90a1dc42f03f2bf263f7978e486ffcc629","user":{"login":"queenypingcap","id":19528243,"avatar_url":"https://avatars.githubusercontent.com/u/19528243?v=3","gravatar_id":"","url":"https://api.github.com/users/queenypingcap","html_url":"https://github.com/queenypingcap","followers_url":"https://api.github.com/users/queenypingcap/followers","following_url":"https://api.github.com/users/queenypingcap/following{/other_user}","gists_url":"https://api.github.com/users/queenypingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/queenypingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/queenypingcap/subscriptions","organizations_url":"https://api.github.com/users/queenypingcap/orgs","repos_url":"https://api.github.com/users/queenypingcap/repos","events_url":"https://api.github.com/users/queenypingcap/events{/privacy}","received_events_url":"https://api.github.com/users/queenypingcap/received_events","type":"User","site_admin":false},"body":"Please consider this: if these cases are sequential and have to be in this order, please keep the ordered list bullets. If not, please change them to unordered list bullets.","created_at":"2016-08-08T10:04:00Z","updated_at":"2016-08-08T10:04:00Z","html_url":"https://github.com/pingcap/pd/pull/249#discussion_r73850815","pull_request_url":"https://api.github.com/repos/pingcap/pd/pulls/249","_links":{"self":{"href":"https://api.github.com/repos/pingcap/pd/pulls/comments/73850815"},"html":{"href":"https://github.com/pingcap/pd/pull/249#discussion_r73850815"},"pull_request":{"href":"https://api.github.com/repos/pingcap/pd/pulls/249"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/pd/pulls/249","id":80038254,"html_url":"https://github.com/pingcap/pd/pull/249","diff_url":"https://github.com/pingcap/pd/pull/249.diff","patch_url":"https://github.com/pingcap/pd/pull/249.patch","issue_url":"https://api.github.com/repos/pingcap/pd/issues/249","number":249,"state":"open","locked":false,"title":"server: refine join flag","user":{"login":"overvenus","id":2150711,"avatar_url":"https://avatars.githubusercontent.com/u/2150711?v=3","gravatar_id":"","url":"https://api.github.com/users/overvenus","html_url":"https://github.com/overvenus","followers_url":"https://api.github.com/users/overvenus/followers","following_url":"https://api.github.com/users/overvenus/following{/other_user}","gists_url":"https://api.github.com/users/overvenus/gists{/gist_id}","starred_url":"https://api.github.com/users/overvenus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overvenus/subscriptions","organizations_url":"https://api.github.com/users/overvenus/orgs","repos_url":"https://api.github.com/users/overvenus/repos","events_url":"https://api.github.com/users/overvenus/events{/privacy}","received_events_url":"https://api.github.com/users/overvenus/received_events","type":"User","site_admin":false},"body":"#248 #247 #246 \r\n\r\nEtcd automatically re-join cluster if there is data dir.\r\nJoin cases:\r\n 1. join cluster\r\n   - 1.1. with data-dir: return \"\"\r\n   - 1.2. without data-dir: MemberAdd, MemberList, gen initial-cluster\r\n 2. join self\r\n   - 2.1. with data-dir: return \"\"\r\n   - 2.2. without data-dir: return \"\"\r\n 3. re-join after fail\r\n   - 3.1. with data-dir: return \"\"\r\n   - 3.2. without data-dir: return error(etcd reports: raft log corrupted, truncated, or lost?)\r\n 4. join after delete\r\n   - 4.1. with data-dir: return \"\" (cluster will reject it, however itself will keep runing.)\r\n   - 4.2. without data-dir: treat as case 1.2\r\n\r\nPTAL @siddontang @qiuyesuifeng @huachaohuang \r\n\r\ncc @v01dstar @iamxy  ","created_at":"2016-08-04T08:31:55Z","updated_at":"2016-08-08T10:04:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c249ff79c4325a67a89ff628deb3c89343002f84","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/pd/pulls/249/commits","review_comments_url":"https://api.github.com/repos/pingcap/pd/pulls/249/comments","review_comment_url":"https://api.github.com/repos/pingcap/pd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/pd/issues/249/comments","statuses_url":"https://api.github.com/repos/pingcap/pd/statuses/d8b01d90a1dc42f03f2bf263f7978e486ffcc629","head":{"label":"overvenus:refine-join","ref":"refine-join","sha":"d8b01d90a1dc42f03f2bf263f7978e486ffcc629","user":{"login":"overvenus","id":2150711,"avatar_url":"https://avatars.githubusercontent.com/u/2150711?v=3","gravatar_id":"","url":"https://api.github.com/users/overvenus","html_url":"https://github.com/overvenus","followers_url":"https://api.github.com/users/overvenus/followers","following_url":"https://api.github.com/users/overvenus/following{/other_user}","gists_url":"https://api.github.com/users/overvenus/gists{/gist_id}","starred_url":"https://api.github.com/users/overvenus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overvenus/subscriptions","organizations_url":"https://api.github.com/users/overvenus/orgs","repos_url":"https://api.github.com/users/overvenus/repos","events_url":"https://api.github.com/users/overvenus/events{/privacy}","received_events_url":"https://api.github.com/users/overvenus/received_events","type":"User","site_admin":false},"repo":{"id":64187243,"name":"pd","full_name":"overvenus/pd","owner":{"login":"overvenus","id":2150711,"avatar_url":"https://avatars.githubusercontent.com/u/2150711?v=3","gravatar_id":"","url":"https://api.github.com/users/overvenus","html_url":"https://github.com/overvenus","followers_url":"https://api.github.com/users/overvenus/followers","following_url":"https://api.github.com/users/overvenus/following{/other_user}","gists_url":"https://api.github.com/users/overvenus/gists{/gist_id}","starred_url":"https://api.github.com/users/overvenus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overvenus/subscriptions","organizations_url":"https://api.github.com/users/overvenus/orgs","repos_url":"https://api.github.com/users/overvenus/repos","events_url":"https://api.github.com/users/overvenus/events{/privacy}","received_events_url":"https://api.github.com/users/overvenus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/overvenus/pd","description":"Placement driver for TiKV","fork":true,"url":"https://api.github.com/repos/overvenus/pd","forks_url":"https://api.github.com/repos/overvenus/pd/forks","keys_url":"https://api.github.com/repos/overvenus/pd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/overvenus/pd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/overvenus/pd/teams","hooks_url":"https://api.github.com/repos/overvenus/pd/hooks","issue_events_url":"https://api.github.com/repos/overvenus/pd/issues/events{/number}","events_url":"https://api.github.com/repos/overvenus/pd/events","assignees_url":"https://api.github.com/repos/overvenus/pd/assignees{/user}","branches_url":"https://api.github.com/repos/overvenus/pd/branches{/branch}","tags_url":"https://api.github.com/repos/overvenus/pd/tags","blobs_url":"https://api.github.com/repos/overvenus/pd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/overvenus/pd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/overvenus/pd/git/refs{/sha}","trees_url":"https://api.github.com/repos/overvenus/pd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/overvenus/pd/statuses/{sha}","languages_url":"https://api.github.com/repos/overvenus/pd/languages","stargazers_url":"https://api.github.com/repos/overvenus/pd/stargazers","contributors_url":"https://api.github.com/repos/overvenus/pd/contributors","subscribers_url":"https://api.github.com/repos/overvenus/pd/subscribers","subscription_url":"https://api.github.com/repos/overvenus/pd/subscription","commits_url":"https://api.github.com/repos/overvenus/pd/commits{/sha}","git_commits_url":"https://api.github.com/repos/overvenus/pd/git/commits{/sha}","comments_url":"https://api.github.com/repos/overvenus/pd/comments{/number}","issue_comment_url":"https://api.github.com/repos/overvenus/pd/issues/comments{/number}","contents_url":"https://api.github.com/repos/overvenus/pd/contents/{+path}","compare_url":"https://api.github.com/repos/overvenus/pd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/overvenus/pd/merges","archive_url":"https://api.github.com/repos/overvenus/pd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/overvenus/pd/downloads","issues_url":"https://api.github.com/repos/overvenus/pd/issues{/number}","pulls_url":"https://api.github.com/repos/overvenus/pd/pulls{/number}","milestones_url":"https://api.github.com/repos/overvenus/pd/milestones{/number}","notifications_url":"https://api.github.com/repos/overvenus/pd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/overvenus/pd/labels{/name}","releases_url":"https://api.github.com/repos/overvenus/pd/releases{/id}","deployments_url":"https://api.github.com/repos/overvenus/pd/deployments","created_at":"2016-07-26T03:36:04Z","updated_at":"2016-07-26T03:36:05Z","pushed_at":"2016-08-08T08:46:01Z","git_url":"git://github.com/overvenus/pd.git","ssh_url":"git@github.com:overvenus/pd.git","clone_url":"https://github.com/overvenus/pd.git","svn_url":"https://github.com/overvenus/pd","homepage":"","size":2982,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"a62c75dc3dd1606a73e66097f7def8058e07d55e","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":53311716,"name":"pd","full_name":"pingcap/pd","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/pd","description":"Placement driver for TiKV","fork":false,"url":"https://api.github.com/repos/pingcap/pd","forks_url":"https://api.github.com/repos/pingcap/pd/forks","keys_url":"https://api.github.com/repos/pingcap/pd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/pd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/pd/teams","hooks_url":"https://api.github.com/repos/pingcap/pd/hooks","issue_events_url":"https://api.github.com/repos/pingcap/pd/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/pd/events","assignees_url":"https://api.github.com/repos/pingcap/pd/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/pd/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/pd/tags","blobs_url":"https://api.github.com/repos/pingcap/pd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/pd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/pd/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/pd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/pd/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/pd/languages","stargazers_url":"https://api.github.com/repos/pingcap/pd/stargazers","contributors_url":"https://api.github.com/repos/pingcap/pd/contributors","subscribers_url":"https://api.github.com/repos/pingcap/pd/subscribers","subscription_url":"https://api.github.com/repos/pingcap/pd/subscription","commits_url":"https://api.github.com/repos/pingcap/pd/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/pd/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/pd/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/pd/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/pd/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/pd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/pd/merges","archive_url":"https://api.github.com/repos/pingcap/pd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/pd/downloads","issues_url":"https://api.github.com/repos/pingcap/pd/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/pd/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/pd/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/pd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/pd/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/pd/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/pd/deployments","created_at":"2016-03-07T09:13:06Z","updated_at":"2016-08-03T16:23:03Z","pushed_at":"2016-08-08T08:46:01Z","git_url":"git://github.com/pingcap/pd.git","ssh_url":"git@github.com:pingcap/pd.git","clone_url":"https://github.com/pingcap/pd.git","svn_url":"https://github.com/pingcap/pd","homepage":"","size":3405,"stargazers_count":17,"watchers_count":17,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":20,"forks":4,"open_issues":20,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/pd/pulls/249"},"html":{"href":"https://github.com/pingcap/pd/pull/249"},"issue":{"href":"https://api.github.com/repos/pingcap/pd/issues/249"},"comments":{"href":"https://api.github.com/repos/pingcap/pd/issues/249/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/pd/pulls/249/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/pd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/pd/pulls/249/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/pd/statuses/d8b01d90a1dc42f03f2bf263f7978e486ffcc629"}}}}
{"actor":{"display_login":"queenypingcap"}}