mirror of https://github.com/citusdata/citus.git
replace Begin words in coordinated transactions with use (#3293)
parent
a2f2107e6a
commit
2829c601dd
|
@ -298,7 +298,7 @@ PG_FUNCTION_INFO_V1(citus_text_send_as_jsonb);
|
||||||
static void
|
static void
|
||||||
CitusCopyFrom(CopyStmt *copyStatement, char *completionTag)
|
CitusCopyFrom(CopyStmt *copyStatement, char *completionTag)
|
||||||
{
|
{
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
/* disallow COPY to/from file or program except for superusers */
|
/* disallow COPY to/from file or program except for superusers */
|
||||||
if (copyStatement->filename != NULL && !superuser())
|
if (copyStatement->filename != NULL && !superuser())
|
||||||
|
@ -2251,7 +2251,7 @@ CitusCopyDestReceiverStartup(DestReceiver *dest, int operation,
|
||||||
/* keep the table metadata to avoid looking it up for every tuple */
|
/* keep the table metadata to avoid looking it up for every tuple */
|
||||||
copyDest->tableMetadata = cacheEntry;
|
copyDest->tableMetadata = cacheEntry;
|
||||||
|
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
if (cacheEntry->replicationModel == REPLICATION_MODEL_2PC ||
|
if (cacheEntry->replicationModel == REPLICATION_MODEL_2PC ||
|
||||||
MultiShardCommitProtocol == COMMIT_PROTOCOL_2PC)
|
MultiShardCommitProtocol == COMMIT_PROTOCOL_2PC)
|
||||||
|
|
|
@ -237,7 +237,7 @@ AcquireDistributedLockOnRelations(List *relationIdList, LOCKMODE lockMode)
|
||||||
relationIdList = SortList(relationIdList, CompareOids);
|
relationIdList = SortList(relationIdList, CompareOids);
|
||||||
workerNodeList = SortList(workerNodeList, CompareWorkerNodes);
|
workerNodeList = SortList(workerNodeList, CompareWorkerNodes);
|
||||||
|
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
foreach_oid(relationId, relationIdList)
|
foreach_oid(relationId, relationIdList)
|
||||||
{
|
{
|
||||||
|
|
|
@ -897,7 +897,7 @@ StartDistributedExecution(DistributedExecution *execution)
|
||||||
*/
|
*/
|
||||||
if (DistributedExecutionRequiresRollback(execution) || LocalExecutionHappened)
|
if (DistributedExecutionRequiresRollback(execution) || LocalExecutionHappened)
|
||||||
{
|
{
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
if (TaskListRequires2PC(taskList) || LocalExecutionHappened)
|
if (TaskListRequires2PC(taskList) || LocalExecutionHappened)
|
||||||
{
|
{
|
||||||
|
|
|
@ -122,7 +122,7 @@ broadcast_intermediate_result(PG_FUNCTION_ARGS)
|
||||||
* Intermediate results will be stored in a directory that is derived
|
* Intermediate results will be stored in a directory that is derived
|
||||||
* from the distributed transaction ID.
|
* from the distributed transaction ID.
|
||||||
*/
|
*/
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
List *nodeList = ActivePrimaryWorkerNodeList(NoLock);
|
List *nodeList = ActivePrimaryWorkerNodeList(NoLock);
|
||||||
EState *estate = CreateExecutorState();
|
EState *estate = CreateExecutorState();
|
||||||
|
@ -164,7 +164,7 @@ create_intermediate_result(PG_FUNCTION_ARGS)
|
||||||
* Intermediate results will be stored in a directory that is derived
|
* Intermediate results will be stored in a directory that is derived
|
||||||
* from the distributed transaction ID.
|
* from the distributed transaction ID.
|
||||||
*/
|
*/
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
EState *estate = CreateExecutorState();
|
EState *estate = CreateExecutorState();
|
||||||
RemoteFileDestReceiver *resultDest =
|
RemoteFileDestReceiver *resultDest =
|
||||||
|
|
|
@ -53,7 +53,7 @@ ExecuteSubPlans(DistributedPlan *distributedPlan)
|
||||||
* Intermediate results of subplans will be stored in a directory that is
|
* Intermediate results of subplans will be stored in a directory that is
|
||||||
* derived from the distributed transaction ID.
|
* derived from the distributed transaction ID.
|
||||||
*/
|
*/
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
foreach(subPlanCell, subPlanList)
|
foreach(subPlanCell, subPlanList)
|
||||||
{
|
{
|
||||||
|
|
|
@ -361,7 +361,7 @@ DropShards(Oid relationId, char *schemaName, char *relationName,
|
||||||
{
|
{
|
||||||
ListCell *shardIntervalCell = NULL;
|
ListCell *shardIntervalCell = NULL;
|
||||||
|
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
/* At this point we intentionally decided to not use 2PC for reference tables */
|
/* At this point we intentionally decided to not use 2PC for reference tables */
|
||||||
if (MultiShardCommitProtocol == COMMIT_PROTOCOL_2PC)
|
if (MultiShardCommitProtocol == COMMIT_PROTOCOL_2PC)
|
||||||
|
|
|
@ -284,7 +284,7 @@ master_append_table_to_shard(PG_FUNCTION_ARGS)
|
||||||
errhint("Try running master_create_empty_shard() first")));
|
errhint("Try running master_create_empty_shard() first")));
|
||||||
}
|
}
|
||||||
|
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
/* issue command to append table to each shard placement */
|
/* issue command to append table to each shard placement */
|
||||||
foreach(shardPlacementCell, shardPlacementList)
|
foreach(shardPlacementCell, shardPlacementList)
|
||||||
|
|
|
@ -386,7 +386,7 @@ RemoteExplain(Task *task, ExplainState *es)
|
||||||
* Use a coordinated transaction to ensure that we open a transaction block
|
* Use a coordinated transaction to ensure that we open a transaction block
|
||||||
* such that we can set a savepoint.
|
* such that we can set a savepoint.
|
||||||
*/
|
*/
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
for (int placementIndex = 0; placementIndex < placementCount; placementIndex++)
|
for (int placementIndex = 0; placementIndex < placementCount; placementIndex++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -720,7 +720,7 @@ GetCurrentDistributedTransactionId(void)
|
||||||
* sets it for the current backend. It also sets the databaseId and
|
* sets it for the current backend. It also sets the databaseId and
|
||||||
* processId fields.
|
* processId fields.
|
||||||
*
|
*
|
||||||
* This function should only be called on BeginCoordinatedTransaction(). Any other
|
* This function should only be called on UseCoordinatedTransaction(). Any other
|
||||||
* callers is very likely to break the distributed transaction management.
|
* callers is very likely to break the distributed transaction management.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
|
|
|
@ -96,7 +96,6 @@ bool FunctionOpensTransactionBlock = true;
|
||||||
|
|
||||||
|
|
||||||
/* transaction management functions */
|
/* transaction management functions */
|
||||||
static void BeginCoordinatedTransaction(void);
|
|
||||||
static void CoordinatedTransactionCallback(XactEvent event, void *arg);
|
static void CoordinatedTransactionCallback(XactEvent event, void *arg);
|
||||||
static void CoordinatedSubTransactionCallback(SubXactEvent event, SubTransactionId subId,
|
static void CoordinatedSubTransactionCallback(SubXactEvent event, SubTransactionId subId,
|
||||||
SubTransactionId parentSubid, void *arg);
|
SubTransactionId parentSubid, void *arg);
|
||||||
|
@ -111,18 +110,26 @@ static bool MaybeExecutingUDF(void);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* BeginOrContinueCoordinatedTransaction starts a coordinated transaction,
|
* UseCoordinatedTransaction sets up the necessary variables to use
|
||||||
* unless one already is in progress.
|
* a coordinated transaction, unless one is already in progress.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BeginOrContinueCoordinatedTransaction(void)
|
UseCoordinatedTransaction(void)
|
||||||
{
|
{
|
||||||
if (CurrentCoordinatedTransactionState == COORD_TRANS_STARTED)
|
if (CurrentCoordinatedTransactionState == COORD_TRANS_STARTED)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BeginCoordinatedTransaction();
|
if (CurrentCoordinatedTransactionState != COORD_TRANS_NONE &&
|
||||||
|
CurrentCoordinatedTransactionState != COORD_TRANS_IDLE)
|
||||||
|
{
|
||||||
|
ereport(ERROR, (errmsg("starting transaction in wrong state")));
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentCoordinatedTransactionState = COORD_TRANS_STARTED;
|
||||||
|
|
||||||
|
AssignDistributedTransactionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -169,25 +176,6 @@ InitializeTransactionManagement(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* BeginCoordinatedTransaction begins a coordinated transaction. No
|
|
||||||
* pre-existing coordinated transaction may be in progress./
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
BeginCoordinatedTransaction(void)
|
|
||||||
{
|
|
||||||
if (CurrentCoordinatedTransactionState != COORD_TRANS_NONE &&
|
|
||||||
CurrentCoordinatedTransactionState != COORD_TRANS_IDLE)
|
|
||||||
{
|
|
||||||
ereport(ERROR, (errmsg("starting transaction in wrong state")));
|
|
||||||
}
|
|
||||||
|
|
||||||
CurrentCoordinatedTransactionState = COORD_TRANS_STARTED;
|
|
||||||
|
|
||||||
AssignDistributedTransactionId();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Transaction management callback, handling coordinated transaction, and
|
* Transaction management callback, handling coordinated transaction, and
|
||||||
* transaction independent connection management.
|
* transaction independent connection management.
|
||||||
|
|
|
@ -89,7 +89,7 @@ SendCommandToWorkerAsUser(char *nodeName, int32 nodePort, const char *nodeUser,
|
||||||
{
|
{
|
||||||
uint connectionFlags = 0;
|
uint connectionFlags = 0;
|
||||||
|
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
CoordinatedTransactionUse2PC();
|
CoordinatedTransactionUse2PC();
|
||||||
|
|
||||||
MultiConnection *transactionConnection = GetNodeUserDatabaseConnection(
|
MultiConnection *transactionConnection = GetNodeUserDatabaseConnection(
|
||||||
|
@ -279,7 +279,7 @@ SendCommandToWorkersParamsInternal(TargetWorkerSet targetWorkerSet, const char *
|
||||||
List *workerNodeList = TargetWorkerSetNodeList(targetWorkerSet, ShareLock);
|
List *workerNodeList = TargetWorkerSetNodeList(targetWorkerSet, ShareLock);
|
||||||
ListCell *workerNodeCell = NULL;
|
ListCell *workerNodeCell = NULL;
|
||||||
|
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
CoordinatedTransactionUse2PC();
|
CoordinatedTransactionUse2PC();
|
||||||
|
|
||||||
/* open connections in parallel */
|
/* open connections in parallel */
|
||||||
|
|
|
@ -197,7 +197,7 @@ LockShardListResourcesOnFirstWorker(LOCKMODE lockmode, List *shardIntervalList)
|
||||||
appendStringInfo(lockCommand, "])");
|
appendStringInfo(lockCommand, "])");
|
||||||
|
|
||||||
/* need to hold the lock until commit */
|
/* need to hold the lock until commit */
|
||||||
BeginOrContinueCoordinatedTransaction();
|
UseCoordinatedTransaction();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use the superuser connection to make sure we are allowed to lock.
|
* Use the superuser connection to make sure we are allowed to lock.
|
||||||
|
|
|
@ -106,7 +106,7 @@ extern StringInfo activeSetStmts;
|
||||||
/*
|
/*
|
||||||
* Coordinated transaction management.
|
* Coordinated transaction management.
|
||||||
*/
|
*/
|
||||||
extern void BeginOrContinueCoordinatedTransaction(void);
|
extern void UseCoordinatedTransaction(void);
|
||||||
extern bool InCoordinatedTransaction(void);
|
extern bool InCoordinatedTransaction(void);
|
||||||
extern void CoordinatedTransactionUse2PC(void);
|
extern void CoordinatedTransactionUse2PC(void);
|
||||||
extern bool IsMultiStatementTransaction(void);
|
extern bool IsMultiStatementTransaction(void);
|
||||||
|
|
Loading…
Reference in New Issue