{"action":"created","comment":{"url":"https://api.github.com/repos/zalando/patroni/pulls/comments/38935573","id":38935573,"diff_hunk":"@@ -50,19 +55,20 @@ def initialize(self):\n \n         # is data directory empty?\n         if self.postgresql.data_directory_empty():\n-            # racing to initialize\n-            if self.ha.dcs.race('/initialize'):\n-                self.postgresql.initialize()\n-                self.ha.dcs.take_leader()\n-                self.postgresql.start()\n-                self.postgresql.create_replication_user()\n-                self.postgresql.create_connection_users()\n-            else:\n-                while True:","path":"patroni/__init__.py","position":24,"original_position":24,"commit_id":"ff499604f0cfc5ce1b9e581ce3838ef943d78860","original_commit_id":"ff499604f0cfc5ce1b9e581ce3838ef943d78860","user":{"login":"alexeyklyukin","id":339913,"avatar_url":"https://avatars.githubusercontent.com/u/339913?v=3","gravatar_id":"","url":"https://api.github.com/users/alexeyklyukin","html_url":"https://github.com/alexeyklyukin","followers_url":"https://api.github.com/users/alexeyklyukin/followers","following_url":"https://api.github.com/users/alexeyklyukin/following{/other_user}","gists_url":"https://api.github.com/users/alexeyklyukin/gists{/gist_id}","starred_url":"https://api.github.com/users/alexeyklyukin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexeyklyukin/subscriptions","organizations_url":"https://api.github.com/users/alexeyklyukin/orgs","repos_url":"https://api.github.com/users/alexeyklyukin/repos","events_url":"https://api.github.com/users/alexeyklyukin/events{/privacy}","received_events_url":"https://api.github.com/users/alexeyklyukin/received_events","type":"User","site_admin":false},"body":"I don't see us waiting for the leader in the code fragment you've highlighted. What has changed is that now we try to bootstrap the PostgreSQL cluster before taking the leader: doing it the other way around provides no benefits, but bears an additional responsibility to remove the leader flag during cleanup_on_failed_initialization.\r\n\r\nActually, I see one problem here: if the initialiser node suddenly dies after initidb (say, it cannot not create the users), and then restarts - it will think it was fully initialised and will try to start as a normal member that was started after a stop, potentially acquiring the master role (which would screw up the whole cluster), or a replica, in which case it won't be able to catchup with the master, because it was not initialised from it.","created_at":"2015-09-08T14:58:35Z","updated_at":"2015-09-08T14:58:35Z","html_url":"https://github.com/zalando/patroni/pull/30#discussion_r38935573","pull_request_url":"https://api.github.com/repos/zalando/patroni/pulls/30","_links":{"self":{"href":"https://api.github.com/repos/zalando/patroni/pulls/comments/38935573"},"html":{"href":"https://github.com/zalando/patroni/pull/30#discussion_r38935573"},"pull_request":{"href":"https://api.github.com/repos/zalando/patroni/pulls/30"}}},"pull_request":{"url":"https://api.github.com/repos/zalando/patroni/pulls/30","id":44414553,"html_url":"https://github.com/zalando/patroni/pull/30","diff_url":"https://github.com/zalando/patroni/pull/30.diff","patch_url":"https://github.com/zalando/patroni/pull/30.patch","issue_url":"https://api.github.com/repos/zalando/patroni/issues/30","number":30,"state":"open","locked":false,"title":"Make sure initialize flag is reset on failure.","user":{"login":"alexeyklyukin","id":339913,"avatar_url":"https://avatars.githubusercontent.com/u/339913?v=3","gravatar_id":"","url":"https://api.github.com/users/alexeyklyukin","html_url":"https://github.com/alexeyklyukin","followers_url":"https://api.github.com/users/alexeyklyukin/followers","following_url":"https://api.github.com/users/alexeyklyukin/following{/other_user}","gists_url":"https://api.github.com/users/alexeyklyukin/gists{/gist_id}","starred_url":"https://api.github.com/users/alexeyklyukin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexeyklyukin/subscriptions","organizations_url":"https://api.github.com/users/alexeyklyukin/orgs","repos_url":"https://api.github.com/users/alexeyklyukin/repos","events_url":"https://api.github.com/users/alexeyklyukin/events{/privacy}","received_events_url":"https://api.github.com/users/alexeyklyukin/received_events","type":"User","site_admin":false},"body":"Cleanup the initialize flag if the initializing node fails\r\nto bootstrap its PostgreSQL database.\r\n\r\nRename dcs.race to initialize, since we only call it for the\r\ninitialize flag. Factored out PostgreSQL bootstrapping code\r\ninto a separate function.","created_at":"2015-09-08T10:13:29Z","updated_at":"2015-09-08T14:58:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2731485e1f42cd1e79d29cf392437cc1adec9f63","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/zalando/patroni/pulls/30/commits","review_comments_url":"https://api.github.com/repos/zalando/patroni/pulls/30/comments","review_comment_url":"https://api.github.com/repos/zalando/patroni/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zalando/patroni/issues/30/comments","statuses_url":"https://api.github.com/repos/zalando/patroni/statuses/ff499604f0cfc5ce1b9e581ce3838ef943d78860","head":{"label":"zalando:feature/cleanup_on_failed_initialization","ref":"feature/cleanup_on_failed_initialization","sha":"ff499604f0cfc5ce1b9e581ce3838ef943d78860","user":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"repo":{"id":38744670,"name":"patroni","full_name":"zalando/patroni","owner":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando/patroni","description":" Runners to orchestrate a high-availability PostgreSQL","fork":false,"url":"https://api.github.com/repos/zalando/patroni","forks_url":"https://api.github.com/repos/zalando/patroni/forks","keys_url":"https://api.github.com/repos/zalando/patroni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando/patroni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando/patroni/teams","hooks_url":"https://api.github.com/repos/zalando/patroni/hooks","issue_events_url":"https://api.github.com/repos/zalando/patroni/issues/events{/number}","events_url":"https://api.github.com/repos/zalando/patroni/events","assignees_url":"https://api.github.com/repos/zalando/patroni/assignees{/user}","branches_url":"https://api.github.com/repos/zalando/patroni/branches{/branch}","tags_url":"https://api.github.com/repos/zalando/patroni/tags","blobs_url":"https://api.github.com/repos/zalando/patroni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando/patroni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando/patroni/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando/patroni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando/patroni/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando/patroni/languages","stargazers_url":"https://api.github.com/repos/zalando/patroni/stargazers","contributors_url":"https://api.github.com/repos/zalando/patroni/contributors","subscribers_url":"https://api.github.com/repos/zalando/patroni/subscribers","subscription_url":"https://api.github.com/repos/zalando/patroni/subscription","commits_url":"https://api.github.com/repos/zalando/patroni/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando/patroni/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando/patroni/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando/patroni/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando/patroni/contents/{+path}","compare_url":"https://api.github.com/repos/zalando/patroni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando/patroni/merges","archive_url":"https://api.github.com/repos/zalando/patroni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando/patroni/downloads","issues_url":"https://api.github.com/repos/zalando/patroni/issues{/number}","pulls_url":"https://api.github.com/repos/zalando/patroni/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando/patroni/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando/patroni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando/patroni/labels{/name}","releases_url":"https://api.github.com/repos/zalando/patroni/releases{/id}","created_at":"2015-07-08T09:27:19Z","updated_at":"2015-09-04T06:40:02Z","pushed_at":"2015-09-08T14:53:53Z","git_url":"git://github.com/zalando/patroni.git","ssh_url":"git@github.com:zalando/patroni.git","clone_url":"https://github.com/zalando/patroni.git","svn_url":"https://github.com/zalando/patroni","homepage":"","size":1083,"stargazers_count":10,"watchers_count":10,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":12,"forks":3,"open_issues":12,"watchers":10,"default_branch":"master"}},"base":{"label":"zalando:master","ref":"master","sha":"dd8472f6393e2181c23773883e52f00babb526cd","user":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"repo":{"id":38744670,"name":"patroni","full_name":"zalando/patroni","owner":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando/patroni","description":" Runners to orchestrate a high-availability PostgreSQL","fork":false,"url":"https://api.github.com/repos/zalando/patroni","forks_url":"https://api.github.com/repos/zalando/patroni/forks","keys_url":"https://api.github.com/repos/zalando/patroni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando/patroni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando/patroni/teams","hooks_url":"https://api.github.com/repos/zalando/patroni/hooks","issue_events_url":"https://api.github.com/repos/zalando/patroni/issues/events{/number}","events_url":"https://api.github.com/repos/zalando/patroni/events","assignees_url":"https://api.github.com/repos/zalando/patroni/assignees{/user}","branches_url":"https://api.github.com/repos/zalando/patroni/branches{/branch}","tags_url":"https://api.github.com/repos/zalando/patroni/tags","blobs_url":"https://api.github.com/repos/zalando/patroni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando/patroni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando/patroni/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando/patroni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando/patroni/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando/patroni/languages","stargazers_url":"https://api.github.com/repos/zalando/patroni/stargazers","contributors_url":"https://api.github.com/repos/zalando/patroni/contributors","subscribers_url":"https://api.github.com/repos/zalando/patroni/subscribers","subscription_url":"https://api.github.com/repos/zalando/patroni/subscription","commits_url":"https://api.github.com/repos/zalando/patroni/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando/patroni/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando/patroni/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando/patroni/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando/patroni/contents/{+path}","compare_url":"https://api.github.com/repos/zalando/patroni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando/patroni/merges","archive_url":"https://api.github.com/repos/zalando/patroni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando/patroni/downloads","issues_url":"https://api.github.com/repos/zalando/patroni/issues{/number}","pulls_url":"https://api.github.com/repos/zalando/patroni/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando/patroni/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando/patroni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando/patroni/labels{/name}","releases_url":"https://api.github.com/repos/zalando/patroni/releases{/id}","created_at":"2015-07-08T09:27:19Z","updated_at":"2015-09-04T06:40:02Z","pushed_at":"2015-09-08T14:53:53Z","git_url":"git://github.com/zalando/patroni.git","ssh_url":"git@github.com:zalando/patroni.git","clone_url":"https://github.com/zalando/patroni.git","svn_url":"https://github.com/zalando/patroni","homepage":"","size":1083,"stargazers_count":10,"watchers_count":10,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":12,"forks":3,"open_issues":12,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zalando/patroni/pulls/30"},"html":{"href":"https://github.com/zalando/patroni/pull/30"},"issue":{"href":"https://api.github.com/repos/zalando/patroni/issues/30"},"comments":{"href":"https://api.github.com/repos/zalando/patroni/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/zalando/patroni/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/zalando/patroni/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zalando/patroni/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/zalando/patroni/statuses/ff499604f0cfc5ce1b9e581ce3838ef943d78860"}}}}