@@ -127,7 +127,7 @@ static void MtmAddSubtransactions(MtmTransState* ts, TransactionId *subxids, int
127
127
static void MtmShmemStartup (void );
128
128
129
129
static BgwPool * MtmPoolConstructor (void );
130
- static bool MtmRunUtilityStmt (PGconn * conn , char const * sql );
130
+ static bool MtmRunUtilityStmt (PGconn * conn , char const * sql , char * * errmsg );
131
131
static void MtmBroadcastUtilityStmt (char const * sql , bool ignoreError );
132
132
133
133
MtmState * Mtm ;
@@ -1793,14 +1793,24 @@ mtm_get_cluster_state(PG_FUNCTION_ARGS)
1793
1793
/*
1794
1794
* Execute statement with specified parameters and check its result
1795
1795
*/
1796
- static bool MtmRunUtilityStmt (PGconn * conn , char const * sql )
1796
+ static bool MtmRunUtilityStmt (PGconn * conn , char const * sql , char * * errmsg )
1797
1797
{
1798
1798
PGresult * result = PQexec (conn , sql );
1799
1799
int status = PQresultStatus (result );
1800
+ char * errstr ;
1801
+
1800
1802
bool ret = status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK ;
1801
- if (!ret ) {
1802
- elog (WARNING , "Command '%s' failed with status %d" , sql , status );
1803
+
1804
+ if (!ret ) {
1805
+ char * errstr = PQresultErrorMessage (result );
1806
+ int errlen = strlen (errstr );
1807
+
1808
+ * errmsg = palloc0 (errlen );
1809
+
1810
+ /* Strip "ERROR:\t" from beginning and "\n" from end of error string */
1811
+ strncpy (* errmsg , errstr + 7 , errlen - 1 - 7 );
1803
1812
}
1813
+
1804
1814
PQclear (result );
1805
1815
return ret ;
1806
1816
}
@@ -1814,6 +1824,7 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
1814
1824
int failedNode = -1 ;
1815
1825
char const * errorMsg = NULL ;
1816
1826
PGconn * * conns = palloc0 (sizeof (PGconn * )* MtmNodes );
1827
+ char * utility_errmsg ;
1817
1828
1818
1829
while (conn_str < conn_str_end )
1819
1830
{
@@ -1849,15 +1860,18 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
1849
1860
{
1850
1861
if (conns [i ])
1851
1862
{
1852
- if (!MtmRunUtilityStmt (conns [i ], "BEGIN TRANSACTION" ) && !ignoreError )
1863
+ if (!MtmRunUtilityStmt (conns [i ], "BEGIN TRANSACTION" , & utility_errmsg ) && !ignoreError )
1853
1864
{
1854
1865
errorMsg = "Failed to start transaction at node %d" ;
1855
1866
failedNode = i ;
1856
1867
break ;
1857
1868
}
1858
- if (!MtmRunUtilityStmt (conns [i ], sql ) && !ignoreError )
1869
+ if (!MtmRunUtilityStmt (conns [i ], sql , & utility_errmsg ) && !ignoreError )
1859
1870
{
1860
- errorMsg = "Failed to run command at node %d" ;
1871
+ // errorMsg = "Failed to run command at node %d";
1872
+ // XXX: add check for our node
1873
+ errorMsg = utility_errmsg ;
1874
+
1861
1875
failedNode = i ;
1862
1876
break ;
1863
1877
}
@@ -1869,13 +1883,13 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
1869
1883
{
1870
1884
if (conns [i ])
1871
1885
{
1872
- MtmRunUtilityStmt (conns [i ], "ROLLBACK TRANSACTION" );
1886
+ MtmRunUtilityStmt (conns [i ], "ROLLBACK TRANSACTION" , & utility_errmsg );
1873
1887
}
1874
1888
}
1875
1889
} else {
1876
1890
for (i = 0 ; i < MtmNodes ; i ++ )
1877
1891
{
1878
- if (conns [i ] && !MtmRunUtilityStmt (conns [i ], "COMMIT TRANSACTION" ) && !ignoreError )
1892
+ if (conns [i ] && !MtmRunUtilityStmt (conns [i ], "COMMIT TRANSACTION" , & utility_errmsg ) && !ignoreError )
1879
1893
{
1880
1894
errorMsg = "Commit failed at node %d" ;
1881
1895
failedNode = i ;
@@ -1958,7 +1972,7 @@ static bool MtmTwoPhaseCommit(MtmCurrentTrans* x)
1958
1972
if (!x -> isReplicated && (x -> isDistributed && x -> containsDML )) {
1959
1973
MtmGenerateGid (x -> gid );
1960
1974
if (!x -> isTransactionBlock ) {
1961
- elog (WARNING , "Start transaction block for %s" , x -> gid );
1975
+ /* elog(WARNING, "Start transaction block for %s", x->gid); */
1962
1976
BeginTransactionBlock ();
1963
1977
x -> isTransactionBlock = true;
1964
1978
CommitTransactionCommand ();
@@ -2054,6 +2068,13 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
2054
2068
case T_ReindexStmt :
2055
2069
skipCommand = true;
2056
2070
break ;
2071
+ case T_CreateStmt :
2072
+ {
2073
+ /* Do not replicate temp tables */
2074
+ CreateStmt * stmt = (CreateStmt * ) parsetree ;
2075
+ skipCommand = stmt -> relation -> relpersistence == RELPERSISTENCE_TEMP ;
2076
+ }
2077
+ break ;
2057
2078
default :
2058
2079
skipCommand = false;
2059
2080
break ;
0 commit comments