@@ -414,7 +414,7 @@ do_sql_command(PGconn *conn, const char *sql)
414
414
static void
415
415
do_sql_send_command (PGconn * conn , const char * sql )
416
416
{
417
- if (PQsendQuery (conn , sql ) != PGRES_COMMAND_OK )
417
+ if (! PQsendQuery (conn , sql ))
418
418
{
419
419
PGresult * res = PQgetResult (conn );
420
420
@@ -724,7 +724,7 @@ RunDtmStatement(char const * sql, unsigned expectedStatus, DtmCommandResultHandl
724
724
{
725
725
if (entry -> xact_depth > 0 )
726
726
{
727
- do_sql_command (entry -> conn , sql );
727
+ do_sql_send_command (entry -> conn , sql );
728
728
}
729
729
}
730
730
@@ -791,16 +791,16 @@ pgfdw_xact_callback(XactEvent event, void *arg)
791
791
HASH_SEQ_STATUS scan ;
792
792
ConnCacheEntry * entry ;
793
793
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
+ // }
804
804
805
805
/* Quick exit if no connections were touched in this transaction. */
806
806
if (!xact_got_connection )
@@ -863,6 +863,11 @@ pgfdw_xact_callback(XactEvent event, void *arg)
863
863
864
864
switch (event )
865
865
{
866
+ case XACT_EVENT_START :
867
+ case XACT_EVENT_COMMIT_PREPARED :
868
+ case XACT_EVENT_ABORT_PREPARED :
869
+ break ;
870
+
866
871
case XACT_EVENT_PARALLEL_PRE_COMMIT :
867
872
case XACT_EVENT_PRE_COMMIT :
868
873
@@ -873,37 +878,13 @@ pgfdw_xact_callback(XactEvent event, void *arg)
873
878
pgfdw_reject_incomplete_xact_state_change (entry );
874
879
875
880
/* 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 :
901
881
if (!currentGlobalTransactionId )
902
882
{
903
883
entry -> changing_xact_state = true;
904
884
do_sql_command (entry -> conn , "COMMIT TRANSACTION" );
905
885
entry -> changing_xact_state = false;
906
886
}
887
+
907
888
/*
908
889
* If there were any errors in subtransactions, and we
909
890
* made prepared statements, do a DEALLOCATE ALL to make
@@ -927,7 +908,27 @@ pgfdw_xact_callback(XactEvent event, void *arg)
927
908
entry -> have_prep_stmt = false;
928
909
entry -> have_error = false;
929
910
break ;
911
+ case XACT_EVENT_PRE_PREPARE :
930
912
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 ;
931
932
case XACT_EVENT_PARALLEL_ABORT :
932
933
case XACT_EVENT_ABORT :
933
934
@@ -991,11 +992,6 @@ pgfdw_xact_callback(XactEvent event, void *arg)
991
992
/* Disarm changing_xact_state if it all worked. */
992
993
entry -> changing_xact_state = abort_cleanup_failure ;
993
994
break ;
994
-
995
- case XACT_EVENT_START :
996
- case XACT_EVENT_COMMIT_PREPARED :
997
- case XACT_EVENT_ABORT_PREPARED :
998
- break ;
999
995
}
1000
996
}
1001
997
@@ -1014,13 +1010,12 @@ pgfdw_xact_callback(XactEvent event, void *arg)
1014
1010
disconnect_pg_server (entry );
1015
1011
}
1016
1012
}
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
+ // {
1019
1015
/*
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.)
1024
1019
*/
1025
1020
xact_got_connection = false;
1026
1021
@@ -1029,7 +1024,7 @@ pgfdw_xact_callback(XactEvent event, void *arg)
1029
1024
1030
1025
currentGlobalTransactionId = 0 ;
1031
1026
currentConnection = NULL ;
1032
- }
1027
+ // }
1033
1028
}
1034
1029
1035
1030
/*
0 commit comments