aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/parallel.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-08-26 10:07:28 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-08-26 10:07:28 -0400
commitfbf28b6b52c269188262a87247adb2c359acd6c5 (patch)
treea97d45be7b437ee563cee88b42f589cd11104c11 /src/backend/access/transam/parallel.c
parentae025a15988f5491903cd3a2075f308c2773f711 (diff)
downloadpostgresql-fbf28b6b52c269188262a87247adb2c359acd6c5.tar.gz
postgresql-fbf28b6b52c269188262a87247adb2c359acd6c5.zip
Fix logic for adding "parallel worker" context line to worker errors.
The previous coding here was capable of adding a "parallel worker" context line to errors that were not, in fact, returned from a parallel worker. Instead of using an errcontext callback to add that annotation, just paste it onto the message by hand; this looks uglier but is more reliable. Discussion: <19757.1472151987@sss.pgh.pa.us>
Diffstat (limited to 'src/backend/access/transam/parallel.c')
-rw-r--r--src/backend/access/transam/parallel.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index a47eba647bc..ec6e1c5e6dc 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -108,7 +108,6 @@ static dlist_head pcxt_list = DLIST_STATIC_INIT(pcxt_list);
/* Private functions. */
static void HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg);
-static void ParallelErrorContext(void *arg);
static void ParallelExtensionTrampoline(dsm_segment *seg, shm_toc *toc);
static void ParallelWorkerMain(Datum main_arg);
static void WaitForParallelWorkersToExit(ParallelContext *pcxt);
@@ -788,30 +787,43 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
case 'N': /* NoticeResponse */
{
ErrorData edata;
- ErrorContextCallback errctx;
ErrorContextCallback *save_error_context_stack;
- /*
- * Rethrow the error using the error context callbacks that
- * were in effect when the context was created, not the
- * current ones.
- */
- save_error_context_stack = error_context_stack;
- errctx.callback = ParallelErrorContext;
- errctx.arg = NULL;
- errctx.previous = pcxt->error_context_stack;
- error_context_stack = &errctx;
-
/* Parse ErrorResponse or NoticeResponse. */
pq_parse_errornotice(msg, &edata);
/* Death of a worker isn't enough justification for suicide. */
edata.elevel = Min(edata.elevel, ERROR);
- /* Rethrow error or notice. */
+ /*
+ * If desired, add a context line to show that this is a
+ * message propagated from a parallel worker. Otherwise, it
+ * can sometimes be confusing to understand what actually
+ * happened. (We don't do this in FORCE_PARALLEL_REGRESS mode
+ * because it causes test-result instability depending on
+ * whether a parallel worker is actually used or not.)
+ */
+ if (force_parallel_mode != FORCE_PARALLEL_REGRESS)
+ {
+ if (edata.context)
+ edata.context = psprintf("%s\n%s", edata.context,
+ _("parallel worker"));
+ else
+ edata.context = pstrdup(_("parallel worker"));
+ }
+
+ /*
+ * Context beyond that should use the error context callbacks
+ * that were in effect when the ParallelContext was created,
+ * not the current ones.
+ */
+ save_error_context_stack = error_context_stack;
+ error_context_stack = pcxt->error_context_stack;
+
+ /* Rethrow error or print notice. */
ThrowErrorData(&edata);
- /* Restore previous context. */
+ /* Not an error, so restore previous context stack. */
error_context_stack = save_error_context_stack;
break;
@@ -1113,18 +1125,6 @@ ParallelExtensionTrampoline(dsm_segment *seg, shm_toc *toc)
}
/*
- * Give the user a hint that this is a message propagated from a parallel
- * worker. Otherwise, it can sometimes be confusing to understand what
- * actually happened.
- */
-static void
-ParallelErrorContext(void *arg)
-{
- if (force_parallel_mode != FORCE_PARALLEL_REGRESS)
- errcontext("parallel worker");
-}
-
-/*
* Update shared memory with the ending location of the last WAL record we
* wrote, if it's greater than the value already stored there.
*/