From f5d6c24e0464e6137a035b1c55f419a82d412460 Mon Sep 17 00:00:00 2001 From: Pavan Deolasee Date: Fri, 3 Jul 2015 15:37:46 +0530 Subject: [PATCH] Handle deferred triggers and close portals before starting 2 phase commit At the end of the 2PC, coordinator closes connections to the remote nodes. So a subsequent attempt to close open Remote Subplans throw an error "Failed to synchronize data node". --- src/backend/access/transam/xact.c | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index a75c525a4b..30e36576cb 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -2269,6 +2269,27 @@ CommitTransaction(void) elog(WARNING, "CommitTransaction while in %s state", TransStateAsString(s->state)); Assert(s->parent == NULL); + /* + * Do pre-commit processing that involves calling user-defined code, such + * as triggers. Since closing cursors could queue trigger actions, + * triggers could open cursors, etc, we have to keep looping until there's + * nothing left to do. + */ + for (;;) + { + /* + * Fire all currently pending deferred triggers. + */ + AfterTriggerFireDeferred(); + + /* + * Close open portals (converting holdable ones into static portals). + * If there weren't any, we are done ... otherwise loop back to check + * if they queued deferred triggers. Lather, rinse, repeat. + */ + if (!PreCommit_Portals(false)) + break; + } #ifdef PGXC /* @@ -2381,27 +2402,6 @@ CommitTransaction(void) } #endif - /* - * Do pre-commit processing that involves calling user-defined code, such - * as triggers. Since closing cursors could queue trigger actions, - * triggers could open cursors, etc, we have to keep looping until there's - * nothing left to do. - */ - for (;;) - { - /* - * Fire all currently pending deferred triggers. - */ - AfterTriggerFireDeferred(); - - /* - * Close open portals (converting holdable ones into static portals). - * If there weren't any, we are done ... otherwise loop back to check - * if they queued deferred triggers. Lather, rinse, repeat. - */ - if (!PreCommit_Portals(false)) - break; - } CallXactCallbacks(is_parallel_worker ? XACT_EVENT_PARALLEL_PRE_COMMIT : XACT_EVENT_PRE_COMMIT); -- 2.39.5