提交 49fc2332 编写于 作者: A Asim R P 提交者: Asim RP

Let dispatcher raise error when a DTM broadcast fails

There already is a PG_TRY() ... PG_CATCH() block to handle such errors
in the DTM retry logic.  This change makes it easier to test the error
handling in the retry logic.

The patch also fixes a bug in dispatcher that invoked CopyErrorData
interface incorrectly, without switching to a memory context other that
ErrorContext.
上级 cbee6d14
...@@ -791,7 +791,7 @@ doNotifyingCommitPrepared(void) ...@@ -791,7 +791,7 @@ doNotifyingCommitPrepared(void)
{ {
succeeded = doDispatchDtxProtocolCommand(DTX_PROTOCOL_COMMAND_COMMIT_PREPARED, /* flags */ 0, succeeded = doDispatchDtxProtocolCommand(DTX_PROTOCOL_COMMAND_COMMIT_PREPARED, /* flags */ 0,
currentGxact->gid, currentGxact->gxid, currentGxact->gid, currentGxact->gxid,
&badGangs, /* raiseError */ false, &badGangs, /* raiseError */ true,
&direct, NULL, 0); &direct, NULL, 0);
} }
PG_CATCH(); PG_CATCH();
...@@ -839,7 +839,7 @@ doNotifyingCommitPrepared(void) ...@@ -839,7 +839,7 @@ doNotifyingCommitPrepared(void)
succeeded = doDispatchDtxProtocolCommand( succeeded = doDispatchDtxProtocolCommand(
DTX_PROTOCOL_COMMAND_RETRY_COMMIT_PREPARED, /* flags */ 0, DTX_PROTOCOL_COMMAND_RETRY_COMMIT_PREPARED, /* flags */ 0,
currentGxact->gid, currentGxact->gxid, currentGxact->gid, currentGxact->gxid,
&badGangs, /* raiseError */ false, &badGangs, /* raiseError */ true,
&direct, NULL, 0); &direct, NULL, 0);
} }
PG_CATCH(); PG_CATCH();
......
...@@ -557,6 +557,15 @@ cdbdisp_dumpDispatchResult(CdbDispatchResult *dispatchResult) ...@@ -557,6 +557,15 @@ cdbdisp_dumpDispatchResult(CdbDispatchResult *dispatchResult)
return NULL; return NULL;
} }
/*
* The returned error object is allocated in TopTransactionContext.
*
* Caution: do not use the returned object across transaction boundary.
* Current usages of this API are such that the returned object is either
* logged using elog() or rethrown, both within a transaction context, at the
* time of finishing a dispatched command. The caution applies to future uses
* of this function.
*/
ErrorData * ErrorData *
cdbdisp_get_PQerror(PGresult *pgresult) cdbdisp_get_PQerror(PGresult *pgresult)
{ {
...@@ -633,7 +642,11 @@ cdbdisp_get_PQerror(PGresult *pgresult) ...@@ -633,7 +642,11 @@ cdbdisp_get_PQerror(PGresult *pgresult)
if (fld) if (fld)
errcontext("%s", fld); errcontext("%s", fld);
return errfinish_and_return(0); Assert(TopTransactionContext);
MemoryContext oldcontext = MemoryContextSwitchTo(TopTransactionContext);
ErrorData *edata = errfinish_and_return(0);
MemoryContextSwitchTo(oldcontext);
return edata;
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册