{"action":"created","comment":{"url":"https://api.github.com/repos/citusdata/citus/pulls/comments/68389224","id":68389224,"diff_hunk":"@@ -1045,88 +1056,203 @@ ExecuteDistributedDDLCommand(Oid relationId, const char *ddlCommandString)\n \n /*\n  * ExecuteCommandOnWorkerShards executes a given command on all the finalized\n- * shard placements of the given table. If the remote command errors out on the\n- * first attempted placement, the function returns false. Otherwise, it returns\n- * true.\n- *\n- * If the remote query errors out on the first attempted placement, it is very\n- * likely that the command is going to fail on other placements too. This is\n- * because most errors here will be PostgreSQL errors. Hence, the function fails\n- * fast to avoid marking a high number of placements as failed. If the command\n- * succeeds on at least one placement before failing on others, then the list of\n- * failed placements is returned in failedPlacementList.\n+ * shard placements of the given table with two-phase commit.\n+ * \n+ * ExecuteCommandOnWorkerShards opens an individual connection for each of the   \n+ * shard placement. After all connections are opened, a BEGIN command followed by \n+ * a proper \"SELECT worker_apply_shard_ddl_command(<shardId>, <DDL Command>)\" is\n+ * sent to all open connections in a serial manner.\n+ * \n+ * The opened transactions are handled by the CompleteShardPlacementTransactions\n+ * function.\n  *\n  * Note: There are certain errors which would occur on few nodes and not on the\n  * others. For example, adding a column with a type which exists on some nodes\n- * and not on the others. In that case, this function might still end up returning\n- * a large number of placements as failed.\n+ * and not on the others. \n+ * \n+ * Note: The execution will be blocked if a prepared transaction from previous\n+ * executions exist on the workers. In this case, those prepared transactions should\n+ * be removed by either COMMIT PREPARED or ROLLBACK PREPARED.\n  */\n static bool\n ExecuteCommandOnWorkerShards(Oid relationId, const char *commandString,\n \t\t\t\t\t\t\t List **failedPlacementList)\n {\n-\tbool isFirstPlacement = true;\n-\tListCell *shardCell = NULL;\n-\tList *shardList = NIL;\n+\tList *shardIdList = LoadShardList(relationId);\n \tchar *relationOwner = TableOwner(relationId);\n+\tHTAB *shardConnectionHash = OpenConnectionsToAllShardPlacements(shardIdList,","path":"src/backend/distributed/executor/multi_utility.c","position":105,"original_position":105,"commit_id":"83648491c975c0ad1603760ded7b051c9c0f293c","original_commit_id":"83648491c975c0ad1603760ded7b051c9c0f293c","user":{"login":"marcocitus","id":7127240,"avatar_url":"https://avatars.githubusercontent.com/u/7127240?v=3","gravatar_id":"","url":"https://api.github.com/users/marcocitus","html_url":"https://github.com/marcocitus","followers_url":"https://api.github.com/users/marcocitus/followers","following_url":"https://api.github.com/users/marcocitus/following{/other_user}","gists_url":"https://api.github.com/users/marcocitus/gists{/gist_id}","starred_url":"https://api.github.com/users/marcocitus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcocitus/subscriptions","organizations_url":"https://api.github.com/users/marcocitus/orgs","repos_url":"https://api.github.com/users/marcocitus/repos","events_url":"https://api.github.com/users/marcocitus/events{/privacy}","received_events_url":"https://api.github.com/users/marcocitus/received_events","type":"User","site_admin":false},"body":"If we were to implement multi-statement DDL changes. Would we want to store this hash in a static variable, or rebuild the hash from shardPlacementConnectionList?","created_at":"2016-06-24T12:08:46Z","updated_at":"2016-06-24T12:08:46Z","html_url":"https://github.com/citusdata/citus/pull/618#discussion_r68389224","pull_request_url":"https://api.github.com/repos/citusdata/citus/pulls/618","_links":{"self":{"href":"https://api.github.com/repos/citusdata/citus/pulls/comments/68389224"},"html":{"href":"https://github.com/citusdata/citus/pull/618#discussion_r68389224"},"pull_request":{"href":"https://api.github.com/repos/citusdata/citus/pulls/618"}}},"pull_request":{"url":"https://api.github.com/repos/citusdata/citus/pulls/618","id":74770469,"html_url":"https://github.com/citusdata/citus/pull/618","diff_url":"https://github.com/citusdata/citus/pull/618.diff","patch_url":"https://github.com/citusdata/citus/pull/618.patch","issue_url":"https://api.github.com/repos/citusdata/citus/issues/618","number":618,"state":"open","locked":false,"title":"Propagate DDL Commands with 2PC","user":{"login":"aamederen","id":1406797,"avatar_url":"https://avatars.githubusercontent.com/u/1406797?v=3","gravatar_id":"","url":"https://api.github.com/users/aamederen","html_url":"https://github.com/aamederen","followers_url":"https://api.github.com/users/aamederen/followers","following_url":"https://api.github.com/users/aamederen/following{/other_user}","gists_url":"https://api.github.com/users/aamederen/gists{/gist_id}","starred_url":"https://api.github.com/users/aamederen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aamederen/subscriptions","organizations_url":"https://api.github.com/users/aamederen/orgs","repos_url":"https://api.github.com/users/aamederen/repos","events_url":"https://api.github.com/users/aamederen/events{/privacy}","received_events_url":"https://api.github.com/users/aamederen/received_events","type":"User","site_admin":false},"body":"Fixes #513\r\nFixes #480\r\n\r\nThis change modifies the DDL Propagation logic so that DDL queries\r\nare propagated via 2-Phase Commit protocol. This way, failures during\r\nthe execution of distributed DDL commands will not leave the table in\r\nan intermediate state.\r\n\r\nThe workflow of the successful case is this:\r\n1. Open individual connections to all shard placements\r\n2. Send `BEGIN; SELECT worker_apply_shard_ddl_command(<shardId>, <DDL Command>)`\r\nto all connections, one by one, in a serial manner.\r\n3. Send `PREPARE TRANSCATION <transaction_id>` to all connections.\r\n4. Sedn `COMMIT` to all connections.\r\n\r\nFailure cases:\r\n- If a worker problem occurs before sending of all DDL commands is finished, then\r\nall changes are rolled back.\r\n- If a worker problem occurs after all DDL commands are sent but not after\r\n`PREPARE TRANSACTION` commands are finished, then all changes are rolled back.\r\nHowever, if a worker node is failed, then the prepared transactions in that worker\r\nshould be rolled back manually.\r\n- If a worker problem occurs during `COMMIT PREPARED` statements are being sent,\r\nthen the prepared transactions on the failed workers should be commited manually.\r\n- If master fails before the first 'PREPARE TRANSACTION' is sent, then nothing is\r\nchanged on workers.\r\n- If master fails during `PREPARE TRANSACTION` commands are being sent, then the\r\nprepared transactions on workers should be rolled back manually.\r\n- If master fails during `COMMIT PREPARED` or `ROLLBACK PREPARED` commands are being\r\nsent, then the remaining prepared transactions on the workers should be handled manually.","created_at":"2016-06-22T11:53:39Z","updated_at":"2016-06-24T12:08:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4edc88928a58fd6ec86dc7cd48543ad5d9d35697","assignee":{"login":"marcocitus","id":7127240,"avatar_url":"https://avatars.githubusercontent.com/u/7127240?v=3","gravatar_id":"","url":"https://api.github.com/users/marcocitus","html_url":"https://github.com/marcocitus","followers_url":"https://api.github.com/users/marcocitus/followers","following_url":"https://api.github.com/users/marcocitus/following{/other_user}","gists_url":"https://api.github.com/users/marcocitus/gists{/gist_id}","starred_url":"https://api.github.com/users/marcocitus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcocitus/subscriptions","organizations_url":"https://api.github.com/users/marcocitus/orgs","repos_url":"https://api.github.com/users/marcocitus/repos","events_url":"https://api.github.com/users/marcocitus/events{/privacy}","received_events_url":"https://api.github.com/users/marcocitus/received_events","type":"User","site_admin":false},"assignees":[{"login":"marcocitus","id":7127240,"avatar_url":"https://avatars.githubusercontent.com/u/7127240?v=3","gravatar_id":"","url":"https://api.github.com/users/marcocitus","html_url":"https://github.com/marcocitus","followers_url":"https://api.github.com/users/marcocitus/followers","following_url":"https://api.github.com/users/marcocitus/following{/other_user}","gists_url":"https://api.github.com/users/marcocitus/gists{/gist_id}","starred_url":"https://api.github.com/users/marcocitus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcocitus/subscriptions","organizations_url":"https://api.github.com/users/marcocitus/orgs","repos_url":"https://api.github.com/users/marcocitus/repos","events_url":"https://api.github.com/users/marcocitus/events{/privacy}","received_events_url":"https://api.github.com/users/marcocitus/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/citusdata/citus/milestones/5","html_url":"https://github.com/citusdata/citus/milestones/5.2%20Release","labels_url":"https://api.github.com/repos/citusdata/citus/milestones/5/labels","id":1766257,"number":5,"title":"5.2 Release","description":"Citus v5.2 Release","creator":{"login":"ozgune","id":2545443,"avatar_url":"https://avatars.githubusercontent.com/u/2545443?v=3","gravatar_id":"","url":"https://api.github.com/users/ozgune","html_url":"https://github.com/ozgune","followers_url":"https://api.github.com/users/ozgune/followers","following_url":"https://api.github.com/users/ozgune/following{/other_user}","gists_url":"https://api.github.com/users/ozgune/gists{/gist_id}","starred_url":"https://api.github.com/users/ozgune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ozgune/subscriptions","organizations_url":"https://api.github.com/users/ozgune/orgs","repos_url":"https://api.github.com/users/ozgune/repos","events_url":"https://api.github.com/users/ozgune/events{/privacy}","received_events_url":"https://api.github.com/users/ozgune/received_events","type":"User","site_admin":false},"open_issues":38,"closed_issues":27,"state":"open","created_at":"2016-05-14T17:08:34Z","updated_at":"2016-06-22T18:10:01Z","due_on":"2016-07-22T07:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/citusdata/citus/pulls/618/commits","review_comments_url":"https://api.github.com/repos/citusdata/citus/pulls/618/comments","review_comment_url":"https://api.github.com/repos/citusdata/citus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/citusdata/citus/issues/618/comments","statuses_url":"https://api.github.com/repos/citusdata/citus/statuses/83648491c975c0ad1603760ded7b051c9c0f293c","head":{"label":"citusdata:ddl_propagation_2pc","ref":"ddl_propagation_2pc","sha":"83648491c975c0ad1603760ded7b051c9c0f293c","user":{"login":"citusdata","id":2545424,"avatar_url":"https://avatars.githubusercontent.com/u/2545424?v=3","gravatar_id":"","url":"https://api.github.com/users/citusdata","html_url":"https://github.com/citusdata","followers_url":"https://api.github.com/users/citusdata/followers","following_url":"https://api.github.com/users/citusdata/following{/other_user}","gists_url":"https://api.github.com/users/citusdata/gists{/gist_id}","starred_url":"https://api.github.com/users/citusdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citusdata/subscriptions","organizations_url":"https://api.github.com/users/citusdata/orgs","repos_url":"https://api.github.com/users/citusdata/repos","events_url":"https://api.github.com/users/citusdata/events{/privacy}","received_events_url":"https://api.github.com/users/citusdata/received_events","type":"Organization","site_admin":false},"repo":{"id":50874442,"name":"citus","full_name":"citusdata/citus","owner":{"login":"citusdata","id":2545424,"avatar_url":"https://avatars.githubusercontent.com/u/2545424?v=3","gravatar_id":"","url":"https://api.github.com/users/citusdata","html_url":"https://github.com/citusdata","followers_url":"https://api.github.com/users/citusdata/followers","following_url":"https://api.github.com/users/citusdata/following{/other_user}","gists_url":"https://api.github.com/users/citusdata/gists{/gist_id}","starred_url":"https://api.github.com/users/citusdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citusdata/subscriptions","organizations_url":"https://api.github.com/users/citusdata/orgs","repos_url":"https://api.github.com/users/citusdata/repos","events_url":"https://api.github.com/users/citusdata/events{/privacy}","received_events_url":"https://api.github.com/users/citusdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/citusdata/citus","description":"Scalable PostgreSQL for real-time workloads","fork":false,"url":"https://api.github.com/repos/citusdata/citus","forks_url":"https://api.github.com/repos/citusdata/citus/forks","keys_url":"https://api.github.com/repos/citusdata/citus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/citusdata/citus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/citusdata/citus/teams","hooks_url":"https://api.github.com/repos/citusdata/citus/hooks","issue_events_url":"https://api.github.com/repos/citusdata/citus/issues/events{/number}","events_url":"https://api.github.com/repos/citusdata/citus/events","assignees_url":"https://api.github.com/repos/citusdata/citus/assignees{/user}","branches_url":"https://api.github.com/repos/citusdata/citus/branches{/branch}","tags_url":"https://api.github.com/repos/citusdata/citus/tags","blobs_url":"https://api.github.com/repos/citusdata/citus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/citusdata/citus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/citusdata/citus/git/refs{/sha}","trees_url":"https://api.github.com/repos/citusdata/citus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/citusdata/citus/statuses/{sha}","languages_url":"https://api.github.com/repos/citusdata/citus/languages","stargazers_url":"https://api.github.com/repos/citusdata/citus/stargazers","contributors_url":"https://api.github.com/repos/citusdata/citus/contributors","subscribers_url":"https://api.github.com/repos/citusdata/citus/subscribers","subscription_url":"https://api.github.com/repos/citusdata/citus/subscription","commits_url":"https://api.github.com/repos/citusdata/citus/commits{/sha}","git_commits_url":"https://api.github.com/repos/citusdata/citus/git/commits{/sha}","comments_url":"https://api.github.com/repos/citusdata/citus/comments{/number}","issue_comment_url":"https://api.github.com/repos/citusdata/citus/issues/comments{/number}","contents_url":"https://api.github.com/repos/citusdata/citus/contents/{+path}","compare_url":"https://api.github.com/repos/citusdata/citus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/citusdata/citus/merges","archive_url":"https://api.github.com/repos/citusdata/citus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/citusdata/citus/downloads","issues_url":"https://api.github.com/repos/citusdata/citus/issues{/number}","pulls_url":"https://api.github.com/repos/citusdata/citus/pulls{/number}","milestones_url":"https://api.github.com/repos/citusdata/citus/milestones{/number}","notifications_url":"https://api.github.com/repos/citusdata/citus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/citusdata/citus/labels{/name}","releases_url":"https://api.github.com/repos/citusdata/citus/releases{/id}","deployments_url":"https://api.github.com/repos/citusdata/citus/deployments","created_at":"2016-02-01T21:58:39Z","updated_at":"2016-06-24T10:39:34Z","pushed_at":"2016-06-24T09:10:37Z","git_url":"git://github.com/citusdata/citus.git","ssh_url":"git@github.com:citusdata/citus.git","clone_url":"https://github.com/citusdata/citus.git","svn_url":"https://github.com/citusdata/citus","homepage":"https://www.citusdata.com","size":2808,"stargazers_count":1402,"watchers_count":1402,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":92,"mirror_url":null,"open_issues_count":359,"forks":92,"open_issues":359,"watchers":1402,"default_branch":"master"}},"base":{"label":"citusdata:master","ref":"master","sha":"105f8a91321ace7bcc9dd460647cacc2545a38c9","user":{"login":"citusdata","id":2545424,"avatar_url":"https://avatars.githubusercontent.com/u/2545424?v=3","gravatar_id":"","url":"https://api.github.com/users/citusdata","html_url":"https://github.com/citusdata","followers_url":"https://api.github.com/users/citusdata/followers","following_url":"https://api.github.com/users/citusdata/following{/other_user}","gists_url":"https://api.github.com/users/citusdata/gists{/gist_id}","starred_url":"https://api.github.com/users/citusdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citusdata/subscriptions","organizations_url":"https://api.github.com/users/citusdata/orgs","repos_url":"https://api.github.com/users/citusdata/repos","events_url":"https://api.github.com/users/citusdata/events{/privacy}","received_events_url":"https://api.github.com/users/citusdata/received_events","type":"Organization","site_admin":false},"repo":{"id":50874442,"name":"citus","full_name":"citusdata/citus","owner":{"login":"citusdata","id":2545424,"avatar_url":"https://avatars.githubusercontent.com/u/2545424?v=3","gravatar_id":"","url":"https://api.github.com/users/citusdata","html_url":"https://github.com/citusdata","followers_url":"https://api.github.com/users/citusdata/followers","following_url":"https://api.github.com/users/citusdata/following{/other_user}","gists_url":"https://api.github.com/users/citusdata/gists{/gist_id}","starred_url":"https://api.github.com/users/citusdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citusdata/subscriptions","organizations_url":"https://api.github.com/users/citusdata/orgs","repos_url":"https://api.github.com/users/citusdata/repos","events_url":"https://api.github.com/users/citusdata/events{/privacy}","received_events_url":"https://api.github.com/users/citusdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/citusdata/citus","description":"Scalable PostgreSQL for real-time workloads","fork":false,"url":"https://api.github.com/repos/citusdata/citus","forks_url":"https://api.github.com/repos/citusdata/citus/forks","keys_url":"https://api.github.com/repos/citusdata/citus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/citusdata/citus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/citusdata/citus/teams","hooks_url":"https://api.github.com/repos/citusdata/citus/hooks","issue_events_url":"https://api.github.com/repos/citusdata/citus/issues/events{/number}","events_url":"https://api.github.com/repos/citusdata/citus/events","assignees_url":"https://api.github.com/repos/citusdata/citus/assignees{/user}","branches_url":"https://api.github.com/repos/citusdata/citus/branches{/branch}","tags_url":"https://api.github.com/repos/citusdata/citus/tags","blobs_url":"https://api.github.com/repos/citusdata/citus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/citusdata/citus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/citusdata/citus/git/refs{/sha}","trees_url":"https://api.github.com/repos/citusdata/citus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/citusdata/citus/statuses/{sha}","languages_url":"https://api.github.com/repos/citusdata/citus/languages","stargazers_url":"https://api.github.com/repos/citusdata/citus/stargazers","contributors_url":"https://api.github.com/repos/citusdata/citus/contributors","subscribers_url":"https://api.github.com/repos/citusdata/citus/subscribers","subscription_url":"https://api.github.com/repos/citusdata/citus/subscription","commits_url":"https://api.github.com/repos/citusdata/citus/commits{/sha}","git_commits_url":"https://api.github.com/repos/citusdata/citus/git/commits{/sha}","comments_url":"https://api.github.com/repos/citusdata/citus/comments{/number}","issue_comment_url":"https://api.github.com/repos/citusdata/citus/issues/comments{/number}","contents_url":"https://api.github.com/repos/citusdata/citus/contents/{+path}","compare_url":"https://api.github.com/repos/citusdata/citus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/citusdata/citus/merges","archive_url":"https://api.github.com/repos/citusdata/citus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/citusdata/citus/downloads","issues_url":"https://api.github.com/repos/citusdata/citus/issues{/number}","pulls_url":"https://api.github.com/repos/citusdata/citus/pulls{/number}","milestones_url":"https://api.github.com/repos/citusdata/citus/milestones{/number}","notifications_url":"https://api.github.com/repos/citusdata/citus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/citusdata/citus/labels{/name}","releases_url":"https://api.github.com/repos/citusdata/citus/releases{/id}","deployments_url":"https://api.github.com/repos/citusdata/citus/deployments","created_at":"2016-02-01T21:58:39Z","updated_at":"2016-06-24T10:39:34Z","pushed_at":"2016-06-24T09:10:37Z","git_url":"git://github.com/citusdata/citus.git","ssh_url":"git@github.com:citusdata/citus.git","clone_url":"https://github.com/citusdata/citus.git","svn_url":"https://github.com/citusdata/citus","homepage":"https://www.citusdata.com","size":2808,"stargazers_count":1402,"watchers_count":1402,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":92,"mirror_url":null,"open_issues_count":359,"forks":92,"open_issues":359,"watchers":1402,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/citusdata/citus/pulls/618"},"html":{"href":"https://github.com/citusdata/citus/pull/618"},"issue":{"href":"https://api.github.com/repos/citusdata/citus/issues/618"},"comments":{"href":"https://api.github.com/repos/citusdata/citus/issues/618/comments"},"review_comments":{"href":"https://api.github.com/repos/citusdata/citus/pulls/618/comments"},"review_comment":{"href":"https://api.github.com/repos/citusdata/citus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/citusdata/citus/pulls/618/commits"},"statuses":{"href":"https://api.github.com/repos/citusdata/citus/statuses/83648491c975c0ad1603760ded7b051c9c0f293c"}}}}
{"actor":{"display_login":"marcocitus"}}