Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5656683

Browse files
author
Etsuro Fujita
committed
postgres_fdw: Minor cleanup for pgfdw_abort_cleanup().
Commit 85c6961 introduced this function to deduplicate code in the transaction callback functions, but the SQL command passed as an argument to it was useless when it returned before aborting a remote transaction using the command. Modify pgfdw_abort_cleanup() so that it constructs the command when/if necessary, as before, removing the argument from it. Also update comments in pgfdw_abort_cleanup() and one of the calling functions. Etsuro Fujita, reviewed by David Zhang. Discussion: https://postgr.es/m/CAPmGK158hrd%3DZfXmgkmNFHivgh18e4oE2Gz151C2Q4OBDjZ08A%40mail.gmail.com
1 parent ad8759b commit 5656683

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

contrib/postgres_fdw/connection.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ static bool pgfdw_exec_cleanup_query(PGconn *conn, const char *query,
110110
bool ignore_errors);
111111
static bool pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime,
112112
PGresult **result, bool *timed_out);
113-
static void pgfdw_abort_cleanup(ConnCacheEntry *entry, const char *sql,
114-
bool toplevel);
113+
static void pgfdw_abort_cleanup(ConnCacheEntry *entry, bool toplevel);
115114
static void pgfdw_finish_pre_commit_cleanup(List *pending_entries);
116115
static void pgfdw_finish_pre_subcommit_cleanup(List *pending_entries,
117116
int curlevel);
@@ -1015,8 +1014,8 @@ pgfdw_xact_callback(XactEvent event, void *arg)
10151014
break;
10161015
case XACT_EVENT_PARALLEL_ABORT:
10171016
case XACT_EVENT_ABORT:
1018-
1019-
pgfdw_abort_cleanup(entry, "ABORT TRANSACTION", true);
1017+
/* Rollback all remote transactions during abort */
1018+
pgfdw_abort_cleanup(entry, true);
10201019
break;
10211020
}
10221021
}
@@ -1109,10 +1108,7 @@ pgfdw_subxact_callback(SubXactEvent event, SubTransactionId mySubid,
11091108
else
11101109
{
11111110
/* Rollback all remote subtransactions during abort */
1112-
snprintf(sql, sizeof(sql),
1113-
"ROLLBACK TO SAVEPOINT s%d; RELEASE SAVEPOINT s%d",
1114-
curlevel, curlevel);
1115-
pgfdw_abort_cleanup(entry, sql, false);
1111+
pgfdw_abort_cleanup(entry, false);
11161112
}
11171113

11181114
/* OK, we're outta that level of subtransaction */
@@ -1465,19 +1461,18 @@ exit: ;
14651461
}
14661462

14671463
/*
1468-
* Abort remote transaction.
1469-
*
1470-
* The statement specified in "sql" is sent to the remote server,
1471-
* in order to rollback the remote transaction.
1464+
* Abort remote transaction or subtransaction.
14721465
*
14731466
* "toplevel" should be set to true if toplevel (main) transaction is
14741467
* rollbacked, false otherwise.
14751468
*
14761469
* Set entry->changing_xact_state to false on success, true on failure.
14771470
*/
14781471
static void
1479-
pgfdw_abort_cleanup(ConnCacheEntry *entry, const char *sql, bool toplevel)
1472+
pgfdw_abort_cleanup(ConnCacheEntry *entry, bool toplevel)
14801473
{
1474+
char sql[100];
1475+
14811476
/*
14821477
* Don't try to clean up the connection if we're already in error
14831478
* recursion trouble.
@@ -1509,8 +1504,14 @@ pgfdw_abort_cleanup(ConnCacheEntry *entry, const char *sql, bool toplevel)
15091504
!pgfdw_cancel_query(entry->conn))
15101505
return; /* Unable to cancel running query */
15111506

1507+
if (toplevel)
1508+
snprintf(sql, sizeof(sql), "ABORT TRANSACTION");
1509+
else
1510+
snprintf(sql, sizeof(sql),
1511+
"ROLLBACK TO SAVEPOINT s%d; RELEASE SAVEPOINT s%d",
1512+
entry->xact_depth, entry->xact_depth);
15121513
if (!pgfdw_exec_cleanup_query(entry->conn, sql, false))
1513-
return; /* Unable to abort remote transaction */
1514+
return; /* Unable to abort remote (sub)transaction */
15141515

15151516
if (toplevel)
15161517
{

0 commit comments

Comments
 (0)