Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 16df7ec

Browse files
committed
do not replicate temp tables; return fixed error message
1 parent 32297b0 commit 16df7ec

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

multimaster.c

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void MtmAddSubtransactions(MtmTransState* ts, TransactionId *subxids, int
126126
static void MtmShmemStartup(void);
127127

128128
static BgwPool* MtmPoolConstructor(void);
129-
static bool MtmRunUtilityStmt(PGconn* conn, char const* sql);
129+
static bool MtmRunUtilityStmt(PGconn* conn, char const* sql, char **errmsg);
130130
static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError);
131131

132132
MtmState* Mtm;
@@ -1791,14 +1791,24 @@ mtm_get_cluster_state(PG_FUNCTION_ARGS)
17911791
/*
17921792
* Execute statement with specified parameters and check its result
17931793
*/
1794-
static bool MtmRunUtilityStmt(PGconn* conn, char const* sql)
1794+
static bool MtmRunUtilityStmt(PGconn* conn, char const* sql, char **errmsg)
17951795
{
17961796
PGresult *result = PQexec(conn, sql);
17971797
int status = PQresultStatus(result);
1798+
char *errstr;
1799+
17981800
bool ret = status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK;
1799-
if (!ret) {
1800-
elog(WARNING, "Command '%s' failed with status %d", sql, status);
1801+
1802+
if (!ret) {
1803+
char *errstr = PQresultErrorMessage(result);
1804+
int errlen = strlen(errstr);
1805+
1806+
*errmsg = palloc0(errlen);
1807+
1808+
/* Strip "ERROR:\t" from beginning and "\n" from end of error string */
1809+
strncpy(*errmsg, errstr + 7, errlen - 1 - 7);
18011810
}
1811+
18021812
PQclear(result);
18031813
return ret;
18041814
}
@@ -1812,6 +1822,7 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
18121822
int failedNode = -1;
18131823
char const* errorMsg = NULL;
18141824
PGconn **conns = palloc0(sizeof(PGconn*)*MtmNodes);
1825+
char* utility_errmsg;
18151826

18161827
while (conn_str < conn_str_end)
18171828
{
@@ -1847,15 +1858,18 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
18471858
{
18481859
if (conns[i])
18491860
{
1850-
if (!MtmRunUtilityStmt(conns[i], "BEGIN TRANSACTION") && !ignoreError)
1861+
if (!MtmRunUtilityStmt(conns[i], "BEGIN TRANSACTION", &utility_errmsg) && !ignoreError)
18511862
{
18521863
errorMsg = "Failed to start transaction at node %d";
18531864
failedNode = i;
18541865
break;
18551866
}
1856-
if (!MtmRunUtilityStmt(conns[i], sql) && !ignoreError)
1867+
if (!MtmRunUtilityStmt(conns[i], sql, &utility_errmsg) && !ignoreError)
18571868
{
1858-
errorMsg = "Failed to run command at node %d";
1869+
// errorMsg = "Failed to run command at node %d";
1870+
// XXX: add check for our node
1871+
errorMsg = utility_errmsg;
1872+
18591873
failedNode = i;
18601874
break;
18611875
}
@@ -1867,13 +1881,13 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
18671881
{
18681882
if (conns[i])
18691883
{
1870-
MtmRunUtilityStmt(conns[i], "ROLLBACK TRANSACTION");
1884+
MtmRunUtilityStmt(conns[i], "ROLLBACK TRANSACTION", &utility_errmsg);
18711885
}
18721886
}
18731887
} else {
18741888
for (i = 0; i < MtmNodes; i++)
18751889
{
1876-
if (conns[i] && !MtmRunUtilityStmt(conns[i], "COMMIT TRANSACTION") && !ignoreError)
1890+
if (conns[i] && !MtmRunUtilityStmt(conns[i], "COMMIT TRANSACTION", &utility_errmsg) && !ignoreError)
18771891
{
18781892
errorMsg = "Commit failed at node %d";
18791893
failedNode = i;
@@ -1955,8 +1969,8 @@ static bool MtmTwoPhaseCommit(MtmCurrentTrans* x)
19551969
{
19561970
if (x->isDistributed && x->containsDML) {
19571971
MtmGenerateGid(x->gid);
1958-
if (!IsTransactionBlock()) {
1959-
elog(WARNING, "Start transaction block for %d", x->xid);
1972+
if (!x->isTransactionBlock) {
1973+
/* elog(WARNING, "Start transaction block for %s", x->gid); */
19601974
BeginTransactionBlock();
19611975
CommitTransactionCommand();
19621976
StartTransactionCommand();
@@ -2048,6 +2062,13 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
20482062
case T_ReindexStmt:
20492063
skipCommand = true;
20502064
break;
2065+
case T_CreateStmt:
2066+
{
2067+
/* Do not replicate temp tables */
2068+
CreateStmt *stmt = (CreateStmt *) parsetree;
2069+
skipCommand = stmt->relation->relpersistence == RELPERSISTENCE_TEMP;
2070+
}
2071+
break;
20512072
default:
20522073
skipCommand = false;
20532074
break;

0 commit comments

Comments
 (0)