diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index c8751c6..5ca7375 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -115,6 +115,10 @@ TransactionId *ParallelCurrentXids; * globally accessible, so can be set from anywhere in the code that requires * recording flags. */ +bool MyXactAccessedTempRel = false; + +/* Transaction do the write on local node */ +bool XactWriteLocalNode = false; int MyXactFlags; /* @@ -2160,6 +2164,8 @@ CommitTransaction(void) XactTopTransactionId = InvalidTransactionId; nParallelCurrentXids = 0; + UnregisterTransactionLocalNode(); + /* * done with commit processing, set current transaction state back to * default @@ -2431,6 +2437,8 @@ PrepareTransaction(void) XactTopTransactionId = InvalidTransactionId; nParallelCurrentXids = 0; + UnregisterTransactionLocalNode(); + /* * done with 1st phase commit processing, set current transaction state * back to default @@ -2615,6 +2623,8 @@ AbortTransaction(void) pgstat_report_xact_timestamp(0); } + UnregisterTransactionLocalNode(); + /* * State remains TRANS_ABORT until CleanupTransaction(). */ @@ -4298,6 +4308,24 @@ AbortOutOfAnyTransaction(void) } /* + * RegisterTransactionLocalNode --- remember to wrote on local node + */ +void +RegisterTransactionLocalNode(void) +{ + XactWriteLocalNode = true; +} + +/* + * UnregisterTransactionLocalNode --- forget to wrote on local node + */ +void +UnregisterTransactionLocalNode(void) +{ + XactWriteLocalNode = false; +} + +/* * IsTransactionBlock --- are we within a transaction block? */ bool diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 0b524e0..661a82b 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -437,6 +437,9 @@ ExecInsert(ModifyTableState *mtstate, if (resultRelationDesc->rd_att->constr || resultRelInfo->ri_PartitionCheck) ExecConstraints(resultRelInfo, slot, oldslot, estate); + /* Remember to wrote on local node for foreign transaction */ + RegisterTransactionLocalNode(); + if (onconflict != ONCONFLICT_NONE && resultRelInfo->ri_NumIndices > 0) { /* Perform a speculative insertion. */ @@ -698,6 +701,9 @@ ExecDelete(ItemPointer tupleid, } else { + /* Remember to wrote on local node for foreign transaction */ + RegisterTransactionLocalNode(); + /* * delete the tuple * @@ -995,6 +1001,9 @@ lreplace:; if (resultRelationDesc->rd_att->constr || resultRelInfo->ri_PartitionCheck) ExecConstraints(resultRelInfo, slot, slot, estate); + /* Remember to wrote on local node for foreign transaction */ + RegisterTransactionLocalNode(); + /* * replace the heap tuple * diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 5b37c05..aee1a07 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -376,6 +376,8 @@ extern void RegisterXactCallback(XactCallback callback, void *arg); extern void UnregisterXactCallback(XactCallback callback, void *arg); extern void RegisterSubXactCallback(SubXactCallback callback, void *arg); extern void UnregisterSubXactCallback(SubXactCallback callback, void *arg); +extern void RegisterTransactionLocalNode(void); +extern void UnregisterTransactionLocalNode(void); extern int xactGetCommittedChildren(TransactionId **ptr);