PostgreSQL Source Code git master
parallel.h File Reference
#include "access/xlogdefs.h"
#include "lib/ilist.h"
#include "postmaster/bgworker.h"
#include "storage/shm_mq.h"
#include "storage/shm_toc.h"
Include dependency graph for parallel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ParallelWorkerInfo
 
struct  ParallelContext
 
struct  ParallelWorkerContext
 

Macros

#define IsParallelWorker()   (ParallelWorkerNumber >= 0)
 

Typedefs

typedef void(* parallel_worker_main_type) (dsm_segment *seg, shm_toc *toc)
 
typedef struct ParallelWorkerInfo ParallelWorkerInfo
 
typedef struct ParallelContext ParallelContext
 
typedef struct ParallelWorkerContext ParallelWorkerContext
 

Functions

ParallelContextCreateParallelContext (const char *library_name, const char *function_name, int nworkers)
 
void InitializeParallelDSM (ParallelContext *pcxt)
 
void ReinitializeParallelDSM (ParallelContext *pcxt)
 
void ReinitializeParallelWorkers (ParallelContext *pcxt, int nworkers_to_launch)
 
void LaunchParallelWorkers (ParallelContext *pcxt)
 
void WaitForParallelWorkersToAttach (ParallelContext *pcxt)
 
void WaitForParallelWorkersToFinish (ParallelContext *pcxt)
 
void DestroyParallelContext (ParallelContext *pcxt)
 
bool ParallelContextActive (void)
 
void HandleParallelMessageInterrupt (void)
 
void ProcessParallelMessages (void)
 
void AtEOXact_Parallel (bool isCommit)
 
void AtEOSubXact_Parallel (bool isCommit, SubTransactionId mySubId)
 
void ParallelWorkerReportLastRecEnd (XLogRecPtr last_xlog_end)
 
void ParallelWorkerMain (Datum main_arg)
 

Variables

PGDLLIMPORT volatile sig_atomic_t ParallelMessagePending
 
PGDLLIMPORT int ParallelWorkerNumber
 
PGDLLIMPORT bool InitializingParallelWorker
 

Macro Definition Documentation

◆ IsParallelWorker

#define IsParallelWorker ( )    (ParallelWorkerNumber >= 0)

Definition at line 60 of file parallel.h.

Typedef Documentation

◆ parallel_worker_main_type

typedef void(* parallel_worker_main_type) (dsm_segment *seg, shm_toc *toc)

Definition at line 23 of file parallel.h.

◆ ParallelContext

◆ ParallelWorkerContext

◆ ParallelWorkerInfo

Function Documentation

◆ AtEOSubXact_Parallel()

void AtEOSubXact_Parallel ( bool  isCommit,
SubTransactionId  mySubId 
)

Definition at line 1261 of file parallel.c.

1262{
1263 while (!dlist_is_empty(&pcxt_list))
1264 {
1265 ParallelContext *pcxt;
1266
1268 if (pcxt->subid != mySubId)
1269 break;
1270 if (isCommit)
1271 elog(WARNING, "leaked parallel context");
1273 }
1274}
void DestroyParallelContext(ParallelContext *pcxt)
Definition: parallel.c:957
static dlist_head pcxt_list
Definition: parallel.c:127
#define WARNING
Definition: elog.h:36
#define elog(elevel,...)
Definition: elog.h:226
#define dlist_head_element(type, membername, lhead)
Definition: ilist.h:603
static bool dlist_is_empty(const dlist_head *head)
Definition: ilist.h:336
SubTransactionId subid
Definition: parallel.h:34

References DestroyParallelContext(), dlist_head_element, dlist_is_empty(), elog, pcxt_list, ParallelContext::subid, and WARNING.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

◆ AtEOXact_Parallel()

void AtEOXact_Parallel ( bool  isCommit)

Definition at line 1282 of file parallel.c.

1283{
1284 while (!dlist_is_empty(&pcxt_list))
1285 {
1286 ParallelContext *pcxt;
1287
1289 if (isCommit)
1290 elog(WARNING, "leaked parallel context");
1292 }
1293}

References DestroyParallelContext(), dlist_head_element, dlist_is_empty(), elog, pcxt_list, and WARNING.

Referenced by AbortTransaction(), and CommitTransaction().

◆ CreateParallelContext()

ParallelContext * CreateParallelContext ( const char *  library_name,
const char *  function_name,
int  nworkers 
)

Definition at line 173 of file parallel.c.

175{
176 MemoryContext oldcontext;
177 ParallelContext *pcxt;
178
179 /* It is unsafe to create a parallel context if not in parallel mode. */
181
182 /* Number of workers should be non-negative. */
183 Assert(nworkers >= 0);
184
185 /* We might be running in a short-lived memory context. */
187
188 /* Initialize a new ParallelContext. */
191 pcxt->nworkers = nworkers;
192 pcxt->nworkers_to_launch = nworkers;
193 pcxt->library_name = pstrdup(library_name);
194 pcxt->function_name = pstrdup(function_name);
198
199 /* Restore previous memory context. */
200 MemoryContextSwitchTo(oldcontext);
201
202 return pcxt;
203}
ErrorContextCallback * error_context_stack
Definition: elog.c:95
#define palloc0_object(type)
Definition: fe_memutils.h:75
Assert(PointerIsAligned(start, uint64))
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:347
MemoryContext TopTransactionContext
Definition: mcxt.c:171
char * pstrdup(const char *in)
Definition: mcxt.c:1781
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
#define shm_toc_initialize_estimator(e)
Definition: shm_toc.h:49
char * library_name
Definition: parallel.h:38
ErrorContextCallback * error_context_stack
Definition: parallel.h:40
shm_toc_estimator estimator
Definition: parallel.h:41
dlist_node node
Definition: parallel.h:33
int nworkers_to_launch
Definition: parallel.h:36
char * function_name
Definition: parallel.h:39
SubTransactionId GetCurrentSubTransactionId(void)
Definition: xact.c:792
bool IsInParallelMode(void)
Definition: xact.c:1090

References Assert(), dlist_push_head(), error_context_stack, ParallelContext::error_context_stack, ParallelContext::estimator, ParallelContext::function_name, GetCurrentSubTransactionId(), IsInParallelMode(), ParallelContext::library_name, MemoryContextSwitchTo(), ParallelContext::node, ParallelContext::nworkers, ParallelContext::nworkers_to_launch, palloc0_object, pcxt_list, pstrdup(), shm_toc_initialize_estimator, ParallelContext::subid, and TopTransactionContext.

Referenced by _brin_begin_parallel(), _bt_begin_parallel(), _gin_begin_parallel(), ExecInitParallelPlan(), and parallel_vacuum_init().

◆ DestroyParallelContext()

void DestroyParallelContext ( ParallelContext pcxt)

Definition at line 957 of file parallel.c.

958{
959 int i;
960
961 /*
962 * Be careful about order of operations here! We remove the parallel
963 * context from the list before we do anything else; otherwise, if an
964 * error occurs during a subsequent step, we might try to nuke it again
965 * from AtEOXact_Parallel or AtEOSubXact_Parallel.
966 */
967 dlist_delete(&pcxt->node);
968
969 /* Kill each worker in turn, and forget their error queues. */
970 if (pcxt->worker != NULL)
971 {
972 for (i = 0; i < pcxt->nworkers_launched; ++i)
973 {
974 if (pcxt->worker[i].error_mqh != NULL)
975 {
977
979 pcxt->worker[i].error_mqh = NULL;
980 }
981 }
982 }
983
984 /*
985 * If we have allocated a shared memory segment, detach it. This will
986 * implicitly detach the error queues, and any other shared memory queues,
987 * stored there.
988 */
989 if (pcxt->seg != NULL)
990 {
991 dsm_detach(pcxt->seg);
992 pcxt->seg = NULL;
993 }
994
995 /*
996 * If this parallel context is actually in backend-private memory rather
997 * than shared memory, free that memory instead.
998 */
999 if (pcxt->private_memory != NULL)
1000 {
1001 pfree(pcxt->private_memory);
1002 pcxt->private_memory = NULL;
1003 }
1004
1005 /*
1006 * We can't finish transaction commit or abort until all of the workers
1007 * have exited. This means, in particular, that we can't respond to
1008 * interrupts at this stage.
1009 */
1013
1014 /* Free the worker array itself. */
1015 if (pcxt->worker != NULL)
1016 {
1017 pfree(pcxt->worker);
1018 pcxt->worker = NULL;
1019 }
1020
1021 /* Free memory. */
1022 pfree(pcxt->library_name);
1023 pfree(pcxt->function_name);
1024 pfree(pcxt);
1025}
static void WaitForParallelWorkersToExit(ParallelContext *pcxt)
Definition: parallel.c:917
void TerminateBackgroundWorker(BackgroundWorkerHandle *handle)
Definition: bgworker.c:1312
void dsm_detach(dsm_segment *seg)
Definition: dsm.c:803
static void dlist_delete(dlist_node *node)
Definition: ilist.h:405
int i
Definition: isn.c:77
void pfree(void *pointer)
Definition: mcxt.c:1616
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:136
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:134
void shm_mq_detach(shm_mq_handle *mqh)
Definition: shm_mq.c:843
dsm_segment * seg
Definition: parallel.h:42
ParallelWorkerInfo * worker
Definition: parallel.h:45
void * private_memory
Definition: parallel.h:43
int nworkers_launched
Definition: parallel.h:37
BackgroundWorkerHandle * bgwhandle
Definition: parallel.h:27
shm_mq_handle * error_mqh
Definition: parallel.h:28

