@@ -127,7 +127,7 @@ static void MtmAddSubtransactions(MtmTransState* ts, TransactionId *subxids, int
127127static void MtmShmemStartup (void );
128128
129129static BgwPool * MtmPoolConstructor (void );
130- static bool MtmRunUtilityStmt (PGconn * conn , char const * sql );
130+ static bool MtmRunUtilityStmt (PGconn * conn , char const * sql , char * * errmsg );
131131static void MtmBroadcastUtilityStmt (char const * sql , bool ignoreError );
132132
133133MtmState * Mtm ;
@@ -1793,14 +1793,24 @@ mtm_get_cluster_state(PG_FUNCTION_ARGS)
17931793/*
17941794 * Execute statement with specified parameters and check its result
17951795 */
1796- static bool MtmRunUtilityStmt (PGconn * conn , char const * sql )
1796+ static bool MtmRunUtilityStmt (PGconn * conn , char const * sql , char * * errmsg )
17971797{
17981798 PGresult * result = PQexec (conn , sql );
17991799 int status = PQresultStatus (result );
1800+ char * errstr ;
1801+
18001802 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 );
18031812 }
1813+
18041814 PQclear (result );
18051815 return ret ;
18061816}
@@ -1814,6 +1824,7 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
18141824 int failedNode = -1 ;
18151825 char const * errorMsg = NULL ;
18161826 PGconn * * conns = palloc0 (sizeof (PGconn * )* MtmNodes );
1827+ char * utility_errmsg ;
18171828
18181829 while (conn_str < conn_str_end )
18191830 {
@@ -1849,15 +1860,18 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
18491860 {
18501861 if (conns [i ])
18511862 {
1852- if (!MtmRunUtilityStmt (conns [i ], "BEGIN TRANSACTION" ) && !ignoreError )
1863+ if (!MtmRunUtilityStmt (conns [i ], "BEGIN TRANSACTION" , & utility_errmsg ) && !ignoreError )
18531864 {
18541865 errorMsg = "Failed to start transaction at node %d" ;
18551866 failedNode = i ;
18561867 break ;
18571868 }
1858- if (!MtmRunUtilityStmt (conns [i ], sql ) && !ignoreError )
1869+ if (!MtmRunUtilityStmt (conns [i ], sql , & utility_errmsg ) && !ignoreError )
18591870 {
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+
18611875 failedNode = i ;
18621876 break ;
18631877 }
@@ -1869,13 +1883,13 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
18691883 {
18701884 if (conns [i ])
18711885 {
1872- MtmRunUtilityStmt (conns [i ], "ROLLBACK TRANSACTION" );
1886+ MtmRunUtilityStmt (conns [i ], "ROLLBACK TRANSACTION" , & utility_errmsg );
18731887 }
18741888 }
18751889 } else {
18761890 for (i = 0 ; i < MtmNodes ; i ++ )
18771891 {
1878- if (conns [i ] && !MtmRunUtilityStmt (conns [i ], "COMMIT TRANSACTION" ) && !ignoreError )
1892+ if (conns [i ] && !MtmRunUtilityStmt (conns [i ], "COMMIT TRANSACTION" , & utility_errmsg ) && !ignoreError )
18791893 {
18801894 errorMsg = "Commit failed at node %d" ;
18811895 failedNode = i ;
@@ -1958,7 +1972,7 @@ static bool MtmTwoPhaseCommit(MtmCurrentTrans* x)
19581972 if (!x -> isReplicated && (x -> isDistributed && x -> containsDML )) {
19591973 MtmGenerateGid (x -> gid );
19601974 if (!x -> isTransactionBlock ) {
1961- elog (WARNING , "Start transaction block for %s" , x -> gid );
1975+ /* elog(WARNING, "Start transaction block for %s", x->gid); */
19621976 BeginTransactionBlock ();
19631977 x -> isTransactionBlock = true;
19641978 CommitTransactionCommand ();
@@ -2054,6 +2068,13 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
20542068 case T_ReindexStmt :
20552069 skipCommand = true;
20562070 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 ;
20572078 default :
20582079 skipCommand = false;
20592080 break ;
0 commit comments