@@ -180,6 +180,8 @@ static bool MtmRunUtilityStmt(PGconn* conn, char const* sql, char **errmsg);
180
180
static void MtmBroadcastUtilityStmt (char const * sql , bool ignoreError , int forceOnNode );
181
181
static void MtmProcessDDLCommand (char const * queryString , bool transactional );
182
182
183
+ static int MtmGidParseNodeId (const char * gid );
184
+
183
185
// static void MtmLockCluster(void);
184
186
// static void MtmUnlockCluster(void);
185
187
@@ -1060,6 +1062,8 @@ MtmCreateTransState(MtmCurrentTrans* x)
1060
1062
}
1061
1063
strcpy (ts -> gid , x -> gid );
1062
1064
x -> isActive = true;
1065
+
1066
+ Assert (ts -> gid [0 ] == '\0' || MtmGidParseNodeId (ts -> gid ) == ts -> gtid .node );
1063
1067
return ts ;
1064
1068
}
1065
1069
@@ -1807,7 +1811,7 @@ static void MtmLoadPreparedTransactions(void)
1807
1811
if (!found || tm -> state == NULL ) {
1808
1812
TransactionId xid = GetNewTransactionId (false);
1809
1813
MtmTransState * ts = (MtmTransState * )hash_search (MtmXid2State , & xid , HASH_ENTER , & found );
1810
- MTM_LOG1 ("Recover prepared transaction %s (%llu) state=%s" , gid , (long64 )xid , pxacts [i ].state_3pc );
1814
+ MTM_LOG1 ("Load prepared transaction %s (%llu) state=%s" , gid , (long64 )xid , pxacts [i ].state_3pc );
1811
1815
MyPgXact -> xid = InvalidTransactionId ; /* dirty hack:((( */
1812
1816
Assert (!found );
1813
1817
ts -> isEnqueued = false;
@@ -1820,7 +1824,7 @@ static void MtmLoadPreparedTransactions(void)
1820
1824
ts -> snapshot = INVALID_CSN ;
1821
1825
ts -> isTwoPhase = false;
1822
1826
ts -> csn = 0 ; /* should be replaced with real CSN by poll result */
1823
- ts -> gtid .node = MtmNodeId ;
1827
+ ts -> gtid .node = MtmGidParseNodeId ( gid ) ;
1824
1828
ts -> gtid .xid = xid ;
1825
1829
ts -> nSubxids = 0 ;
1826
1830
ts -> votingCompleted = true;
@@ -1911,6 +1915,7 @@ void MtmSetCurrentTransactionGID(char const* gid)
1911
1915
strcpy (MtmTx .gid , gid );
1912
1916
MtmTx .isDistributed = true;
1913
1917
MtmTx .isReplicated = true;
1918
+ MtmTx .gtid .node = MtmGidParseNodeId (gid );
1914
1919
}
1915
1920
1916
1921
TransactionId MtmGetCurrentTransactionId (void )
@@ -2066,6 +2071,8 @@ void MtmPollStatusOfPreparedTransactionsForDisabledNode(int disabledNodeId, bool
2066
2071
&& (ts -> status == TRANSACTION_STATUS_UNKNOWN || ts -> status == TRANSACTION_STATUS_IN_PROGRESS ))
2067
2072
{
2068
2073
Assert (ts -> gid [0 ]);
2074
+ Assert (MtmGidParseNodeId (ts -> gid ) == ts -> gtid .node );
2075
+
2069
2076
if (ts -> status == TRANSACTION_STATUS_IN_PROGRESS ) {
2070
2077
MTM_ELOG (LOG , "Abort transaction %s because its coordinator is disabled and it is not prepared at node %d" , ts -> gid , MtmNodeId );
2071
2078
TXFINISH ("%s ABORT, PollStatusOfPrepared" , ts -> gid );
@@ -2119,6 +2126,7 @@ MtmPollStatusOfPreparedTransactions(bool majorMode)
2119
2126
&& (ts -> status == TRANSACTION_STATUS_UNKNOWN || ts -> status == TRANSACTION_STATUS_IN_PROGRESS ))
2120
2127
{
2121
2128
Assert (ts -> gid [0 ]);
2129
+ Assert (MtmGidParseNodeId (ts -> gid ) == ts -> gtid .node );
2122
2130
2123
2131
if (majorMode )
2124
2132
{
@@ -2130,7 +2138,7 @@ MtmPollStatusOfPreparedTransactions(bool majorMode)
2130
2138
// MtmBroadcastPollMessage(ts);
2131
2139
if (ts -> gtid .node == MtmNodeId && !ts -> isPrepared )
2132
2140
{
2133
- MTM_LOG1 ("Abort our in-progress transaction %s" , ts -> gid );
2141
+ MTM_LOG1 ("Abort our in-progress transaction %s (%d, %d) " , ts -> gid , ts -> gtid . node , MtmNodeId );
2134
2142
MtmFinishPreparedTransaction (ts , false);
2135
2143
}
2136
2144
else
@@ -4756,6 +4764,15 @@ MtmGenerateGid(char* gid)
4756
4764
{
4757
4765
static int localCount ;
4758
4766
sprintf (gid , "MTM-%d-%d-%d-" INT64_FORMAT , MtmNodeId , MyProcPid , ++ localCount , (int64 ) GetCurrentTimestamp ());
4767
+ // MTM_LOG1("MtmGenerateGid: %s", gid);
4768
+ }
4769
+
4770
+ static int
4771
+ MtmGidParseNodeId (const char * gid )
4772
+ {
4773
+ int MtmNodeId ;
4774
+ sscanf (gid , "MTM-%d-%*d-%*d-%*d" , & MtmNodeId );
4775
+ return MtmNodeId ;
4759
4776
}
4760
4777
4761
4778
/*
0 commit comments