References ParallelWorkerInfo::bgwhandle, dlist_delete(), dsm_detach(), ParallelWorkerInfo::error_mqh, ParallelContext::function_name, HOLD_INTERRUPTS, i, ParallelContext::library_name, ParallelContext::node, ParallelContext::nworkers_launched, pfree(), ParallelContext::private_memory, RESUME_INTERRUPTS, ParallelContext::seg, shm_mq_detach(), TerminateBackgroundWorker(), WaitForParallelWorkersToExit(), and ParallelContext::worker.

Referenced by _brin_begin_parallel(), _brin_end_parallel(), _bt_begin_parallel(), _bt_end_parallel(), _gin_begin_parallel(), _gin_end_parallel(), AtEOSubXact_Parallel(), AtEOXact_Parallel(), ExecParallelCleanup(), and parallel_vacuum_end().

◆ HandleParallelMessageInterrupt()

void HandleParallelMessageInterrupt ( void  )

Definition at line 1044 of file parallel.c.

1045{
1046 InterruptPending = true;
1049}
volatile sig_atomic_t ParallelMessagePending
Definition: parallel.c:118
volatile sig_atomic_t InterruptPending
Definition: globals.c:32
struct Latch * MyLatch
Definition: globals.c:63
void SetLatch(Latch *latch)
Definition: latch.c:290

References InterruptPending, MyLatch, ParallelMessagePending, and SetLatch().

Referenced by procsignal_sigusr1_handler().

◆ InitializeParallelDSM()

void InitializeParallelDSM ( ParallelContext pcxt)

Definition at line 211 of file parallel.c.

