@@ -64,6 +64,7 @@ typedef struct {
64
64
bool isReplicated ;/* transaction on replica */
65
65
bool isDistributed ;/* transaction performed INSERT/UPDATE/DELETE and has to be replicated to other nodes */
66
66
bool isPrepared ;/* transaction is perpared at first stage of 2PC */
67
+ bool isTransactionBlock ;/* is transaction block */
67
68
bool containsDML ;/* transaction contains DML statements */
68
69
XidStatus status ;/* transaction status */
69
70
csn_t snapshot ;/* transaction snaphsot */
@@ -590,7 +591,7 @@ MtmXactCallback(XactEvent event, void *arg)
590
591
MtmEndTransaction (& MtmTx , false);
591
592
break ;
592
593
case XACT_EVENT_COMMIT_COMMAND :
593
- if (!IsTransactionBlock () ) {
594
+ if (!MtmTx . isTransactionBlock ) {
594
595
MtmTwoPhaseCommit (& MtmTx );
595
596
}
596
597
break ;
@@ -629,6 +630,7 @@ MtmBeginTransaction(MtmCurrentTrans* x)
629
630
x -> isReplicated = false;
630
631
x -> isDistributed = MtmIsUserTransaction ();
631
632
x -> isPrepared = false;
633
+ x -> isTransactionBlock = IsTransactionBlock ();
632
634
if (x -> isDistributed && Mtm -> status != MTM_ONLINE ) {
633
635
/* reject all user's transactions at offline cluster */
634
636
MtmUnlock ();
@@ -1930,19 +1932,20 @@ MtmGenerateGid(char* gid)
1930
1932
1931
1933
static bool MtmTwoPhaseCommit (MtmCurrentTrans * x )
1932
1934
{
1933
- if (x -> isDistributed && x -> containsDML ) {
1935
+ if (! x -> isReplicated && ( x -> isDistributed && x -> containsDML ) ) {
1934
1936
MtmGenerateGid (x -> gid );
1935
- if (!IsTransactionBlock () ) {
1936
- elog (WARNING ,"Start transaction block for %d " ,x -> xid );
1937
+ if (!x -> isTransactionBlock ) {
1938
+ elog (WARNING ,"Start transaction block for %s " ,x -> gid );
1937
1939
BeginTransactionBlock ();
1940
+ x -> isTransactionBlock = true;
1938
1941
CommitTransactionCommand ();
1939
1942
StartTransactionCommand ();
1940
1943
}
1941
1944
if (!PrepareTransactionBlock (x -> gid ))
1942
1945
{
1943
1946
elog (WARNING ,"Failed to prepare transaction %s" ,x -> gid );
1944
1947
/* ??? Should we do explicit rollback */
1945
- }else {
1948
+ }else {
1946
1949
CommitTransactionCommand ();
1947
1950
StartTransactionCommand ();
1948
1951
if (MtmGetCurrentTransactionStatus ()== TRANSACTION_STATUS_ABORTED ) {
@@ -1970,8 +1973,11 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
1970
1973
TransactionStmt * stmt = (TransactionStmt * )parsetree ;
1971
1974
switch (stmt -> kind )
1972
1975
{
1976
+ case TRANS_STMT_BEGIN :
1977
+ MtmTx .isTransactionBlock = true;
1978
+ break ;
1973
1979
case TRANS_STMT_COMMIT :
1974
- if (MtmTwoPhaseCommit (& MtmTx )) {
1980
+ if (MtmTwoPhaseCommit (& MtmTx )) {
1975
1981
return ;
1976
1982
}
1977
1983
break ;
@@ -2036,9 +2042,6 @@ MtmExecutorFinish(QueryDesc *queryDesc)
2036
2042
}
2037
2043
}
2038
2044
}
2039
- if (MtmTx .isDistributed && MtmTx .containsDML && !IsTransactionBlock ()) {
2040
- MtmTwoPhaseCommit (& MtmTx );
2041
- }
2042
2045
}
2043
2046
if (PreviousExecutorFinishHook != NULL )
2044
2047
{