@@ -414,7 +414,7 @@ do_sql_command(PGconn *conn, const char *sql)
414414static void
415415do_sql_send_command (PGconn * conn , const char * sql )
416416{
417- if (PQsendQuery (conn , sql ) != PGRES_COMMAND_OK )
417+ if (! PQsendQuery (conn , sql ))
418418 {
419419 PGresult * res = PQgetResult (conn );
420420
@@ -724,7 +724,7 @@ RunDtmStatement(char const * sql, unsigned expectedStatus, DtmCommandResultHandl
724724 {
725725 if (entry -> xact_depth > 0 )
726726 {
727- do_sql_command (entry -> conn , sql );
727+ do_sql_send_command (entry -> conn , sql );
728728 }
729729 }
730730
@@ -791,16 +791,16 @@ pgfdw_xact_callback(XactEvent event, void *arg)
791791 HASH_SEQ_STATUS scan ;
792792 ConnCacheEntry * entry ;
793793
794- /* Do nothing for this events */
795- switch (event )
796- {
797- case XACT_EVENT_START :
798- case XACT_EVENT_COMMIT_PREPARED :
799- case XACT_EVENT_ABORT_PREPARED :
800- return ;
801- default :
802- break ;
803- }
794+ // / * Do nothing for this events */
795+ // switch (event)
796+ // {
797+ // case XACT_EVENT_START:
798+ // case XACT_EVENT_COMMIT_PREPARED:
799+ // case XACT_EVENT_ABORT_PREPARED:
800+ // return;
801+ // default:
802+ // break;
803+ // }
804804
805805 /* Quick exit if no connections were touched in this transaction. */
806806 if (!xact_got_connection )
@@ -863,6 +863,11 @@ pgfdw_xact_callback(XactEvent event, void *arg)
863863
864864 switch (event )
865865 {
866+ case XACT_EVENT_START :
867+ case XACT_EVENT_COMMIT_PREPARED :
868+ case XACT_EVENT_ABORT_PREPARED :
869+ break ;
870+
866871 case XACT_EVENT_PARALLEL_PRE_COMMIT :
867872 case XACT_EVENT_PRE_COMMIT :
868873
@@ -873,37 +878,13 @@ pgfdw_xact_callback(XactEvent event, void *arg)
873878 pgfdw_reject_incomplete_xact_state_change (entry );
874879
875880 /* Commit all remote transactions during pre-commit */
876- entry -> changing_xact_state = true;
877- do_sql_command (entry -> conn , "COMMIT TRANSACTION" );
878- // do_sql_send_command(entry->conn, "COMMIT TRANSACTION");
879- entry -> changing_xact_state = false;
880- continue ;
881-
882- case XACT_EVENT_PRE_PREPARE :
883-
884- /*
885- * We disallow remote transactions that modified anything,
886- * since it's not very reasonable to hold them open until
887- * the prepared transaction is committed. For the moment,
888- * throw error unconditionally; later we might allow
889- * read-only cases. Note that the error will cause us to
890- * come right back here with event == XACT_EVENT_ABORT, so
891- * we'll clean up the connection state at that point.
892- */
893- ereport (ERROR ,
894- (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
895- errmsg ("cannot prepare a transaction that modified remote tables" )));
896- break ;
897-
898- case XACT_EVENT_PARALLEL_COMMIT :
899- case XACT_EVENT_COMMIT :
900- case XACT_EVENT_PREPARE :
901881 if (!currentGlobalTransactionId )
902882 {
903883 entry -> changing_xact_state = true;
904884 do_sql_command (entry -> conn , "COMMIT TRANSACTION" );
905885 entry -> changing_xact_state = false;
906886 }
887+
907888 /*
908889 * If there were any errors in subtransactions, and we
909890 * made prepared statements, do a DEALLOCATE ALL to make
@@ -927,7 +908,27 @@ pgfdw_xact_callback(XactEvent event, void *arg)
927908 entry -> have_prep_stmt = false;
928909 entry -> have_error = false;
929910 break ;
911+ case XACT_EVENT_PRE_PREPARE :
930912
913+ /*
914+ * We disallow remote transactions that modified anything,
915+ * since it's not very reasonable to hold them open until
916+ * the prepared transaction is committed. For the moment,
917+ * throw error unconditionally; later we might allow
918+ * read-only cases. Note that the error will cause us to
919+ * come right back here with event == XACT_EVENT_ABORT, so
920+ * we'll clean up the connection state at that point.
921+ */
922+ ereport (ERROR ,
923+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
924+ errmsg ("cannot prepare a transaction that modified remote tables" )));
925+ break ;
926+ case XACT_EVENT_PARALLEL_COMMIT :
927+ case XACT_EVENT_COMMIT :
928+ case XACT_EVENT_PREPARE :
929+ /* Pre-commit should have closed the open transaction */
930+ // elog(ERROR, "missed cleaning up connection during pre-commit");
931+ break ;
931932 case XACT_EVENT_PARALLEL_ABORT :
932933 case XACT_EVENT_ABORT :
933934
@@ -991,11 +992,6 @@ pgfdw_xact_callback(XactEvent event, void *arg)
991992 /* Disarm changing_xact_state if it all worked. */
992993 entry -> changing_xact_state = abort_cleanup_failure ;
993994 break ;
994-
995- case XACT_EVENT_START :
996- case XACT_EVENT_COMMIT_PREPARED :
997- case XACT_EVENT_ABORT_PREPARED :
998- break ;
999995 }
1000996 }
1001997
@@ -1014,13 +1010,12 @@ pgfdw_xact_callback(XactEvent event, void *arg)
10141010 disconnect_pg_server (entry );
10151011 }
10161012 }
1017- if (event != XACT_EVENT_PARALLEL_PRE_COMMIT && event != XACT_EVENT_PRE_COMMIT )
1018- {
1013+ // if (event != XACT_EVENT_PARALLEL_PRE_COMMIT && event != XACT_EVENT_PRE_COMMIT)
1014+ // {
10191015 /*
1020- * Regardless of the event type, we can now mark ourselves as out of
1021- * the transaction. (Note: if we are here during PRE_COMMIT or
1022- * PRE_PREPARE, this saves a useless scan of the hashtable during
1023- * COMMIT or PREPARE.)
1016+ * Regardless of the event type, we can now mark ourselves as out of the
1017+ * transaction. (Note: if we are here during PRE_COMMIT or PRE_PREPARE,
1018+ * this saves a useless scan of the hashtable during COMMIT or PREPARE.)
10241019 */
10251020 xact_got_connection = false;
10261021
@@ -1029,7 +1024,7 @@ pgfdw_xact_callback(XactEvent event, void *arg)
10291024
10301025 currentGlobalTransactionId = 0 ;
10311026 currentConnection = NULL ;
1032- }
1027+ // }
10331028}
10341029
10351030/*
0 commit comments