212{
213 MemoryContext oldcontext;
214 Size library_len = 0;
215 Size guc_len = 0;
216 Size combocidlen = 0;
217 Size tsnaplen = 0;
218 Size asnaplen = 0;
219 Size tstatelen = 0;
220 Size pendingsyncslen = 0;
221 Size reindexlen = 0;
222 Size relmapperlen = 0;
223 Size uncommittedenumslen = 0;
224 Size clientconninfolen = 0;
225 Size segsize = 0;
226 int i;
228 dsm_handle session_dsm_handle = DSM_HANDLE_INVALID;
229 Snapshot transaction_snapshot = GetTransactionSnapshot();
230 Snapshot active_snapshot = GetActiveSnapshot();
231
232 /* We might be running in a very short-lived memory context. */
234
235 /* Allow space to store the fixed-size parallel state. */
238
239 /*
240 * If we manage to reach here while non-interruptible, it's unsafe to
241 * launch any workers: we would fail to process interrupts sent by them.
242 * We can deal with that edge case by pretending no workers were
243 * requested.
244 */
246 pcxt->nworkers = 0;
247
248 /*
249 * Normally, the user will have requested at least one worker process, but
250 * if by chance they have not, we can skip a bunch of things here.
251 */
252 if (pcxt->nworkers > 0)
253 {
254 /* Get (or create) the per-session DSM segment's handle. */
255 session_dsm_handle = GetSessionDsmHandle();
256
257 /*
258 * If we weren't able to create a per-session DSM segment, then we can
259 * continue but we can't safely launch any workers because their
260 * record typmods would be incompatible so they couldn't exchange
261 * tuples.
262 */
263 if (session_dsm_handle == DSM_HANDLE_INVALID)
264 pcxt->nworkers = 0;
265 }
266
267 if (pcxt->nworkers > 0)
268 {
271 "parallel error queue size not buffer-aligned");
272
273 /* Estimate space for various kinds of state sharing. */
274 library_len = EstimateLibraryStateSpace();
275 shm_toc_estimate_chunk(&pcxt->estimator, library_len);
276 guc_len = EstimateGUCStateSpace();
277 shm_toc_estimate_chunk(&pcxt->estimator, guc_len);
278 combocidlen = EstimateComboCIDStateSpace();
279 shm_toc_estimate_chunk(&pcxt->estimator, combocidlen);
281 {
282 tsnaplen = EstimateSnapshotSpace(transaction_snapshot);
283 shm_toc_estimate_chunk(&pcxt->estimator, tsnaplen);
284 }
285 asnaplen = EstimateSnapshotSpace(active_snapshot);
286 shm_toc_estimate_chunk(&pcxt->estimator, asnaplen);
287 tstatelen = EstimateTransactionStateSpace();
288 shm_toc_estimate_chunk(&pcxt->estimator, tstatelen);
290 pendingsyncslen = EstimatePendingSyncsSpace();
291 shm_toc_estimate_chunk(&pcxt->estimator, pendingsyncslen);
292 reindexlen = EstimateReindexStateSpace();
293 shm_toc_estimate_chunk(&pcxt->estimator, reindexlen);
294 relmapperlen = EstimateRelationMapSpace();
295 shm_toc_estimate_chunk(&pcxt->estimator, relmapperlen);
296 uncommittedenumslen = EstimateUncommittedEnumsSpace();
297 shm_toc_estimate_chunk(&pcxt->estimator, uncommittedenumslen);
298 clientconninfolen = EstimateClientConnectionInfoSpace();
299 shm_toc_estimate_chunk(&pcxt->estimator, clientconninfolen);
300 /* If you add more chunks here, you probably need to add keys. */
302
303 /* Estimate space need for error queues. */
306 pcxt->nworkers));
308
309 /* Estimate how much we'll need for the entrypoint info. */
310 shm_toc_estimate_chunk(&pcxt->estimator, strlen(pcxt->library_name) +
311 strlen(pcxt->function_name) + 2);
313 }
314
315 /*
316 * Create DSM and initialize with new table of contents. But if the user
317 * didn't request any workers, then don't bother creating a dynamic shared
318 * memory segment; instead, just use backend-private memory.
319 *
320 * Also, if we can't create a dynamic shared memory segment because the
321 * maximum number of segments have already been created, then fall back to
322 * backend-private memory, and plan not to use any workers. We hope this
323 * won't happen very often, but it's better to abandon the use of
324 * parallelism than to fail outright.
325 */
326 segsize = shm_toc_estimate(&pcxt->estimator);
327 if (pcxt->nworkers > 0)
329 if (pcxt->seg != NULL)
332 segsize);
333 else
334 {
335 pcxt->nworkers = 0;
338 segsize);
339 }
340
341 /* Initialize fixed-size state in shared memory. */
342 fps = (FixedParallelState *)
359 SpinLockInit(&fps->mutex);
360 fps->last_xlog_end = 0;
362
363 /* We can skip the rest of this if we're not budgeting for any workers. */
364 if (pcxt->nworkers > 0)
365 {
366 char *libraryspace;
367 char *gucspace;
368 char *combocidspace;
369 char *tsnapspace;
370 char *asnapspace;
371 char *tstatespace;
372 char *pendingsyncsspace;
373 char *reindexspace;
374 char *relmapperspace;
375 char *error_queue_space;
376 char *session_dsm_handle_space;
377 char *entrypointstate;
378 char *uncommittedenumsspace;
379 char *clientconninfospace;
380 Size lnamelen;
381
382 /* Serialize shared libraries we have loaded. */
383 libraryspace = shm_toc_allocate(pcxt->toc, library_len);
384 SerializeLibraryState(library_len, libraryspace);
385 shm_toc_insert(pcxt->toc, PARALLEL_KEY_LIBRARY, libraryspace);
386
387 /* Serialize GUC settings. */
388 gucspace = shm_toc_allocate(pcxt->toc, guc_len);
389 SerializeGUCState(guc_len, gucspace);
390 shm_toc_insert(pcxt->toc, PARALLEL_KEY_GUC, gucspace);
391
392 /* Serialize combo CID state. */
393 combocidspace = shm_toc_allocate(pcxt->toc, combocidlen);
394 SerializeComboCIDState(combocidlen, combocidspace);
395 shm_toc_insert(pcxt->toc, PARALLEL_KEY_COMBO_CID, combocidspace);
396
397 /*
398 * Serialize the transaction snapshot if the transaction isolation
399 * level uses a transaction snapshot.
400 */
402 {
403 tsnapspace = shm_toc_allocate(pcxt->toc, tsnaplen);
404 SerializeSnapshot(transaction_snapshot, tsnapspace);
406 tsnapspace);
407 }
408
409 /* Serialize the active snapshot. */
410 asnapspace = shm_toc_allocate(pcxt->toc, asnaplen);
411 SerializeSnapshot(active_snapshot, asnapspace);
413
414 /* Provide the handle for per-session segment. */
415 session_dsm_handle_space = shm_toc_allocate(pcxt->toc,
416 sizeof(dsm_handle));
417 *(dsm_handle *) session_dsm_handle_space = session_dsm_handle;
419 session_dsm_handle_space);
420
421 /* Serialize transaction state. */
422 tstatespace = shm_toc_allocate(pcxt->toc, tstatelen);
423 SerializeTransactionState(tstatelen, tstatespace);
425
426 /* Serialize pending syncs. */
427 pendingsyncsspace = shm_toc_allocate(pcxt->toc, pendingsyncslen);
428 SerializePendingSyncs(pendingsyncslen, pendingsyncsspace);
430 pendingsyncsspace);
431
432 /* Serialize reindex state. */
433 reindexspace = shm_toc_allocate(pcxt->toc, reindexlen);
434 SerializeReindexState(reindexlen, reindexspace);
435 shm_toc_insert(pcxt->toc, PARALLEL_KEY_REINDEX_STATE, reindexspace);
436
437 /* Serialize relmapper state. */
438 relmapperspace = shm_toc_allocate(pcxt->toc, relmapperlen);
439 SerializeRelationMap(relmapperlen, relmapperspace);
441 relmapperspace);
442
443 /* Serialize uncommitted enum state. */
444 uncommittedenumsspace = shm_toc_allocate(pcxt->toc,
445 uncommittedenumslen);
446 SerializeUncommittedEnums(uncommittedenumsspace, uncommittedenumslen);
448 uncommittedenumsspace);
449
450 /* Serialize our ClientConnectionInfo. */
451 clientconninfospace = shm_toc_allocate(pcxt->toc, clientconninfolen);
452 SerializeClientConnectionInfo(clientconninfolen, clientconninfospace);
454 clientconninfospace);
455
456 /* Allocate space for worker information. */
458
459 /*
460 * Establish error queues in dynamic shared memory.
461 *
462 * These queues should be used only for transmitting ErrorResponse,
463 * NoticeResponse, and NotifyResponse protocol messages. Tuple data
464 * should be transmitted via separate (possibly larger?) queues.
465 */
466 error_queue_space =
467 shm_toc_allocate(pcxt->toc,
469 pcxt->nworkers));
470 for (i = 0; i < pcxt->nworkers; ++i)
471 {
472 char *start;
473 shm_mq *mq;
474
475 start = error_queue_space + i * PARALLEL_ERROR_QUEUE_SIZE;
478 pcxt->worker[i].error_mqh = shm_mq_attach(mq, pcxt->seg, NULL);
479 }
480 shm_toc_insert(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, error_queue_space);
481
482 /*
483 * Serialize entrypoint information. It's unsafe to pass function
484 * pointers across processes, as the function pointer may be different
485 * in each process in EXEC_BACKEND builds, so we always pass library
486 * and function name. (We use library name "postgres" for functions
487 * in the core backend.)
488 */
489 lnamelen = strlen(pcxt->library_name);
490 entrypointstate = shm_toc_allocate(pcxt->toc, lnamelen +
491 strlen(pcxt->function_name) + 2);
492 strcpy(entrypointstate, pcxt->library_name);
493 strcpy(entrypointstate + lnamelen + 1, pcxt->function_name);
494 shm_toc_insert(pcxt->toc, PARALLEL_KEY_ENTRYPOINT, entrypointstate);
495 }
496
497 /* Update nworkers_to_launch, in case we changed nworkers above. */
498 pcxt->nworkers_to_launch = pcxt->nworkers;
499
500 /* Restore previous memory context. */
501 MemoryContextSwitchTo(oldcontext);
502}
#define PARALLEL_KEY_TRANSACTION_STATE
Definition: parallel.c:72
#define PARALLEL_KEY_GUC
Definition: parallel.c:68
#define PARALLEL_KEY_UNCOMMITTEDENUMS
Definition: parallel.c:78
#define PARALLEL_KEY_TRANSACTION_SNAPSHOT
Definition: parallel.c:70
#define PARALLEL_KEY_CLIENTCONNINFO
Definition: parallel.c:79
#define PARALLEL_KEY_PENDING_SYNCS
Definition: parallel.c:75
#define PARALLEL_KEY_ACTIVE_SNAPSHOT
Definition: parallel.c:71
#define PARALLEL_KEY_ERROR_QUEUE
Definition: parallel.c:66
#define PARALLEL_KEY_SESSION_DSM
Definition: parallel.c:74
#define PARALLEL_MAGIC
Definition: parallel.c:58
#define PARALLEL_KEY_REINDEX_STATE
Definition: parallel.c:76
#define PARALLEL_KEY_LIBRARY
Definition: parallel.c:67
#define PARALLEL_KEY_FIXED
Definition: parallel.c:65
#define PARALLEL_KEY_ENTRYPOINT
Definition: parallel.c:73
#define PARALLEL_KEY_COMBO_CID
Definition: parallel.c:69
#define PARALLEL_ERROR_QUEUE_SIZE
Definition: parallel.c:55
#define PARALLEL_KEY_RELMAPPER_STATE
Definition: parallel.c:77
#define BUFFERALIGN(LEN)
Definition: c.h:834
#define StaticAssertDecl(condition, errmessage)
Definition: c.h:948
size_t Size
Definition: c.h:625
void SerializeComboCIDState(Size maxsize, char *start_address)
Definition: combocid.c:316
Size EstimateComboCIDStateSpace(void)
Definition: combocid.c:297
void SerializeLibraryState(Size maxsize, char *start_address)
Definition: dfmgr.c:719
Size EstimateLibraryStateSpace(void)
Definition: dfmgr.c:702
void * dsm_segment_address(dsm_segment *seg)
Definition: dsm.c:1095
dsm_segment * dsm_create(Size size, int flags)
Definition: dsm.c:516
#define DSM_CREATE_NULL_IF_MAXSEGMENTS
Definition: dsm.h:20
uint32 dsm_handle
Definition: dsm_impl.h:55
#define DSM_HANDLE_INVALID
Definition: dsm_impl.h:58
#define palloc0_array(type, count)
Definition: fe_memutils.h:77
int MyProcPid
Definition: globals.c:47
ProcNumber MyProcNumber
Definition: globals.c:90
Oid MyDatabaseId
Definition: globals.c:94
void SerializeGUCState(Size maxsize, char *start_address)
Definition: guc.c:5970
Size EstimateGUCStateSpace(void)
Definition: guc.c:5817
bool current_role_is_superuser
Definition: guc_tables.c:537
return str start
void SerializeReindexState(Size maxsize, char *start_address)
Definition: index.c:4251
Size EstimateReindexStateSpace(void)
Definition: index.c:4240
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1232
MemoryContext TopMemoryContext
Definition: mcxt.c:166
#define INTERRUPTS_CAN_BE_PROCESSED()
Definition: miscadmin.h:130
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:612
bool GetSessionUserIsSuperuser(void)
Definition: miscinit.c:515
Size EstimateClientConnectionInfoSpace(void)
Definition: miscinit.c:1035
Oid GetSessionUserId(void)
Definition: miscinit.c:508
Oid GetAuthenticatedUserId(void)
Definition: miscinit.c:545
Oid GetCurrentRoleId(void)
Definition: miscinit.c:935
void SerializeClientConnectionInfo(Size maxsize PG_USED_FOR_ASSERTS_ONLY, char *start_address)
Definition: miscinit.c:1051
void GetTempNamespaceState(Oid *tempNamespaceId, Oid *tempToastNamespaceId)
Definition: namespace.c:3875
Size EstimateUncommittedEnumsSpace(void)
Definition: pg_enum.c:826
void SerializeUncommittedEnums(void *space, Size size)
Definition: pg_enum.c:840
SerializableXactHandle ShareSerializableXact(void)
Definition: predicate.c:5045
Size EstimateRelationMapSpace(void)
Definition: relmapper.c:713
void SerializeRelationMap(Size maxSize, char *startAddress)
Definition: relmapper.c:724
dsm_handle GetSessionDsmHandle(void)
Definition: session.c:70
shm_mq * shm_mq_create(void *address, Size size)
Definition: shm_mq.c:177
void shm_mq_set_receiver(shm_mq *mq, PGPROC *proc)
Definition: shm_mq.c:206
shm_mq_handle * shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:290
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
Size shm_toc_estimate(shm_toc_estimator *e)
Definition: shm_toc.c:263
shm_toc * shm_toc_create(uint64 magic, void *address, Size nbytes)
Definition: shm_toc.c:40
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
Size mul_size(Size s1, Size s2)
Definition: shmem.c:510
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:1736
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:272
Size EstimateSnapshotSpace(Snapshot snapshot)
Definition: snapmgr.c:1712
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:800
#define SpinLockInit(lock)
Definition: spin.h:57
PGPROC * MyProc
Definition: proc.c:67
void SerializePendingSyncs(Size maxSize, char *startAddress)
Definition: storage.c:600
Size EstimatePendingSyncsSpace(void)
Definition: storage.c:587
Oid temp_toast_namespace_id
Definition: parallel.c:91
XLogRecPtr last_xlog_end
Definition: parallel.c:106
bool role_is_superuser
Definition: parallel.c:94
TimestampTz stmt_ts
Definition: parallel.c:99
SerializableXactHandle serializable_xact_handle
Definition: parallel.c:100
TimestampTz xact_ts
Definition: parallel.c:98
PGPROC * parallel_leader_pgproc
Definition: parallel.c:95
bool session_user_is_superuser
Definition: parallel.c:93
pid_t parallel_leader_pid
Definition: parallel.c:96
Oid authenticated_user_id
Definition: parallel.c:86
ProcNumber parallel_leader_proc_number
Definition: parallel.c:97
shm_toc * toc
Definition: parallel.h:44
Definition: shm_mq.c:72
void SerializeTransactionState(Size maxsize, char *start_address)
Definition: xact.c:5562
Size EstimateTransactionStateSpace(void)
Definition: xact.c:5534
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition: xact.c:880
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:871
#define IsolationUsesXactSnapshot()
Definition: xact.h:52

