From 2388968b62c0de2ed0601d092cd69daca2bbea54 Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Wed, 20 Jul 2016 12:06:57 +0200 Subject: [PATCH] Move CompleteShardPlacementTransactions to multi_shard_transaction.c --- .../distributed/transaction/commit_protocol.c | 60 ----------------- .../transaction/multi_shard_transaction.c | 66 ++++++++++++++++++- .../distributed/multi_shard_transaction.h | 5 +- 3 files changed, 65 insertions(+), 66 deletions(-) diff --git a/src/backend/distributed/transaction/commit_protocol.c b/src/backend/distributed/transaction/commit_protocol.c index a1c7ff839..728f672f4 100644 --- a/src/backend/distributed/transaction/commit_protocol.c +++ b/src/backend/distributed/transaction/commit_protocol.c @@ -45,66 +45,6 @@ InitializeDistributedTransaction(void) } -/* - * CompleteShardPlacementTransactions commits or aborts pending shard placement - * transactions when the local transaction commits or aborts. - */ -void -CompleteShardPlacementTransactions(XactEvent event, void *arg) -{ - if (shardPlacementConnectionList == NIL) - { - /* nothing to do */ - return; - } - else if (event == XACT_EVENT_PRE_COMMIT) - { - /* - * Any failure here will cause local changes to be rolled back, - * and remote changes to either roll back (1PC) or, in case of - * connection or node failure, leave a prepared transaction - * (2PC). - */ - - if (MultiShardCommitProtocol == COMMIT_PROTOCOL_2PC) - { - PrepareRemoteTransactions(shardPlacementConnectionList); - } - - return; - } - else if (event == XACT_EVENT_COMMIT) - { - /* - * A failure here will cause some remote changes to either - * roll back (1PC) or, in case of connection or node failure, - * leave a prepared transaction (2PC). However, the local - * changes have already been committed. - */ - - CommitRemoteTransactions(shardPlacementConnectionList, false); - } - else if (event == XACT_EVENT_ABORT) - { - /* - * A failure here will cause some remote changes to either - * roll back (1PC) or, in case of connection or node failure, - * leave a prepared transaction (2PC). The local changes have - * already been rolled back. - */ - - AbortRemoteTransactions(shardPlacementConnectionList); - } - else - { - return; - } - - CloseConnections(shardPlacementConnectionList); - shardPlacementConnectionList = NIL; -} - - /* * PrepareRemoteTransactions prepares all transactions on connections in * connectionList for commit if the 2PC commit protocol is enabled. diff --git a/src/backend/distributed/transaction/multi_shard_transaction.c b/src/backend/distributed/transaction/multi_shard_transaction.c index b11019be0..3ec4ee618 100644 --- a/src/backend/distributed/transaction/multi_shard_transaction.c +++ b/src/backend/distributed/transaction/multi_shard_transaction.c @@ -23,10 +23,12 @@ #define INITIAL_CONNECTION_CACHE_SIZE 1001 -List *shardPlacementConnectionList = NIL; - +/* Local functions forward declarations */ static void RegisterShardPlacementXactCallback(void); + +/* Global variables used in commit handler */ +static List *shardPlacementConnectionList = NIL; static bool isXactCallbackRegistered = false; @@ -224,6 +226,66 @@ RegisterShardPlacementXactCallback(void) } +/* + * CompleteShardPlacementTransactions commits or aborts pending shard placement + * transactions when the local transaction commits or aborts. + */ +void +CompleteShardPlacementTransactions(XactEvent event, void *arg) +{ + if (shardPlacementConnectionList == NIL) + { + /* nothing to do */ + return; + } + else if (event == XACT_EVENT_PRE_COMMIT) + { + /* + * Any failure here will cause local changes to be rolled back, + * and remote changes to either roll back (1PC) or, in case of + * connection or node failure, leave a prepared transaction + * (2PC). + */ + + if (MultiShardCommitProtocol == COMMIT_PROTOCOL_2PC) + { + PrepareRemoteTransactions(shardPlacementConnectionList); + } + + return; + } + else if (event == XACT_EVENT_COMMIT) + { + /* + * A failure here will cause some remote changes to either + * roll back (1PC) or, in case of connection or node failure, + * leave a prepared transaction (2PC). However, the local + * changes have already been committed. + */ + + CommitRemoteTransactions(shardPlacementConnectionList, false); + } + else if (event == XACT_EVENT_ABORT) + { + /* + * A failure here will cause some remote changes to either + * roll back (1PC) or, in case of connection or node failure, + * leave a prepared transaction (2PC). The local changes have + * already been rolled back. + */ + + AbortRemoteTransactions(shardPlacementConnectionList); + } + else + { + return; + } + + CloseConnections(shardPlacementConnectionList); + shardPlacementConnectionList = NIL; +} + + /* * CloseConnections closes all connections in connectionList. */ diff --git a/src/include/distributed/multi_shard_transaction.h b/src/include/distributed/multi_shard_transaction.h index 2f7c30fd9..95f257768 100644 --- a/src/include/distributed/multi_shard_transaction.h +++ b/src/include/distributed/multi_shard_transaction.h @@ -13,7 +13,6 @@ #define MULTI_SHARD_TRANSACTION_H -#include "access/xact.h" #include "utils/hsearch.h" #include "nodes/pg_list.h" @@ -26,9 +25,6 @@ typedef struct ShardConnections } ShardConnections; -extern List *shardPlacementConnectionList; - - extern HTAB * OpenTransactionsToAllShardPlacements(List *shardIdList, char *relationOwner); extern HTAB * CreateShardConnectionHash(void); @@ -40,4 +36,5 @@ extern ShardConnections * GetShardConnections(HTAB *shardConnectionHash, extern List * ConnectionList(HTAB *connectionHash); extern void CloseConnections(List *connectionList); + #endif /* MULTI_SHARD_TRANSACTION_H */