@@ -108,7 +108,6 @@ static dlist_head pcxt_list = DLIST_STATIC_INIT(pcxt_list);
108108
109109/* Private functions. */
110110static void HandleParallelMessage (ParallelContext * pcxt , int i , StringInfo msg );
111- static void ParallelErrorContext (void * arg );
112111static void ParallelExtensionTrampoline (dsm_segment * seg , shm_toc * toc );
113112static void ParallelWorkerMain (Datum main_arg );
114113static void WaitForParallelWorkersToExit (ParallelContext * pcxt );
@@ -788,30 +787,43 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
788787 case 'N' : /* NoticeResponse */
789788 {
790789 ErrorData edata ;
791- ErrorContextCallback errctx ;
792790 ErrorContextCallback * save_error_context_stack ;
793791
794- /*
795- * Rethrow the error using the error context callbacks that
796- * were in effect when the context was created, not the
797- * current ones.
798- */
799- save_error_context_stack = error_context_stack ;
800- errctx .callback = ParallelErrorContext ;
801- errctx .arg = NULL ;
802- errctx .previous = pcxt -> error_context_stack ;
803- error_context_stack = & errctx ;
804-
805792 /* Parse ErrorResponse or NoticeResponse. */
806793 pq_parse_errornotice (msg , & edata );
807794
808795 /* Death of a worker isn't enough justification for suicide. */
809796 edata .elevel = Min (edata .elevel , ERROR );
810797
811- /* Rethrow error or notice. */
798+ /*
799+ * If desired, add a context line to show that this is a
800+ * message propagated from a parallel worker. Otherwise, it
801+ * can sometimes be confusing to understand what actually
802+ * happened. (We don't do this in FORCE_PARALLEL_REGRESS mode
803+ * because it causes test-result instability depending on
804+ * whether a parallel worker is actually used or not.)
805+ */
806+ if (force_parallel_mode != FORCE_PARALLEL_REGRESS )
807+ {
808+ if (edata .context )
809+ edata .context = psprintf ("%s\n%s" , edata .context ,
810+ _ ("parallel worker" ));
811+ else
812+ edata .context = pstrdup (_ ("parallel worker" ));
813+ }
814+
815+ /*
816+ * Context beyond that should use the error context callbacks
817+ * that were in effect when the ParallelContext was created,
818+ * not the current ones.
819+ */
820+ save_error_context_stack = error_context_stack ;
821+ error_context_stack = pcxt -> error_context_stack ;
822+
823+ /* Rethrow error or print notice. */
812824 ThrowErrorData (& edata );
813825
814- /* Restore previous context. */
826+ /* Not an error, so restore previous context stack . */
815827 error_context_stack = save_error_context_stack ;
816828
817829 break ;
@@ -1112,18 +1124,6 @@ ParallelExtensionTrampoline(dsm_segment *seg, shm_toc *toc)
11121124 entrypt (seg , toc );
11131125}
11141126
1115- /*
1116- * Give the user a hint that this is a message propagated from a parallel
1117- * worker. Otherwise, it can sometimes be confusing to understand what
1118- * actually happened.
1119- */
1120- static void
1121- ParallelErrorContext (void * arg )
1122- {
1123- if (force_parallel_mode != FORCE_PARALLEL_REGRESS )
1124- errcontext ("parallel worker" );
1125- }
1126-
11271127/*
11281128 * Update shared memory with the ending location of the last WAL record we
11291129 * wrote, if it's greater than the value already stored there.
0 commit comments