From a75436a54b6bed4505b67371a2ae7737cd8d63eb Mon Sep 17 00:00:00 2001 From: SaitTalhaNisanci Date: Thu, 5 Mar 2020 18:36:12 +0300 Subject: [PATCH] refactor CoordinatedTransactionCallback (#3571) --- .../transaction/transaction_management.c | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/backend/distributed/transaction/transaction_management.c b/src/backend/distributed/transaction/transaction_management.c index 2dfedf353..f28a43571 100644 --- a/src/backend/distributed/transaction/transaction_management.c +++ b/src/backend/distributed/transaction/transaction_management.c @@ -110,6 +110,7 @@ static void PushSubXact(SubTransactionId subId); static void PopSubXact(SubTransactionId subId); static void SwallowErrors(void (*func)()); static bool MaybeExecutingUDF(void); +static void ResetGlobalVariables(void); /* @@ -248,13 +249,7 @@ CoordinatedTransactionCallback(XactEvent event, void *arg) AfterXactConnectionHandling(true); } - CurrentCoordinatedTransactionState = COORD_TRANS_NONE; - XactModificationLevel = XACT_MODIFICATION_NONE; - TransactionAccessedLocalPlacement = false; - TransactionConnectedToLocalGroup = false; - dlist_init(&InProgressTransactions); - activeSetStmts = NULL; - CoordinatedTransactionUses2PC = false; + ResetGlobalVariables(); UnSetDistributedTransactionId(); @@ -303,13 +298,7 @@ CoordinatedTransactionCallback(XactEvent event, void *arg) AfterXactConnectionHandling(false); } - CurrentCoordinatedTransactionState = COORD_TRANS_NONE; - XactModificationLevel = XACT_MODIFICATION_NONE; - TransactionAccessedLocalPlacement = false; - TransactionConnectedToLocalGroup = false; - dlist_init(&InProgressTransactions); - activeSetStmts = NULL; - CoordinatedTransactionUses2PC = false; + ResetGlobalVariables(); /* * Getting here without ExecutorLevel 0 is a bug, however it is such a big @@ -446,6 +435,23 @@ CoordinatedTransactionCallback(XactEvent event, void *arg) } +/* + * ResetGlobalVariables resets global variables that + * might be changed during the execution of queries. + */ +static void +ResetGlobalVariables() +{ + CurrentCoordinatedTransactionState = COORD_TRANS_NONE; + XactModificationLevel = XACT_MODIFICATION_NONE; + TransactionAccessedLocalPlacement = false; + TransactionConnectedToLocalGroup = false; + dlist_init(&InProgressTransactions); + activeSetStmts = NULL; + CoordinatedTransactionUses2PC = false; +} + + /* * ResetShardPlacementTransactionState performs cleanup after the end of a * transaction.