References FixedParallelState::authenticated_user_id, BUFFERALIGN, current_role_is_superuser, FixedParallelState::current_user_id, FixedParallelState::database_id, dsm_create(), DSM_CREATE_NULL_IF_MAXSEGMENTS, DSM_HANDLE_INVALID, dsm_segment_address(), ParallelWorkerInfo::error_mqh, EstimateClientConnectionInfoSpace(), EstimateComboCIDStateSpace(), EstimateGUCStateSpace(), EstimateLibraryStateSpace(), EstimatePendingSyncsSpace(), EstimateReindexStateSpace(), EstimateRelationMapSpace(), EstimateSnapshotSpace(), EstimateTransactionStateSpace(), EstimateUncommittedEnumsSpace(), ParallelContext::estimator, ParallelContext::function_name, GetActiveSnapshot(), GetAuthenticatedUserId(), GetCurrentRoleId(), GetCurrentStatementStartTimestamp(), GetCurrentTransactionStartTimestamp(), GetSessionDsmHandle(), GetSessionUserId(), GetSessionUserIsSuperuser(), GetTempNamespaceState(), GetTransactionSnapshot(), GetUserIdAndSecContext(), i, INTERRUPTS_CAN_BE_PROCESSED, IsolationUsesXactSnapshot, FixedParallelState::last_xlog_end, ParallelContext::library_name, MemoryContextAlloc(), MemoryContextSwitchTo(), mul_size(), FixedParallelState::mutex, MyDatabaseId, MyProc, MyProcNumber, MyProcPid, ParallelContext::nworkers, ParallelContext::nworkers_to_launch, FixedParallelState::outer_user_id, palloc0_array, PARALLEL_ERROR_QUEUE_SIZE, PARALLEL_KEY_ACTIVE_SNAPSHOT, PARALLEL_KEY_CLIENTCONNINFO, PARALLEL_KEY_COMBO_CID, PARALLEL_KEY_ENTRYPOINT, PARALLEL_KEY_ERROR_QUEUE, PARALLEL_KEY_FIXED, PARALLEL_KEY_GUC, PARALLEL_KEY_LIBRARY, PARALLEL_KEY_PENDING_SYNCS, PARALLEL_KEY_REINDEX_STATE, PARALLEL_KEY_RELMAPPER_STATE, PARALLEL_KEY_SESSION_DSM, PARALLEL_KEY_TRANSACTION_SNAPSHOT, PARALLEL_KEY_TRANSACTION_STATE, PARALLEL_KEY_UNCOMMITTEDENUMS, FixedParallelState::parallel_leader_pgproc, FixedParallelState::parallel_leader_pid, FixedParallelState::parallel_leader_proc_number, PARALLEL_MAGIC, ParallelContext::private_memory, FixedParallelState::role_is_superuser, FixedParallelState::sec_context, ParallelContext::seg, FixedParallelState::serializable_xact_handle, SerializeClientConnectionInfo(), SerializeComboCIDState(), SerializeGUCState(), SerializeLibraryState(), SerializePendingSyncs(), SerializeReindexState(), SerializeRelationMap(), SerializeSnapshot(), SerializeTransactionState(), SerializeUncommittedEnums(), FixedParallelState::session_user_id, FixedParallelState::session_user_is_superuser, ShareSerializableXact(), shm_mq_attach(), shm_mq_create(), shm_mq_set_receiver(), shm_toc_allocate(), shm_toc_create(), shm_toc_estimate(), shm_toc_estimate_chunk, shm_toc_estimate_keys, shm_toc_insert(), SpinLockInit, start, StaticAssertDecl, FixedParallelState::stmt_ts, FixedParallelState::temp_namespace_id, FixedParallelState::temp_toast_namespace_id, ParallelContext::toc, TopMemoryContext, TopTransactionContext, ParallelContext::worker, and FixedParallelState::xact_ts.

Referenced by _brin_begin_parallel(), _bt_begin_parallel(), _gin_begin_parallel(), ExecInitParallelPlan(), and parallel_vacuum_init().

◆ LaunchParallelWorkers()

void LaunchParallelWorkers ( ParallelContext pcxt)

Definition at line 581 of file parallel.c.

