From e1e383cb599b12e9ff2e3cbeb1e208b16eaa4f9c Mon Sep 17 00:00:00 2001 From: Hadi Moshayedi Date: Thu, 9 Jan 2020 11:09:11 -0800 Subject: [PATCH] Don't override xact id assigned by coordinator on workers. We might need to send commands from workers to other workers. In these cases we shouldn't override the xact id assigned by coordinator, or otherwise we won't read the consistent set of result files accross the nodes. --- .../transaction/transaction_management.c | 19 +++++++++++++++++-- .../distributed/transaction_management.h | 7 +++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/backend/distributed/transaction/transaction_management.c b/src/backend/distributed/transaction/transaction_management.c index 0d898236a..e86e5ac55 100644 --- a/src/backend/distributed/transaction/transaction_management.c +++ b/src/backend/distributed/transaction/transaction_management.c @@ -117,7 +117,8 @@ static bool MaybeExecutingUDF(void); void UseCoordinatedTransaction(void) { - if (CurrentCoordinatedTransactionState == COORD_TRANS_STARTED) + if (CurrentCoordinatedTransactionState == COORD_TRANS_STARTED || + CurrentCoordinatedTransactionState == COORD_TRANS_STARTED_ON_WORKER) { return; } @@ -130,7 +131,21 @@ UseCoordinatedTransaction(void) CurrentCoordinatedTransactionState = COORD_TRANS_STARTED; - AssignDistributedTransactionId(); + /* + * This might be part of bigger distributed transaction originating from + * another node, in which case transaction id has already been assigned + * by a assign_distributed_transaction_id() call. + */ + DistributedTransactionId *transactionId = GetCurrentDistributedTransactionId(); + if (transactionId->transactionNumber == 0) + { + CurrentCoordinatedTransactionState = COORD_TRANS_STARTED_ON_WORKER; + AssignDistributedTransactionId(); + } + else + { + CurrentCoordinatedTransactionState = COORD_TRANS_STARTED; + } } diff --git a/src/include/distributed/transaction_management.h b/src/include/distributed/transaction_management.h index 924d836be..f1e9ece90 100644 --- a/src/include/distributed/transaction_management.h +++ b/src/include/distributed/transaction_management.h @@ -35,6 +35,13 @@ typedef enum CoordinatedTransactionState /* no coordinated transaction in progress, but connections established */ COORD_TRANS_IDLE, + /* + * Coordinated transaction was initiated by coordinator, but the worker also + * needs to start a coordinated transaction to be able to send commands to + * other workers. + */ + COORD_TRANS_STARTED_ON_WORKER, + /* coordinated transaction in progress */ COORD_TRANS_STARTED,