mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Support frontend-backend protocol communication using a shm_mq.
A background worker can use pq_redirect_to_shm_mq() to direct protocol that would normally be sent to the frontend to a shm_mq so that another process may read them. The receiving process may use pq_parse_errornotice() to parse an ErrorResponse or NoticeResponse from the background worker and, if it wishes, ThrowErrorData() to propagate the error (with or without further modification). Patch by me. Review by Andres Freund.
This commit is contained in:
@@ -1576,6 +1576,57 @@ FlushErrorState(void)
|
||||
MemoryContextResetAndDeleteChildren(ErrorContext);
|
||||
}
|
||||
|
||||
/*
|
||||
* ThrowErrorData --- report an error described by an ErrorData structure
|
||||
*
|
||||
* This is intended to be used to re-report errors originally thrown by
|
||||
* background worker processes and then propagated (with or without
|
||||
* modification) to the backend responsible for them.
|
||||
*/
|
||||
void
|
||||
ThrowErrorData(ErrorData *edata)
|
||||
{
|
||||
ErrorData *newedata;
|
||||
MemoryContext oldcontext;
|
||||
|
||||
if (!errstart(edata->elevel, edata->filename, edata->lineno,
|
||||
edata->funcname, NULL))
|
||||
return;
|
||||
|
||||
newedata = &errordata[errordata_stack_depth];
|
||||
oldcontext = MemoryContextSwitchTo(edata->assoc_context);
|
||||
|
||||
/* Copy the supplied fields to the error stack. */
|
||||
if (edata->sqlerrcode > 0)
|
||||
newedata->sqlerrcode = edata->sqlerrcode;
|
||||
if (edata->message)
|
||||
newedata->message = pstrdup(edata->message);
|
||||
if (edata->detail)
|
||||
newedata->detail = pstrdup(edata->detail);
|
||||
if (edata->detail_log)
|
||||
newedata->detail_log = pstrdup(edata->detail_log);
|
||||
if (edata->hint)
|
||||
newedata->hint = pstrdup(edata->hint);
|
||||
if (edata->context)
|
||||
newedata->context = pstrdup(edata->context);
|
||||
if (edata->schema_name)
|
||||
newedata->schema_name = pstrdup(edata->schema_name);
|
||||
if (edata->table_name)
|
||||
newedata->table_name = pstrdup(edata->table_name);
|
||||
if (edata->column_name)
|
||||
newedata->column_name = pstrdup(edata->column_name);
|
||||
if (edata->datatype_name)
|
||||
newedata->datatype_name = pstrdup(edata->datatype_name);
|
||||
if (edata->constraint_name)
|
||||
newedata->constraint_name = pstrdup(edata->constraint_name);
|
||||
if (edata->internalquery)
|
||||
newedata->internalquery = pstrdup(edata->internalquery);
|
||||
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
|
||||
errfinish(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* ReThrowError --- re-throw a previously copied error
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user