582{
583 MemoryContext oldcontext;
584 BackgroundWorker worker;
585 int i;
586 bool any_registrations_failed = false;
587
588 /* Skip this if we have no workers. */
589 if (pcxt->nworkers == 0 || pcxt->nworkers_to_launch == 0)
590 return;
591
592 /* We need to be a lock group leader. */
594
595 /* If we do have workers, we'd better have a DSM segment. */
596 Assert(pcxt->seg != NULL);
597
598 /* We might be running in a short-lived memory context. */
600
601 /* Configure a worker. */
602 memset(&worker, 0, sizeof(worker));
603 snprintf(worker.bgw_name, BGW_MAXLEN, "parallel worker for PID %d",
604 MyProcPid);
605 snprintf(worker.bgw_type, BGW_MAXLEN, "parallel worker");
606 worker.bgw_flags =
611 sprintf(worker.bgw_library_name, "postgres");
612 sprintf(worker.bgw_function_name, "ParallelWorkerMain");
614 worker.bgw_notify_pid = MyProcPid;
615
616 /*
617 * Start workers.
618 *
619 * The caller must be able to tolerate ending up with fewer workers than
620 * expected, so there is no need to throw an error here if registration
621 * fails. It wouldn't help much anyway, because registering the worker in
622 * no way guarantees that it will start up and initialize successfully.
623 */
624 for (i = 0; i < pcxt->nworkers_to_launch; ++i)
625 {
626 memcpy(worker.bgw_extra, &i, sizeof(int));
627 if (!any_registrations_failed &&
629 &pcxt->worker[i].bgwhandle))
630 {
632 pcxt->worker[i].bgwhandle);
633 pcxt->nworkers_launched++;
634 }
635 else
636 {
637 /*
638 * If we weren't able to register the worker, then we've bumped up
639 * against the max_worker_processes limit, and future
640 * registrations will probably fail too, so arrange to skip them.
641 * But we still have to execute this code for the remaining slots
642 * to make sure that we forget about the error queues we budgeted
643 * for those workers. Otherwise, we'll wait for them to start,
644 * but they never will.
645 */
646 any_registrations_failed = true;
647 pcxt->worker[i].bgwhandle = NULL;
649 pcxt->worker[i].error_mqh = NULL;
650 }
651 }
652
653 /*
654 * Now that nworkers_launched has taken its final value, we can initialize
655 * known_attached_workers.
656 */
657 if (pcxt->nworkers_launched > 0)
658 {
660 pcxt->nknown_attached_workers = 0;
661 }
662
663 /* Restore previous memory context. */
664 MemoryContextSwitchTo(oldcontext);
665}
bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker, BackgroundWorkerHandle **handle)
Definition: bgworker.c:1061
#define BGW_NEVER_RESTART
Definition: bgworker.h:92
#define BGWORKER_CLASS_PARALLEL
Definition: bgworker.h:75
@ BgWorkerStart_ConsistentState
Definition: bgworker.h:87
#define BGWORKER_BACKEND_DATABASE_CONNECTION
Definition: bgworker.h:60
#define BGWORKER_SHMEM_ACCESS
Definition: bgworker.h:53
#define BGW_MAXLEN
Definition: bgworker.h:93
dsm_handle dsm_segment_handle(dsm_segment *seg)
Definition: dsm.c:1123
#define sprintf
Definition: port.h:262
#define snprintf
Definition: port.h:260
static Datum UInt32GetDatum(uint32 X)
Definition: postgres.h:242
void shm_mq_set_handle(shm_mq_handle *mqh, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:319
void BecomeLockGroupLeader(void)
Definition: proc.c:2011
char bgw_function_name[BGW_MAXLEN]
Definition: bgworker.h:104
Datum bgw_main_arg
Definition: bgworker.h:105
char bgw_name[BGW_MAXLEN]
Definition: bgworker.h:98
int bgw_restart_time
Definition: bgworker.h:102
char bgw_type[BGW_MAXLEN]
Definition: bgworker.h:99
BgWorkerStartTime bgw_start_time
Definition: bgworker.h:101
char bgw_extra[BGW_EXTRALEN]
Definition: bgworker.h:106
pid_t bgw_notify_pid
Definition: bgworker.h:107
char bgw_library_name[MAXPGPATH]
Definition: bgworker.h:103
bool * known_attached_workers
Definition: parallel.h:47
int nknown_attached_workers
Definition: parallel.h:46

References Assert(), BecomeLockGroupLeader(), BackgroundWorker::bgw_extra, BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_main_arg, BGW_MAXLEN, BackgroundWorker::bgw_name, BGW_NEVER_RESTART, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, ParallelWorkerInfo::bgwhandle, BGWORKER_BACKEND_DATABASE_CONNECTION, BGWORKER_CLASS_PARALLEL, BGWORKER_SHMEM_ACCESS, BgWorkerStart_ConsistentState, dsm_segment_handle(), ParallelWorkerInfo::error_mqh, i, ParallelContext::known_attached_workers, MemoryContextSwitchTo(), MyProcPid, ParallelContext::nknown_attached_workers, ParallelContext::nworkers, ParallelContext::nworkers_launched, ParallelContext::nworkers_to_launch, palloc0_array, RegisterDynamicBackgroundWorker(), ParallelContext::seg, shm_mq_detach(), shm_mq_set_handle(), snprintf, sprintf, TopTransactionContext, UInt32GetDatum(), and ParallelContext::worker.

Referenced by _brin_begin_parallel(), _bt_begin_parallel(), _gin_begin_parallel(), ExecGather(), ExecGatherMerge(), and parallel_vacuum_process_all_indexes().

◆ ParallelContextActive()

bool ParallelContextActive ( void  )

Definition at line 1031 of file parallel.c.

1032{
1033 return !dlist_is_empty(&pcxt_list);
1034}

References dlist_is_empty(), and pcxt_list.

Referenced by AtPrepare_PredicateLocks(), ExitParallelMode(), and ReleasePredicateLocks().

◆ ParallelWorkerMain()

void ParallelWorkerMain ( Datum  main_arg)

Definition at line 1299 of file parallel.c.

1300{
1301 dsm_segment *seg;
1302 shm_toc *toc;
1303 FixedParallelState *fps;
1304 char *error_queue_space;
1305 shm_mq *mq;
1306 shm_mq_handle *mqh;
1307 char *libraryspace;
1308 char *entrypointstate;
1309 char *library_name;
1310 char *function_name;
1312 char *gucspace;
1313 char *combocidspace;
1314 char *tsnapspace;
1315 char *asnapspace;
1316 char *tstatespace;
1317 char *pendingsyncsspace;
1318 char *reindexspace;
1319 char *relmapperspace;
1320 char *uncommittedenumsspace;
1321 char *clientconninfospace;
1322 char *session_dsm_handle_space;
1323 Snapshot tsnapshot;
1324 Snapshot asnapshot;
1325
1326 /* Set flag to indicate that we're initializing a parallel worker. */
1328
1329 /* Establish signal handlers. */
1330 pqsignal(SIGTERM, die);
1332
1333 /* Determine and set our parallel worker number. */
1335 memcpy(&ParallelWorkerNumber, MyBgworkerEntry->bgw_extra, sizeof(int));
1336
1337 /* Set up a memory context to work in, just for cleanliness. */
1339 "Parallel worker",
1341
1342 /*
1343 * Attach to the dynamic shared memory segment for the parallel query, and
1344 * find its table of contents.
1345 *
1346 * Note: at this point, we have not created any ResourceOwner in this
1347 * process. This will result in our DSM mapping surviving until process
1348 * exit, which is fine. If there were a ResourceOwner, it would acquire
1349 * ownership of the mapping, but we have no need for that.
1350 */
1351 seg = dsm_attach(DatumGetUInt32(main_arg));
1352 if (seg == NULL)
1353 ereport(ERROR,
1354 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1355 errmsg("could not map dynamic shared memory segment")));
1357 if (toc == NULL)
1358 ereport(ERROR,
1359 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1360 errmsg("invalid magic number in dynamic shared memory segment")));
1361
1362 /* Look up fixed parallel state. */
1363 fps = shm_toc_lookup(toc, PARALLEL_KEY_FIXED, false);
1365
1366 /* Arrange to signal the leader if we exit. */
1370
1371 /*
1372 * Now we can find and attach to the error queue provided for us. That's
1373 * good, because until we do that, any errors that happen here will not be
1374 * reported back to the process that requested that this worker be
1375 * launched.
1376 */
1377 error_queue_space = shm_toc_lookup(toc, PARALLEL_KEY_ERROR_QUEUE, false);
1378 mq = (shm_mq *) (error_queue_space +
1381 mqh = shm_mq_attach(mq, seg, NULL);
1382 pq_redirect_to_shm_mq(seg, mqh);
1385
1386 /*
1387 * Hooray! Primary initialization is complete. Now, we need to set up our
1388 * backend-local state to match the original backend.
1389 */
1390
1391 /*
1392 * Join locking group. We must do this before anything that could try to
1393 * acquire a heavyweight lock, because any heavyweight locks acquired to
1394 * this point could block either directly against the parallel group
1395 * leader or against some process which in turn waits for a lock that
1396 * conflicts with the parallel group leader, causing an undetected
1397 * deadlock. (If we can't join the lock group, the leader has gone away,
1398 * so just exit quietly.)
1399 */
1401 fps->parallel_leader_pid))
1402 return;
1403
1404 /*
1405 * Restore transaction and statement start-time timestamps. This must
1406 * happen before anything that would start a transaction, else asserts in
1407 * xact.c will fire.
1408 */
1410
1411 /*
1412 * Identify the entry point to be called. In theory this could result in
1413 * loading an additional library, though most likely the entry point is in
1414 * the core backend or in a library we just loaded.
1415 */
1416 entrypointstate = shm_toc_lookup(toc, PARALLEL_KEY_ENTRYPOINT, false);
1417 library_name = entrypointstate;
1418 function_name = entrypointstate + strlen(library_name) + 1;
1419
1420 entrypt = LookupParallelWorkerFunction(library_name, function_name);
1421
1422 /*
1423 * Restore current session authorization and role id. No verification
1424 * happens here, we just blindly adopt the leader's state. Note that this
1425 * has to happen before InitPostgres, since InitializeSessionUserId will
1426 * not set these variables.
1427 */
1432
1433 /*
1434 * Restore database connection. We skip connection authorization checks,
1435 * reasoning that (a) the leader checked these things when it started, and
1436 * (b) we do not want parallel mode to cause these failures, because that
1437 * would make use of parallel query plans not transparent to applications.
1438 */
1443
1444 /*
1445 * Set the client encoding to the database encoding, since that is what
1446 * the leader will expect. (We're cheating a bit by not calling
1447 * PrepareClientEncoding first. It's okay because this call will always
1448 * result in installing a no-op conversion. No error should be possible,
1449 * but check anyway.)
1450 */
1452 elog(ERROR, "SetClientEncoding(%d) failed", GetDatabaseEncoding());
1453
1454 /*
1455 * Load libraries that were loaded by original backend. We want to do
1456 * this before restoring GUCs, because the libraries might define custom
1457 * variables.
1458 */
1459 libraryspace = shm_toc_lookup(toc, PARALLEL_KEY_LIBRARY, false);
1461 RestoreLibraryState(libraryspace);
1463
1464 /* Crank up a transaction state appropriate to a parallel worker. */
1465 tstatespace = shm_toc_lookup(toc, PARALLEL_KEY_TRANSACTION_STATE, false);
1466 StartParallelWorkerTransaction(tstatespace);
1467
1468 /*
1469 * Restore state that affects catalog access. Ideally we'd do this even
1470 * before calling InitPostgres, but that has order-of-initialization
1471 * problems, and also the relmapper would get confused during the
1472 * CommitTransactionCommand call above.
1473 */
1474 pendingsyncsspace = shm_toc_lookup(toc, PARALLEL_KEY_PENDING_SYNCS,
1475 false);
1476 RestorePendingSyncs(pendingsyncsspace);
1477 relmapperspace = shm_toc_lookup(toc, PARALLEL_KEY_RELMAPPER_STATE, false);
1478 RestoreRelationMap(relmapperspace);
1479 reindexspace = shm_toc_lookup(toc, PARALLEL_KEY_REINDEX_STATE, false);
1480 RestoreReindexState(reindexspace);
1481 combocidspace = shm_toc_lookup(toc, PARALLEL_KEY_COMBO_CID, false);
1482 RestoreComboCIDState(combocidspace);
1483
1484 /* Attach to the per-session DSM segment and contained objects. */
1485 session_dsm_handle_space =
1487 AttachSession(*(dsm_handle *) session_dsm_handle_space);
1488
1489 /*
1490 * If the transaction isolation level is REPEATABLE READ or SERIALIZABLE,
1491 * the leader has serialized the transaction snapshot and we must restore
1492 * it. At lower isolation levels, there is no transaction-lifetime
1493 * snapshot, but we need TransactionXmin to get set to a value which is
1494 * less than or equal to the xmin of every snapshot that will be used by
1495 * this worker. The easiest way to accomplish that is to install the
1496 * active snapshot as the transaction snapshot. Code running in this
1497 * parallel worker might take new snapshots via GetTransactionSnapshot()
1498 * or GetLatestSnapshot(), but it shouldn't have any way of acquiring a
1499 * snapshot older than the active snapshot.
1500 */
1501 asnapspace = shm_toc_lookup(toc, PARALLEL_KEY_ACTIVE_SNAPSHOT, false);
1502 tsnapspace = shm_toc_lookup(toc, PARALLEL_KEY_TRANSACTION_SNAPSHOT, true);
1503 asnapshot = RestoreSnapshot(asnapspace);
1504 tsnapshot = tsnapspace ? RestoreSnapshot(tsnapspace) : asnapshot;
1507 PushActiveSnapshot(asnapshot);
1508
1509 /*
1510 * We've changed which tuples we can see, and must therefore invalidate
1511 * system caches.
1512 */
1514
1515 /*
1516 * Restore GUC values from launching backend. We can't do this earlier,
1517 * because GUC check hooks that do catalog lookups need to see the same
1518 * database state as the leader. Also, the check hooks for
1519 * session_authorization and role assume we already set the correct role
1520 * OIDs.
1521 */
1522 gucspace = shm_toc_lookup(toc, PARALLEL_KEY_GUC, false);
1523 RestoreGUCState(gucspace);
1524
1525 /*
1526 * Restore current user ID and security context. No verification happens
1527 * here, we just blindly adopt the leader's state. We can't do this till
1528 * after restoring GUCs, else we'll get complaints about restoring
1529 * session_authorization and role. (In effect, we're assuming that all
1530 * the restored values are okay to set, even if we are now inside a
1531 * restricted context.)
1532 */
1534
1535 /* Restore temp-namespace state to ensure search path matches leader's. */
1538
1539 /* Restore uncommitted enums. */
1540 uncommittedenumsspace = shm_toc_lookup(toc, PARALLEL_KEY_UNCOMMITTEDENUMS,
1541 false);
1542 RestoreUncommittedEnums(uncommittedenumsspace);
1543
1544 /* Restore the ClientConnectionInfo. */
1545 clientconninfospace = shm_toc_lookup(toc, PARALLEL_KEY_CLIENTCONNINFO,
1546 false);
1547 RestoreClientConnectionInfo(clientconninfospace);
1548
1549 /*
1550 * Initialize SystemUser now that MyClientConnectionInfo is restored. Also
1551 * ensure that auth_method is actually valid, aka authn_id is not NULL.
1552 */
1556
1557 /* Attach to the leader's serializable transaction, if SERIALIZABLE. */
1559
1560 /*
1561 * We've initialized all of our state now; nothing should change
1562 * hereafter.
1563 */
1566
1567 /*
1568 * Time to do the real work: invoke the caller-supplied code.
1569 */
1570 entrypt(seg, toc);
1571
1572 /* Must exit parallel mode to pop active snapshot. */
1574
1575 /* Must pop active snapshot so snapmgr.c doesn't complain. */
1577
1578 /* Shut down the parallel-worker transaction. */
1580
1581 /* Detach from the per-session DSM segment. */
1582 DetachSession();
1583
1584 /* Report success. */
1586}
static parallel_worker_main_type LookupParallelWorkerFunction(const char *libraryname, const char *funcname)
Definition: parallel.c:1649
int ParallelWorkerNumber
Definition: parallel.c:115
bool InitializingParallelWorker
Definition: parallel.c:121
static FixedParallelState * MyFixedParallelState
Definition: parallel.c:124
static pid_t ParallelLeaderPid
Definition: parallel.c:130
static void ParallelWorkerShutdown(int code, Datum arg)
Definition: parallel.c:1621
void BackgroundWorkerUnblockSignals(void)
Definition: bgworker.c:942
void BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, uint32 flags)
Definition: bgworker.c:902
#define BGWORKER_BYPASS_ROLELOGINCHECK
Definition: bgworker.h:167
#define BGWORKER_BYPASS_ALLOWCONN
Definition: bgworker.h:166
void RestoreComboCIDState(char *comboCIDstate)
Definition: combocid.c:342
void RestoreLibraryState(char *start_address)
Definition: dfmgr.c:741
dsm_segment * dsm_attach(dsm_handle h)
Definition: dsm.c:665
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
ProcNumber ParallelLeaderProcNumber
Definition: globals.c:92
void RestoreGUCState(void *gucstate)
Definition: guc.c:6062
const char * hba_authname(UserAuth auth_method)
Definition: hba.c:3138
void(* parallel_worker_main_type)(dsm_segment *seg, shm_toc *toc)
Definition: parallel.h:23
void RestoreReindexState(const void *reindexstate)
Definition: index.c:4269
void InvalidateSystemCaches(void)
Definition: inval.c:916
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:337
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:49
int GetDatabaseEncoding(void)
Definition: mbutils.c:1264
int SetClientEncoding(int encoding)
Definition: mbutils.c:209
MemoryContext CurrentMemoryContext
Definition: mcxt.c:160
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
void InitializeSystemUser(const char *authn_id, const char *auth_method)
Definition: miscinit.c:874
void SetSessionAuthorization(Oid userid, bool is_superuser)
Definition: miscinit.c:920
void SetCurrentRoleId(Oid roleid, bool is_superuser)
Definition: miscinit.c:956
ClientConnectionInfo MyClientConnectionInfo
Definition: miscinit.c:1018
void RestoreClientConnectionInfo(char *conninfo)
Definition: miscinit.c:1084
void SetAuthenticatedUserId(Oid userid)
Definition: miscinit.c:552
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:619
void SetTempNamespaceState(Oid tempNamespaceId, Oid tempToastNamespaceId)
Definition: namespace.c:3891
void RestoreUncommittedEnums(void *space)
Definition: pg_enum.c:886
#define die(msg)
Definition: pg_test_fsync.c:99
#define pqsignal
Definition: port.h:551
static uint32 DatumGetUInt32(Datum X)
Definition: postgres.h:232
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:352
BackgroundWorker * MyBgworkerEntry
Definition: postmaster.c:200
void pq_set_parallel_leader(pid_t pid, ProcNumber procNumber)
Definition: pqmq.c:82
void pq_redirect_to_shm_mq(dsm_segment *seg, shm_mq_handle *mqh)
Definition: pqmq.c:53
void AttachSerializableXact(SerializableXactHandle handle)
Definition: predicate.c:5054
#define PqMsg_Terminate
Definition: protocol.h:28
void RestoreRelationMap(char *startAddress)
Definition: relmapper.c:741
void DetachSession(void)
Definition: session.c:201
void AttachSession(dsm_handle handle)
Definition: session.c:155
void shm_mq_set_sender(shm_mq *mq, PGPROC *proc)
Definition: shm_mq.c:224
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
shm_toc * shm_toc_attach(uint64 magic, void *address)
Definition: shm_toc.c:64
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:682
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:1793
void RestoreTransactionSnapshot(Snapshot snapshot, PGPROC *source_pgproc)
Definition: snapmgr.c:1853
void PopActiveSnapshot(void)
Definition: snapmgr.c:775
bool BecomeLockGroupMember(PGPROC *leader, int pid)
Definition: proc.c:2041
void RestorePendingSyncs(char *startAddress)
Definition: storage.c:651
const char * authn_id
Definition: libpq-be.h:99
UserAuth auth_method
Definition: libpq-be.h:105
void ExitParallelMode(void)
Definition: xact.c:1065
void EnterParallelMode(void)
Definition: xact.c:1052
void StartTransactionCommand(void)
Definition: xact.c:3080
void StartParallelWorkerTransaction(char *tstatespace)
Definition: xact.c:5633
void SetParallelStartTimestamps(TimestampTz xact_ts, TimestampTz stmt_ts)
Definition: xact.c:860
void EndParallelWorkerTransaction(void)
Definition: xact.c:5658
void CommitTransactionCommand(void)
Definition: xact.c:3178

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), AttachSerializableXact(), AttachSession(), ClientConnectionInfo::auth_method, FixedParallelState::authenticated_user_id, ClientConnectionInfo::authn_id, BackgroundWorkerInitializeConnectionByOid(), BackgroundWorkerUnblockSignals(), BecomeLockGroupMember(), before_shmem_exit(), BackgroundWorker::bgw_extra, BGWORKER_BYPASS_ALLOWCONN, BGWORKER_BYPASS_ROLELOGINCHECK, CommitTransactionCommand(), FixedParallelState::current_user_id, CurrentMemoryContext, FixedParallelState::database_id, DatumGetUInt32(), DetachSession(), die, dsm_attach(), dsm_segment_address(), elog, EndParallelWorkerTransaction(), EnterParallelMode(), ereport, errcode(), errmsg(), ERROR, ExitParallelMode(), GetDatabaseEncoding(), hba_authname(), InitializeSystemUser(), InitializingParallelWorker, InvalidateSystemCaches(), LookupParallelWorkerFunction(), MyBgworkerEntry, MyClientConnectionInfo, MyFixedParallelState, MyProc, FixedParallelState::outer_user_id, PARALLEL_ERROR_QUEUE_SIZE, PARALLEL_KEY_ACTIVE_SNAPSHOT, PARALLEL_KEY_CLIENTCONNINFO, PARALLEL_KEY_COMBO_CID, PARALLEL_KEY_ENTRYPOINT, PARALLEL_KEY_ERROR_QUEUE, PARALLEL_KEY_FIXED, PARALLEL_KEY_GUC, PARALLEL_KEY_LIBRARY, PARALLEL_KEY_PENDING_SYNCS, PARALLEL_KEY_REINDEX_STATE, PARALLEL_KEY_RELMAPPER_STATE, PARALLEL_KEY_SESSION_DSM, PARALLEL_KEY_TRANSACTION_SNAPSHOT, PARALLEL_KEY_TRANSACTION_STATE, PARALLEL_KEY_UNCOMMITTEDENUMS, FixedParallelState::parallel_leader_pgproc, FixedParallelState::parallel_leader_pid, FixedParallelState::parallel_leader_proc_number, PARALLEL_MAGIC, ParallelLeaderPid, ParallelLeaderProcNumber, ParallelWorkerNumber, ParallelWorkerShutdown(), PointerGetDatum(), PopActiveSnapshot(), pq_putmessage, pq_redirect_to_shm_mq(), pq_set_parallel_leader(), PqMsg_Terminate, pqsignal, PushActiveSnapshot(), RestoreClientConnectionInfo(), RestoreComboCIDState(), RestoreGUCState(), RestoreLibraryState(), RestorePendingSyncs(), RestoreReindexState(), RestoreRelationMap(), RestoreSnapshot(), RestoreTransactionSnapshot(), RestoreUncommittedEnums(), FixedParallelState::role_is_superuser, FixedParallelState::sec_context, FixedParallelState::serializable_xact_handle, FixedParallelState::session_user_id, FixedParallelState::session_user_is_superuser, SetAuthenticatedUserId(), SetClientEncoding(), SetCurrentRoleId(), SetParallelStartTimestamps(), SetSessionAuthorization(), SetTempNamespaceState(), SetUserIdAndSecContext(), shm_mq_attach(), shm_mq_set_sender(), shm_toc_attach(), shm_toc_lookup(), StartParallelWorkerTransaction(), StartTransactionCommand(), FixedParallelState::stmt_ts, FixedParallelState::temp_namespace_id, FixedParallelState::temp_toast_namespace_id, TopMemoryContext, and FixedParallelState::xact_ts.

◆ ParallelWorkerReportLastRecEnd()

void ParallelWorkerReportLastRecEnd ( XLogRecPtr  last_xlog_end)

Definition at line 1593 of file parallel.c.

1594{
1596
1597 Assert(fps != NULL);
1598 SpinLockAcquire(&fps->mutex);
1599 if (fps->last_xlog_end < last_xlog_end)
1600 fps->last_xlog_end = last_xlog_end;
1601 SpinLockRelease(&fps->mutex);
1602}
#define SpinLockRelease(lock)
Definition: spin.h:61
#define SpinLockAcquire(lock)
Definition: spin.h:59

References Assert(), FixedParallelState::last_xlog_end, FixedParallelState::mutex, MyFixedParallelState, SpinLockAcquire, and SpinLockRelease.

Referenced by CommitTransaction().

◆ ProcessParallelMessages()

void ProcessParallelMessages ( void  )

Definition at line 1055 of file parallel.c.

1056{
1057 dlist_iter iter;
1058 MemoryContext oldcontext;
1059
1060 static MemoryContext hpm_context = NULL;
1061
1062 /*
1063 * This is invoked from ProcessInterrupts(), and since some of the
1064 * functions it calls contain CHECK_FOR_INTERRUPTS(), there is a potential
1065 * for recursive calls if more signals are received while this runs. It's
1066 * unclear that recursive entry would be safe, and it doesn't seem useful
1067 * even if it is safe, so let's block interrupts until done.
1068 */
1070
1071 /*
1072 * Moreover, CurrentMemoryContext might be pointing almost anywhere. We
1073 * don't want to risk leaking data into long-lived contexts, so let's do
1074 * our work here in a private context that we can reset on each use.
1075 */
1076 if (hpm_context == NULL) /* first time through? */
1078 "ProcessParallelMessages",
1080 else
1081 MemoryContextReset(hpm_context);
1082
1083 oldcontext = MemoryContextSwitchTo(hpm_context);
1084
1085 /* OK to process messages. Reset the flag saying there are more to do. */
1086 ParallelMessagePending = false;
1087
1088 dlist_foreach(iter, &pcxt_list)
1089 {
1090 ParallelContext *pcxt;
1091 int i;
1092
1093 pcxt = dlist_container(ParallelContext, node, iter.cur);
1094 if (pcxt->worker == NULL)
1095 continue;
1096
1097 for (i = 0; i < pcxt->nworkers_launched; ++i)
1098 {
1099 /*
1100 * Read as many messages as we can from each worker, but stop when
1101 * either (1) the worker's error queue goes away, which can happen
1102 * if we receive a Terminate message from the worker; or (2) no
1103 * more messages can be read from the worker without blocking.
1104 */
1105 while (pcxt->worker[i].error_mqh != NULL)
1106 {
1107 shm_mq_result res;
1108 Size nbytes;
1109 void *data;
1110
1111 res = shm_mq_receive(pcxt->worker[i].error_mqh, &nbytes,
1112 &data, true);
1113 if (res == SHM_MQ_WOULD_BLOCK)
1114 break;
1115 else if (res == SHM_MQ_SUCCESS)
1116 {
1117 StringInfoData msg;
1118
1119 initStringInfo(&msg);
1120 appendBinaryStringInfo(&msg, data, nbytes);
1121 ProcessParallelMessage(pcxt, i, &msg);
1122 pfree(msg.data);
1123 }
1124 else
1125 ereport(ERROR,
1126 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1127 errmsg("lost connection to parallel worker")));
1128 }
1129 }
1130 }
1131
1132 MemoryContextSwitchTo(oldcontext);
1133
1134 /* Might as well clear the context on our way out */
1135 MemoryContextReset(hpm_context);
1136
1138}
static void ProcessParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
Definition: parallel.c:1144
#define dlist_foreach(iter, lhead)
Definition: ilist.h:623
#define dlist_container(type, membername, ptr)
Definition: ilist.h:593
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:403
const void * data
shm_mq_result shm_mq_receive(shm_mq_handle *mqh, Size *nbytesp, void **datap, bool nowait)
Definition: shm_mq.c:572
shm_mq_result
Definition: shm_mq.h:37
@ SHM_MQ_SUCCESS
Definition: shm_mq.h:38
@ SHM_MQ_WOULD_BLOCK
Definition: shm_mq.h:39
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition: stringinfo.c:281
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
dlist_node * cur
Definition: ilist.h:179

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, appendBinaryStringInfo(), dlist_iter::cur, StringInfoData::data, data, dlist_container, dlist_foreach, ereport, errcode(), errmsg(), ERROR, ParallelWorkerInfo::error_mqh, HOLD_INTERRUPTS, i, initStringInfo(), MemoryContextReset(), MemoryContextSwitchTo(), ParallelContext::nworkers_launched, ParallelMessagePending, pcxt_list, pfree(), ProcessParallelMessage(), RESUME_INTERRUPTS, shm_mq_receive(), SHM_MQ_SUCCESS, SHM_MQ_WOULD_BLOCK, TopMemoryContext, and ParallelContext::worker.

Referenced by ProcessInterrupts().

◆ ReinitializeParallelDSM()

void ReinitializeParallelDSM ( ParallelContext pcxt)

Definition at line 509 of file parallel.c.

510{
511 MemoryContext oldcontext;
513
514 /* We might be running in a very short-lived memory context. */
516
517 /* Wait for any old workers to exit. */
518 if (pcxt->nworkers_launched > 0)
519 {
522 pcxt->nworkers_launched = 0;
523 if (pcxt->known_attached_workers)
524 {
526 pcxt->known_attached_workers = NULL;
527 pcxt->nknown_attached_workers = 0;
528 }
529 }
530
531 /* Reset a few bits of fixed parallel state to a clean state. */
532 fps = shm_toc_lookup(pcxt->toc, PARALLEL_KEY_FIXED, false);
533 fps->last_xlog_end = 0;
534
535 /* Recreate error queues (if they exist). */
536 if (pcxt->nworkers > 0)
537 {
538 char *error_queue_space;
539 int i;
540
541 error_queue_space =
543 for (i = 0; i < pcxt->nworkers; ++i)
544 {
545 char *start;
546 shm_mq *mq;
547
548 start = error_queue_space + i * PARALLEL_ERROR_QUEUE_SIZE;
551 pcxt->worker[i].error_mqh = shm_mq_attach(mq, pcxt->seg, NULL);
552 }
553 }
554
555 /* Restore previous memory context. */
556 MemoryContextSwitchTo(oldcontext);
557}
void WaitForParallelWorkersToFinish(ParallelContext *pcxt)
Definition: parallel.c:803

References ParallelWorkerInfo::error_mqh, i, ParallelContext::known_attached_workers, FixedParallelState::last_xlog_end, MemoryContextSwitchTo(), MyProc, ParallelContext::nknown_attached_workers, ParallelContext::nworkers, ParallelContext::nworkers_launched, PARALLEL_ERROR_QUEUE_SIZE, PARALLEL_KEY_ERROR_QUEUE, PARALLEL_KEY_FIXED, pfree(), ParallelContext::seg, shm_mq_attach(), shm_mq_create(), shm_mq_set_receiver(), shm_toc_lookup(), start, ParallelContext::toc, TopTransactionContext, WaitForParallelWorkersToExit(), WaitForParallelWorkersToFinish(), and ParallelContext::worker.

Referenced by ExecParallelReinitialize(), and parallel_vacuum_process_all_indexes().

◆ ReinitializeParallelWorkers()

void ReinitializeParallelWorkers ( ParallelContext pcxt,
int  nworkers_to_launch 
)

Definition at line 566 of file parallel.c.

567{
568 /*
569 * The number of workers that need to be launched must be less than the
570 * number of workers with which the parallel context is initialized. But
571 * the caller might not know that InitializeParallelDSM reduced nworkers,
572 * so just silently trim the request.
573 */
574 pcxt->nworkers_to_launch = Min(pcxt->nworkers, nworkers_to_launch);
575}
#define Min(x, y)
Definition: c.h:1003

References Min, ParallelContext::nworkers, and ParallelContext::nworkers_to_launch.

Referenced by parallel_vacuum_process_all_indexes().

◆ WaitForParallelWorkersToAttach()

void WaitForParallelWorkersToAttach ( ParallelContext pcxt)

Definition at line 700 of file parallel.c.

701{
702 int i;
703
704 /* Skip this if we have no launched workers. */
705 if (pcxt->nworkers_launched == 0)
706 return;
707
708 for (;;)
709 {
710 /*
711 * This will process any parallel messages that are pending and it may
712 * also throw an error propagated from a worker.
713 */
715
716 for (i = 0; i < pcxt->nworkers_launched; ++i)
717 {
718 BgwHandleStatus status;
719 shm_mq *mq;
720 int rc;
721 pid_t pid;
722
723 if (pcxt->known_attached_workers[i])
724 continue;
725
726 /*
727 * If error_mqh is NULL, then the worker has already exited
728 * cleanly.
729 */
730 if (pcxt->worker[i].error_mqh == NULL)
731 {
732 pcxt->known_attached_workers[i] = true;
734 continue;
735 }
736
737 status = GetBackgroundWorkerPid(pcxt->worker[i].bgwhandle, &pid);
738 if (status == BGWH_STARTED)
739 {
740 /* Has the worker attached to the error queue? */
741 mq = shm_mq_get_queue(pcxt->worker[i].error_mqh);
742 if (shm_mq_get_sender(mq) != NULL)
743 {
744 /* Yes, so it is known to be attached. */
745 pcxt->known_attached_workers[i] = true;
747 }
748 }
749 else if (status == BGWH_STOPPED)
750 {
751 /*
752 * If the worker stopped without attaching to the error queue,
753 * throw an error.
754 */
755 mq = shm_mq_get_queue(pcxt->worker[i].error_mqh);
756 if (shm_mq_get_sender(mq) == NULL)
758 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
759 errmsg("parallel worker failed to initialize"),
760 errhint("More details may be available in the server log.")));
761
762 pcxt->known_attached_workers[i] = true;
764 }
765 else
766 {
767 /*
768 * Worker not yet started, so we must wait. The postmaster
769 * will notify us if the worker's state changes. Our latch
770 * might also get set for some other reason, but if so we'll
771 * just end up waiting for the same worker again.
772 */
773 rc = WaitLatch(MyLatch,
775 -1, WAIT_EVENT_BGWORKER_STARTUP);
776
777 if (rc & WL_LATCH_SET)
779 }
780 }
781
782 /* If all workers are known to have started, we're done. */
784 {
786 break;
787 }
788 }
789}
BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle, pid_t *pidp)
Definition: bgworker.c:1173
BgwHandleStatus
Definition: bgworker.h:111
@ BGWH_STARTED
Definition: bgworker.h:112
@ BGWH_STOPPED
Definition: bgworker.h:114
int errhint(const char *fmt,...)
Definition: elog.c:1330
void ResetLatch(Latch *latch)
Definition: latch.c:374
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:172
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:123
shm_mq * shm_mq_get_queue(shm_mq_handle *mqh)
Definition: shm_mq.c:905
PGPROC * shm_mq_get_sender(shm_mq *mq)
Definition: shm_mq.c:257
#define WL_EXIT_ON_PM_DEATH
Definition: waiteventset.h:39
#define WL_LATCH_SET
Definition: waiteventset.h:34

References Assert(), BGWH_STARTED, BGWH_STOPPED, ParallelWorkerInfo::bgwhandle, CHECK_FOR_INTERRUPTS, ereport, errcode(), errhint(), errmsg(), ERROR, ParallelWorkerInfo::error_mqh, GetBackgroundWorkerPid(), i, ParallelContext::known_attached_workers, MyLatch, ParallelContext::nknown_attached_workers, ParallelContext::nworkers_launched, ResetLatch(), shm_mq_get_queue(), shm_mq_get_sender(), WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, and ParallelContext::worker.

Referenced by _brin_begin_parallel(), _bt_begin_parallel(), and _gin_begin_parallel().

◆ WaitForParallelWorkersToFinish()

void WaitForParallelWorkersToFinish ( ParallelContext pcxt)

Definition at line 803 of file parallel.c.

804{
805 for (;;)
806 {
807 bool anyone_alive = false;
808 int nfinished = 0;
809 int i;
810
811 /*
812 * This will process any parallel messages that are pending, which may
813 * change the outcome of the loop that follows. It may also throw an
814 * error propagated from a worker.
815 */
817
818 for (i = 0; i < pcxt->nworkers_launched; ++i)
819 {
820 /*
821 * If error_mqh is NULL, then the worker has already exited
822 * cleanly. If we have received a message through error_mqh from
823 * the worker, we know it started up cleanly, and therefore we're
824 * certain to be notified when it exits.
825 */
826 if (pcxt->worker[i].error_mqh == NULL)
827 ++nfinished;
828 else if (pcxt->known_attached_workers[i])
829 {
830 anyone_alive = true;
831 break;
832 }
833 }
834
835 if (!anyone_alive)
836 {
837 /* If all workers are known to have finished, we're done. */
838 if (nfinished >= pcxt->nworkers_launched)
839 {
840 Assert(nfinished == pcxt->nworkers_launched);
841 break;
842 }
843
844 /*
845 * We didn't detect any living workers, but not all workers are
846 * known to have exited cleanly. Either not all workers have
847 * launched yet, or maybe some of them failed to start or
848 * terminated abnormally.
849 */
850 for (i = 0; i < pcxt->nworkers_launched; ++i)
851 {
852 pid_t pid;
853 shm_mq *mq;
854
855 /*
856 * If the worker is BGWH_NOT_YET_STARTED or BGWH_STARTED, we
857 * should just keep waiting. If it is BGWH_STOPPED, then
858 * further investigation is needed.
859 */
860 if (pcxt->worker[i].error_mqh == NULL ||
861 pcxt->worker[i].bgwhandle == NULL ||
863 &pid) != BGWH_STOPPED)
864 continue;
865
866 /*
867 * Check whether the worker ended up stopped without ever
868 * attaching to the error queue. If so, the postmaster was
869 * unable to fork the worker or it exited without initializing
870 * properly. We must throw an error, since the caller may
871 * have been expecting the worker to do some work before
872 * exiting.
873 */
874 mq = shm_mq_get_queue(pcxt->worker[i].error_mqh);
875 if (shm_mq_get_sender(mq) == NULL)
877 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
878 errmsg("parallel worker failed to initialize"),
879 errhint("More details may be available in the server log.")));
880
881 /*
882 * The worker is stopped, but is attached to the error queue.
883 * Unless there's a bug somewhere, this will only happen when
884 * the worker writes messages and terminates after the
885 * CHECK_FOR_INTERRUPTS() near the top of this function and
886 * before the call to GetBackgroundWorkerPid(). In that case,
887 * our latch should have been set as well and the right things
888 * will happen on the next pass through the loop.
889 */
890 }
891 }
892
894 WAIT_EVENT_PARALLEL_FINISH);
896 }
897
898 if (pcxt->toc != NULL)
899 {
901
902 fps = shm_toc_lookup(pcxt->toc, PARALLEL_KEY_FIXED, false);
903 if (fps->last_xlog_end > XactLastRecEnd)
905 }
906}
XLogRecPtr XactLastRecEnd
Definition: xlog.c:257

References Assert(), BGWH_STOPPED, ParallelWorkerInfo::bgwhandle, CHECK_FOR_INTERRUPTS, ereport, errcode(), errhint(), errmsg(), ERROR, ParallelWorkerInfo::error_mqh, GetBackgroundWorkerPid(), i, ParallelContext::known_attached_workers, FixedParallelState::last_xlog_end, MyLatch, ParallelContext::nworkers_launched, PARALLEL_KEY_FIXED, ResetLatch(), shm_mq_get_queue(), shm_mq_get_sender(), shm_toc_lookup(), ParallelContext::toc, WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, ParallelContext::worker, and XactLastRecEnd.

Referenced by _brin_end_parallel(), _bt_end_parallel(), _gin_end_parallel(), ExecParallelFinish(), parallel_vacuum_process_all_indexes(), and ReinitializeParallelDSM().

Variable Documentation

◆ InitializingParallelWorker

◆ ParallelMessagePending

PGDLLIMPORT volatile sig_atomic_t ParallelMessagePending
extern

◆ ParallelWorkerNumber