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 HandleParallelMessages (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 61 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 1248 of file parallel.c.

1249 {
1250  while (!dlist_is_empty(&pcxt_list))
1251  {
1252  ParallelContext *pcxt;
1253 
1255  if (pcxt->subid != mySubId)
1256  break;
1257  if (isCommit)
1258  elog(WARNING, "leaked parallel context");
1259  DestroyParallelContext(pcxt);
1260  }
1261 }
void DestroyParallelContext(ParallelContext *pcxt)
Definition: parallel.c:932
static dlist_head pcxt_list
Definition: parallel.c:127
#define WARNING
Definition: elog.h:36
#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:35

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 1267 of file parallel.c.

1268 {
1269  while (!dlist_is_empty(&pcxt_list))
1270  {
1271  ParallelContext *pcxt;
1272 
1274  if (isCommit)
1275  elog(WARNING, "leaked parallel context");
1276  DestroyParallelContext(pcxt);
1277  }
1278 }

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 170 of file parallel.c.

172 {
173  MemoryContext oldcontext;
174  ParallelContext *pcxt;
175 
176  /* It is unsafe to create a parallel context if not in parallel mode. */
178 
179  /* Number of workers should be non-negative. */
180  Assert(nworkers >= 0);
181 
182  /* We might be running in a short-lived memory context. */
184 
185  /* Initialize a new ParallelContext. */
186  pcxt = palloc0(sizeof(ParallelContext));
188  pcxt->nworkers = nworkers;
189  pcxt->nworkers_to_launch = nworkers;
190  pcxt->library_name = pstrdup(library_name);
191  pcxt->function_name = pstrdup(function_name);
194  dlist_push_head(&pcxt_list, &pcxt->node);
195 
196  /* Restore previous memory context. */
197  MemoryContextSwitchTo(oldcontext);
198 
199  return pcxt;
200 }
ErrorContextCallback * error_context_stack
Definition: elog.c:95
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:347
Assert(fmt[strlen(fmt) - 1] !='\n')
MemoryContext TopTransactionContext
Definition: mcxt.c:146
char * pstrdup(const char *in)
Definition: mcxt.c:1619
void * palloc0(Size size)
Definition: mcxt.c:1232
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:39
ErrorContextCallback * error_context_stack
Definition: parallel.h:41
shm_toc_estimator estimator
Definition: parallel.h:42
dlist_node node
Definition: parallel.h:34
int nworkers_to_launch
Definition: parallel.h:37
char * function_name
Definition: parallel.h:40
SubTransactionId GetCurrentSubTransactionId(void)
Definition: xact.c:780
bool IsInParallelMode(void)
Definition: xact.c:1069

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(), pcxt_list, pstrdup(), shm_toc_initialize_estimator, ParallelContext::subid, and TopTransactionContext.

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

◆ DestroyParallelContext()

void DestroyParallelContext ( ParallelContext pcxt)

Definition at line 932 of file parallel.c.

933 {
934  int i;
935 
936  /*
937  * Be careful about order of operations here! We remove the parallel
938  * context from the list before we do anything else; otherwise, if an
939  * error occurs during a subsequent step, we might try to nuke it again
940  * from AtEOXact_Parallel or AtEOSubXact_Parallel.
941  */
942  dlist_delete(&pcxt->node);
943 
944  /* Kill each worker in turn, and forget their error queues. */
945  if (pcxt->worker != NULL)
946  {
947  for (i = 0; i < pcxt->nworkers_launched; ++i)
948  {
949  if (pcxt->worker[i].error_mqh != NULL)
950  {
952 
954  pcxt->worker[i].error_mqh = NULL;
955  }
956  }
957  }
958 
959  /*
960  * If we have allocated a shared memory segment, detach it. This will
961  * implicitly detach the error queues, and any other shared memory queues,
962  * stored there.
963  */
964  if (pcxt->seg != NULL)
965  {
966  dsm_detach(pcxt->seg);
967  pcxt->seg = NULL;
968  }
969 
970  /*
971  * If this parallel context is actually in backend-private memory rather
972  * than shared memory, free that memory instead.
973  */
974  if (pcxt->private_memory != NULL)
975  {
976  pfree(pcxt->private_memory);
977  pcxt->private_memory = NULL;
978  }
979 
980  /*
981  * We can't finish transaction commit or abort until all of the workers
982  * have exited. This means, in particular, that we can't respond to
983  * interrupts at this stage.
984  */
985  HOLD_INTERRUPTS();
988 
989  /* Free the worker array itself. */
990  if (pcxt->worker != NULL)
991  {
992  pfree(pcxt->worker);
993  pcxt->worker = NULL;
994  }
995 
996  /* Free memory. */
997  pfree(pcxt->library_name);
998  pfree(pcxt->function_name);
999  pfree(pcxt);
1000 }
static void WaitForParallelWorkersToExit(ParallelContext *pcxt)
Definition: parallel.c:892
void TerminateBackgroundWorker(BackgroundWorkerHandle *handle)
Definition: bgworker.c:1211
void dsm_detach(dsm_segment *seg)
Definition: dsm.c:804
static void dlist_delete(dlist_node *node)
Definition: ilist.h:405
int i
Definition: isn.c:73
void pfree(void *pointer)
Definition: mcxt.c:1431
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:135
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:133
void shm_mq_detach(shm_mq_handle *mqh)
Definition: shm_mq.c:844
dsm_segment * seg
Definition: parallel.h:43
ParallelWorkerInfo * worker
Definition: parallel.h:46
void * private_memory
Definition: parallel.h:44
int nworkers_launched
Definition: parallel.h:38
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(), AtEOSubXact_Parallel(), AtEOXact_Parallel(), ExecParallelCleanup(), and parallel_vacuum_end().

◆ HandleParallelMessageInterrupt()

void HandleParallelMessageInterrupt ( void  )

Definition at line 1019 of file parallel.c.

1020 {
1021  InterruptPending = true;
1022  ParallelMessagePending = true;
1023  SetLatch(MyLatch);
1024 }
volatile sig_atomic_t ParallelMessagePending
Definition: parallel.c:118
volatile sig_atomic_t InterruptPending
Definition: globals.c:30
struct Latch * MyLatch
Definition: globals.c:59
void SetLatch(Latch *latch)
Definition: latch.c:633

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

Referenced by procsignal_sigusr1_handler().

◆ HandleParallelMessages()

void HandleParallelMessages ( void  )

Definition at line 1030 of file parallel.c.

1031 {
1032  dlist_iter iter;
1033  MemoryContext oldcontext;
1034 
1035  static MemoryContext hpm_context = NULL;
1036 
1037  /*
1038  * This is invoked from ProcessInterrupts(), and since some of the
1039  * functions it calls contain CHECK_FOR_INTERRUPTS(), there is a potential
1040  * for recursive calls if more signals are received while this runs. It's
1041  * unclear that recursive entry would be safe, and it doesn't seem useful
1042  * even if it is safe, so let's block interrupts until done.
1043  */
1044  HOLD_INTERRUPTS();
1045 
1046  /*
1047  * Moreover, CurrentMemoryContext might be pointing almost anywhere. We
1048  * don't want to risk leaking data into long-lived contexts, so let's do
1049  * our work here in a private context that we can reset on each use.
1050  */
1051  if (hpm_context == NULL) /* first time through? */
1053  "HandleParallelMessages",
1055  else
1056  MemoryContextReset(hpm_context);
1057 
1058  oldcontext = MemoryContextSwitchTo(hpm_context);
1059 
1060  /* OK to process messages. Reset the flag saying there are more to do. */
1061  ParallelMessagePending = false;
1062 
1063  dlist_foreach(iter, &pcxt_list)
1064  {
1065  ParallelContext *pcxt;
1066  int i;
1067 
1068  pcxt = dlist_container(ParallelContext, node, iter.cur);
1069  if (pcxt->worker == NULL)
1070  continue;
1071 
1072  for (i = 0; i < pcxt->nworkers_launched; ++i)
1073  {
1074  /*
1075  * Read as many messages as we can from each worker, but stop when
1076  * either (1) the worker's error queue goes away, which can happen
1077  * if we receive a Terminate message from the worker; or (2) no
1078  * more messages can be read from the worker without blocking.
1079  */
1080  while (pcxt->worker[i].error_mqh != NULL)
1081  {
1083  Size nbytes;
1084  void *data;
1085 
1086  res = shm_mq_receive(pcxt->worker[i].error_mqh, &nbytes,
1087  &data, true);
1088  if (res == SHM_MQ_WOULD_BLOCK)
1089  break;
1090  else if (res == SHM_MQ_SUCCESS)
1091  {
1092  StringInfoData msg;
1093 
1094  initStringInfo(&msg);
1095  appendBinaryStringInfo(&msg, data, nbytes);
1096  HandleParallelMessage(pcxt, i, &msg);
1097  pfree(msg.data);
1098  }
1099  else
1100  ereport(ERROR,
1101  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1102  errmsg("lost connection to parallel worker")));
1103  }
1104  }
1105  }
1106 
1107  MemoryContextSwitchTo(oldcontext);
1108 
1109  /* Might as well clear the context on our way out */
1110  MemoryContextReset(hpm_context);
1111 
1113 }
static void HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
Definition: parallel.c:1119
size_t Size
Definition: c.h:594
int errcode(int sqlerrcode)
Definition: elog.c:860
int errmsg(const char *fmt,...)
Definition: elog.c:1075
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#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:330
MemoryContext TopMemoryContext
Definition: mcxt.c:141
#define AllocSetContextCreate
Definition: memutils.h:128
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:152
const void * data
shm_mq_result shm_mq_receive(shm_mq_handle *mqh, Size *nbytesp, void **datap, bool nowait)
Definition: shm_mq.c:573
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:233
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
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, HandleParallelMessage(), HOLD_INTERRUPTS, i, initStringInfo(), MemoryContextReset(), MemoryContextSwitchTo(), ParallelContext::nworkers_launched, ParallelMessagePending, pcxt_list, pfree(), res, RESUME_INTERRUPTS, shm_mq_receive(), SHM_MQ_SUCCESS, SHM_MQ_WOULD_BLOCK, TopMemoryContext, and ParallelContext::worker.

Referenced by ProcessInterrupts().

◆ InitializeParallelDSM()

void InitializeParallelDSM ( ParallelContext pcxt)

Definition at line 208 of file parallel.c.

209 {
210  MemoryContext oldcontext;
211  Size library_len = 0;
212  Size guc_len = 0;
213  Size combocidlen = 0;
214  Size tsnaplen = 0;
215  Size asnaplen = 0;
216  Size tstatelen = 0;
217  Size pendingsyncslen = 0;
218  Size reindexlen = 0;
219  Size relmapperlen = 0;
220  Size uncommittedenumslen = 0;
221  Size clientconninfolen = 0;
222  Size segsize = 0;
223  int i;
224  FixedParallelState *fps;
225  dsm_handle session_dsm_handle = DSM_HANDLE_INVALID;
226  Snapshot transaction_snapshot = GetTransactionSnapshot();
227  Snapshot active_snapshot = GetActiveSnapshot();
228 
229  /* We might be running in a very short-lived memory context. */
231 
232  /* Allow space to store the fixed-size parallel state. */
234  shm_toc_estimate_keys(&pcxt->estimator, 1);
235 
236  /*
237  * Normally, the user will have requested at least one worker process, but
238  * if by chance they have not, we can skip a bunch of things here.
239  */
240  if (pcxt->nworkers > 0)
241  {
242  /* Get (or create) the per-session DSM segment's handle. */
243  session_dsm_handle = GetSessionDsmHandle();
244 
245  /*
246  * If we weren't able to create a per-session DSM segment, then we can
247  * continue but we can't safely launch any workers because their
248  * record typmods would be incompatible so they couldn't exchange
249  * tuples.
250  */
251  if (session_dsm_handle == DSM_HANDLE_INVALID)
252  pcxt->nworkers = 0;
253  }
254 
255  if (pcxt->nworkers > 0)
256  {
257  /* Estimate space for various kinds of state sharing. */
258  library_len = EstimateLibraryStateSpace();
259  shm_toc_estimate_chunk(&pcxt->estimator, library_len);
260  guc_len = EstimateGUCStateSpace();
261  shm_toc_estimate_chunk(&pcxt->estimator, guc_len);
262  combocidlen = EstimateComboCIDStateSpace();
263  shm_toc_estimate_chunk(&pcxt->estimator, combocidlen);
265  {
266  tsnaplen = EstimateSnapshotSpace(transaction_snapshot);
267  shm_toc_estimate_chunk(&pcxt->estimator, tsnaplen);
268  }
269  asnaplen = EstimateSnapshotSpace(active_snapshot);
270  shm_toc_estimate_chunk(&pcxt->estimator, asnaplen);
271  tstatelen = EstimateTransactionStateSpace();
272  shm_toc_estimate_chunk(&pcxt->estimator, tstatelen);
274  pendingsyncslen = EstimatePendingSyncsSpace();
275  shm_toc_estimate_chunk(&pcxt->estimator, pendingsyncslen);
276  reindexlen = EstimateReindexStateSpace();
277  shm_toc_estimate_chunk(&pcxt->estimator, reindexlen);
278  relmapperlen = EstimateRelationMapSpace();
279  shm_toc_estimate_chunk(&pcxt->estimator, relmapperlen);
280  uncommittedenumslen = EstimateUncommittedEnumsSpace();
281  shm_toc_estimate_chunk(&pcxt->estimator, uncommittedenumslen);
282  clientconninfolen = EstimateClientConnectionInfoSpace();
283  shm_toc_estimate_chunk(&pcxt->estimator, clientconninfolen);
284  /* If you add more chunks here, you probably need to add keys. */
285  shm_toc_estimate_keys(&pcxt->estimator, 12);
286 
287  /* Estimate space need for error queues. */
290  "parallel error queue size not buffer-aligned");
293  pcxt->nworkers));
294  shm_toc_estimate_keys(&pcxt->estimator, 1);
295 
296  /* Estimate how much we'll need for the entrypoint info. */
297  shm_toc_estimate_chunk(&pcxt->estimator, strlen(pcxt->library_name) +
298  strlen(pcxt->function_name) + 2);
299  shm_toc_estimate_keys(&pcxt->estimator, 1);
300  }
301 
302  /*
303  * Create DSM and initialize with new table of contents. But if the user
304  * didn't request any workers, then don't bother creating a dynamic shared
305  * memory segment; instead, just use backend-private memory.
306  *
307  * Also, if we can't create a dynamic shared memory segment because the
308  * maximum number of segments have already been created, then fall back to
309  * backend-private memory, and plan not to use any workers. We hope this
310  * won't happen very often, but it's better to abandon the use of
311  * parallelism than to fail outright.
312  */
313  segsize = shm_toc_estimate(&pcxt->estimator);
314  if (pcxt->nworkers > 0)
316  if (pcxt->seg != NULL)
318  dsm_segment_address(pcxt->seg),
319  segsize);
320  else
321  {
322  pcxt->nworkers = 0;
325  segsize);
326  }
327 
328  /* Initialize fixed-size state in shared memory. */
329  fps = (FixedParallelState *)
330  shm_toc_allocate(pcxt->toc, sizeof(FixedParallelState));
331  fps->database_id = MyDatabaseId;
344  SpinLockInit(&fps->mutex);
345  fps->last_xlog_end = 0;
347 
348  /* We can skip the rest of this if we're not budgeting for any workers. */
349  if (pcxt->nworkers > 0)
350  {
351  char *libraryspace;
352  char *gucspace;
353  char *combocidspace;
354  char *tsnapspace;
355  char *asnapspace;
356  char *tstatespace;
357  char *pendingsyncsspace;
358  char *reindexspace;
359  char *relmapperspace;
360  char *error_queue_space;
361  char *session_dsm_handle_space;
362  char *entrypointstate;
363  char *uncommittedenumsspace;
364  char *clientconninfospace;
365  Size lnamelen;
366 
367  /* Serialize shared libraries we have loaded. */
368  libraryspace = shm_toc_allocate(pcxt->toc, library_len);
369  SerializeLibraryState(library_len, libraryspace);
370  shm_toc_insert(pcxt->toc, PARALLEL_KEY_LIBRARY, libraryspace);
371 
372  /* Serialize GUC settings. */
373  gucspace = shm_toc_allocate(pcxt->toc, guc_len);
374  SerializeGUCState(guc_len, gucspace);
375  shm_toc_insert(pcxt->toc, PARALLEL_KEY_GUC, gucspace);
376 
377  /* Serialize combo CID state. */
378  combocidspace = shm_toc_allocate(pcxt->toc, combocidlen);
379  SerializeComboCIDState(combocidlen, combocidspace);
380  shm_toc_insert(pcxt->toc, PARALLEL_KEY_COMBO_CID, combocidspace);
381 
382  /*
383  * Serialize the transaction snapshot if the transaction isolation
384  * level uses a transaction snapshot.
385  */
387  {
388  tsnapspace = shm_toc_allocate(pcxt->toc, tsnaplen);
389  SerializeSnapshot(transaction_snapshot, tsnapspace);
391  tsnapspace);
392  }
393 
394  /* Serialize the active snapshot. */
395  asnapspace = shm_toc_allocate(pcxt->toc, asnaplen);
396  SerializeSnapshot(active_snapshot, asnapspace);
397  shm_toc_insert(pcxt->toc, PARALLEL_KEY_ACTIVE_SNAPSHOT, asnapspace);
398 
399  /* Provide the handle for per-session segment. */
400  session_dsm_handle_space = shm_toc_allocate(pcxt->toc,
401  sizeof(dsm_handle));
402  *(dsm_handle *) session_dsm_handle_space = session_dsm_handle;
404  session_dsm_handle_space);
405 
406  /* Serialize transaction state. */
407  tstatespace = shm_toc_allocate(pcxt->toc, tstatelen);
408  SerializeTransactionState(tstatelen, tstatespace);
410 
411  /* Serialize pending syncs. */
412  pendingsyncsspace = shm_toc_allocate(pcxt->toc, pendingsyncslen);
413  SerializePendingSyncs(pendingsyncslen, pendingsyncsspace);
415  pendingsyncsspace);
416 
417  /* Serialize reindex state. */
418  reindexspace = shm_toc_allocate(pcxt->toc, reindexlen);
419  SerializeReindexState(reindexlen, reindexspace);
420  shm_toc_insert(pcxt->toc, PARALLEL_KEY_REINDEX_STATE, reindexspace);
421 
422  /* Serialize relmapper state. */
423  relmapperspace = shm_toc_allocate(pcxt->toc, relmapperlen);
424  SerializeRelationMap(relmapperlen, relmapperspace);
426  relmapperspace);
427 
428  /* Serialize uncommitted enum state. */
429  uncommittedenumsspace = shm_toc_allocate(pcxt->toc,
430  uncommittedenumslen);
431  SerializeUncommittedEnums(uncommittedenumsspace, uncommittedenumslen);
433  uncommittedenumsspace);
434 
435  /* Serialize our ClientConnectionInfo. */
436  clientconninfospace = shm_toc_allocate(pcxt->toc, clientconninfolen);
437  SerializeClientConnectionInfo(clientconninfolen, clientconninfospace);
439  clientconninfospace);
440 
441  /* Allocate space for worker information. */
442  pcxt->worker = palloc0(sizeof(ParallelWorkerInfo) * pcxt->nworkers);
443 
444  /*
445  * Establish error queues in dynamic shared memory.
446  *
447  * These queues should be used only for transmitting ErrorResponse,
448  * NoticeResponse, and NotifyResponse protocol messages. Tuple data
449  * should be transmitted via separate (possibly larger?) queues.
450  */
451  error_queue_space =
452  shm_toc_allocate(pcxt->toc,
454  pcxt->nworkers));
455  for (i = 0; i < pcxt->nworkers; ++i)
456  {
457  char *start;
458  shm_mq *mq;
459 
460  start = error_queue_space + i * PARALLEL_ERROR_QUEUE_SIZE;
463  pcxt->worker[i].error_mqh = shm_mq_attach(mq, pcxt->seg, NULL);
464  }
465  shm_toc_insert(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, error_queue_space);
466 
467  /*
468  * Serialize entrypoint information. It's unsafe to pass function
469  * pointers across processes, as the function pointer may be different
470  * in each process in EXEC_BACKEND builds, so we always pass library
471  * and function name. (We use library name "postgres" for functions
472  * in the core backend.)
473  */
474  lnamelen = strlen(pcxt->library_name);
475  entrypointstate = shm_toc_allocate(pcxt->toc, lnamelen +
476  strlen(pcxt->function_name) + 2);
477  strcpy(entrypointstate, pcxt->library_name);
478  strcpy(entrypointstate + lnamelen + 1, pcxt->function_name);
479  shm_toc_insert(pcxt->toc, PARALLEL_KEY_ENTRYPOINT, entrypointstate);
480  }
481 
482  /* Restore previous memory context. */
483  MemoryContextSwitchTo(oldcontext);
484 }
#define PARALLEL_KEY_TRANSACTION_STATE
Definition: parallel.c:74
#define PARALLEL_KEY_GUC
Definition: parallel.c:70
#define PARALLEL_KEY_UNCOMMITTEDENUMS
Definition: parallel.c:80
#define PARALLEL_KEY_TRANSACTION_SNAPSHOT
Definition: parallel.c:72
#define PARALLEL_KEY_CLIENTCONNINFO
Definition: parallel.c:81
#define PARALLEL_KEY_PENDING_SYNCS
Definition: parallel.c:77
#define PARALLEL_KEY_ACTIVE_SNAPSHOT
Definition: parallel.c:73
#define PARALLEL_KEY_ERROR_QUEUE
Definition: parallel.c:68
#define PARALLEL_KEY_SESSION_DSM
Definition: parallel.c:76
#define PARALLEL_MAGIC
Definition: parallel.c:60
#define PARALLEL_KEY_REINDEX_STATE
Definition: parallel.c:78
#define PARALLEL_KEY_LIBRARY
Definition: parallel.c:69
#define PARALLEL_KEY_FIXED
Definition: parallel.c:67
#define PARALLEL_KEY_ENTRYPOINT
Definition: parallel.c:75
#define PARALLEL_KEY_COMBO_CID
Definition: parallel.c:71
#define PARALLEL_ERROR_QUEUE_SIZE
Definition: parallel.c:57
#define PARALLEL_KEY_RELMAPPER_STATE
Definition: parallel.c:79
#define BUFFERALIGN(LEN)
Definition: c.h:802
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:927
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:654
Size EstimateLibraryStateSpace(void)
Definition: dfmgr.c:637
void * dsm_segment_address(dsm_segment *seg)
Definition: dsm.c:1096
dsm_segment * dsm_create(Size size, int flags)
Definition: dsm.c:517
#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
int MyProcPid
Definition: globals.c:45
BackendId MyBackendId
Definition: globals.c:86
Oid MyDatabaseId
Definition: globals.c:90
void SerializeGUCState(Size maxsize, char *start_address)
Definition: guc.c:6026
Size EstimateGUCStateSpace(void)
Definition: guc.c:5873
bool current_role_is_superuser
Definition: guc_tables.c:517
void SerializeReindexState(Size maxsize, char *start_address)
Definition: index.c:4210
Size EstimateReindexStateSpace(void)
Definition: index.c:4199
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1034
void SerializeClientConnectionInfo(Size maxsize, char *start_address)
Definition: miscinit.c:1039
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:632
Size EstimateClientConnectionInfoSpace(void)
Definition: miscinit.c:1023
Oid GetAuthenticatedUserId(void)
Definition: miscinit.c:580
Oid GetCurrentRoleId(void)
Definition: miscinit.c:920
void GetTempNamespaceState(Oid *tempNamespaceId, Oid *tempToastNamespaceId)
Definition: namespace.c:3790
Size EstimateUncommittedEnumsSpace(void)
Definition: pg_enum.c:724
void SerializeUncommittedEnums(void *space, Size size)
Definition: pg_enum.c:738
SerializableXactHandle ShareSerializableXact(void)
Definition: predicate.c:5016
Size EstimateRelationMapSpace(void)
Definition: relmapper.c:714
void SerializeRelationMap(Size maxSize, char *startAddress)
Definition: relmapper.c:725
dsm_handle GetSessionDsmHandle(void)
Definition: session.c:70
shm_mq_handle * shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:291
shm_mq * shm_mq_create(void *address, Size size)
Definition: shm_mq.c:178
void shm_mq_set_receiver(shm_mq *mq, PGPROC *proc)
Definition: shm_mq.c:207
shm_toc * shm_toc_create(uint64 magic, void *address, Size nbytes)
Definition: shm_toc.c:40
Size shm_toc_estimate(shm_toc_estimator *e)
Definition: shm_toc.c:263
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
#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:511
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:1722
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:223
Size EstimateSnapshotSpace(Snapshot snapshot)
Definition: snapmgr.c:1698
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:777
#define SpinLockInit(lock)
Definition: spin.h:60
PGPROC * MyProc
Definition: proc.c:67
void SerializePendingSyncs(Size maxSize, char *startAddress)
Definition: storage.c:577
Size EstimatePendingSyncsSpace(void)
Definition: storage.c:564
Oid temp_toast_namespace_id
Definition: parallel.c:92
XLogRecPtr last_xlog_end
Definition: parallel.c:106
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
pid_t parallel_leader_pid
Definition: parallel.c:96
BackendId parallel_leader_backend_id
Definition: parallel.c:97
Oid authenticated_user_id
Definition: parallel.c:88
shm_toc * toc
Definition: parallel.h:45
Definition: shm_mq.c:73
void SerializeTransactionState(Size maxsize, char *start_address)
Definition: xact.c:5402
Size EstimateTransactionStateSpace(void)
Definition: xact.c:5374
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition: xact.c:864
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:855
#define IsolationUsesXactSnapshot()
Definition: xact.h:51

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(), GetTempNamespaceState(), GetTransactionSnapshot(), GetUserIdAndSecContext(), i, FixedParallelState::is_superuser, IsolationUsesXactSnapshot, FixedParallelState::last_xlog_end, ParallelContext::library_name, MemoryContextAlloc(), MemoryContextSwitchTo(), mul_size(), FixedParallelState::mutex, MyBackendId, MyDatabaseId, MyProc, MyProcPid, ParallelContext::nworkers, FixedParallelState::outer_user_id, palloc0(), 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_backend_id, FixedParallelState::parallel_leader_pgproc, FixedParallelState::parallel_leader_pid, PARALLEL_MAGIC, ParallelContext::private_memory, FixedParallelState::sec_context, ParallelContext::seg, FixedParallelState::serializable_xact_handle, SerializeClientConnectionInfo(), SerializeComboCIDState(), SerializeGUCState(), SerializeLibraryState(), SerializePendingSyncs(), SerializeReindexState(), SerializeRelationMap(), SerializeSnapshot(), SerializeTransactionState(), SerializeUncommittedEnums(), 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, StaticAssertStmt, 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(), ExecInitParallelPlan(), and parallel_vacuum_init().

◆ LaunchParallelWorkers()

void LaunchParallelWorkers ( ParallelContext pcxt)

Definition at line 555 of file parallel.c.

556 {
557  MemoryContext oldcontext;
558  BackgroundWorker worker;
559  int i;
560  bool any_registrations_failed = false;
561 
562  /* Skip this if we have no workers. */
563  if (pcxt->nworkers == 0 || pcxt->nworkers_to_launch == 0)
564  return;
565 
566  /* We need to be a lock group leader. */
568 
569  /* If we do have workers, we'd better have a DSM segment. */
570  Assert(pcxt->seg != NULL);
571 
572  /* We might be running in a short-lived memory context. */
574 
575  /* Configure a worker. */
576  memset(&worker, 0, sizeof(worker));
577  snprintf(worker.bgw_name, BGW_MAXLEN, "parallel worker for PID %d",
578  MyProcPid);
579  snprintf(worker.bgw_type, BGW_MAXLEN, "parallel worker");
580  worker.bgw_flags =
585  sprintf(worker.bgw_library_name, "postgres");
586  sprintf(worker.bgw_function_name, "ParallelWorkerMain");
588  worker.bgw_notify_pid = MyProcPid;
589 
590  /*
591  * Start workers.
592  *
593  * The caller must be able to tolerate ending up with fewer workers than
594  * expected, so there is no need to throw an error here if registration
595  * fails. It wouldn't help much anyway, because registering the worker in
596  * no way guarantees that it will start up and initialize successfully.
597  */
598  for (i = 0; i < pcxt->nworkers_to_launch; ++i)
599  {
600  memcpy(worker.bgw_extra, &i, sizeof(int));
601  if (!any_registrations_failed &&
603  &pcxt->worker[i].bgwhandle))
604  {
606  pcxt->worker[i].bgwhandle);
607  pcxt->nworkers_launched++;
608  }
609  else
610  {
611  /*
612  * If we weren't able to register the worker, then we've bumped up
613  * against the max_worker_processes limit, and future
614  * registrations will probably fail too, so arrange to skip them.
615  * But we still have to execute this code for the remaining slots
616  * to make sure that we forget about the error queues we budgeted
617  * for those workers. Otherwise, we'll wait for them to start,
618  * but they never will.
619  */
620  any_registrations_failed = true;
621  pcxt->worker[i].bgwhandle = NULL;
623  pcxt->worker[i].error_mqh = NULL;
624  }
625  }
626 
627  /*
628  * Now that nworkers_launched has taken its final value, we can initialize
629  * known_attached_workers.
630  */
631  if (pcxt->nworkers_launched > 0)
632  {
633  pcxt->known_attached_workers =
634  palloc0(sizeof(bool) * pcxt->nworkers_launched);
635  pcxt->nknown_attached_workers = 0;
636  }
637 
638  /* Restore previous memory context. */
639  MemoryContextSwitchTo(oldcontext);
640 }
bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker, BackgroundWorkerHandle **handle)
Definition: bgworker.c:960
#define BGW_NEVER_RESTART
Definition: bgworker.h:85
#define BGWORKER_CLASS_PARALLEL
Definition: bgworker.h:68
@ BgWorkerStart_ConsistentState
Definition: bgworker.h:80
#define BGWORKER_BACKEND_DATABASE_CONNECTION
Definition: bgworker.h:60
#define BGWORKER_SHMEM_ACCESS
Definition: bgworker.h:53
#define BGW_MAXLEN
Definition: bgworker.h:86
dsm_handle dsm_segment_handle(dsm_segment *seg)
Definition: dsm.c:1124
#define sprintf
Definition: port.h:240
#define snprintf
Definition: port.h:238
static Datum UInt32GetDatum(uint32 X)
Definition: postgres.h:232
void shm_mq_set_handle(shm_mq_handle *mqh, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:320
void BecomeLockGroupLeader(void)
Definition: proc.c:1860
char bgw_function_name[BGW_MAXLEN]
Definition: bgworker.h:97
Datum bgw_main_arg
Definition: bgworker.h:98
char bgw_name[BGW_MAXLEN]
Definition: bgworker.h:91
int bgw_restart_time
Definition: bgworker.h:95
char bgw_type[BGW_MAXLEN]
Definition: bgworker.h:92
BgWorkerStartTime bgw_start_time
Definition: bgworker.h:94
char bgw_extra[BGW_EXTRALEN]
Definition: bgworker.h:99
pid_t bgw_notify_pid
Definition: bgworker.h:100
char bgw_library_name[MAXPGPATH]
Definition: bgworker.h:96
bool * known_attached_workers
Definition: parallel.h:48
int nknown_attached_workers
Definition: parallel.h:47

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(), 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(), ExecGather(), ExecGatherMerge(), and parallel_vacuum_process_all_indexes().

◆ ParallelContextActive()

bool ParallelContextActive ( void  )

Definition at line 1006 of file parallel.c.

1007 {
1008  return !dlist_is_empty(&pcxt_list);
1009 }

References dlist_is_empty(), and pcxt_list.

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

◆ ParallelWorkerMain()

void ParallelWorkerMain ( Datum  main_arg)

Definition at line 1284 of file parallel.c.

1285 {
1286  dsm_segment *seg;
1287  shm_toc *toc;
1288  FixedParallelState *fps;
1289  char *error_queue_space;
1290  shm_mq *mq;
1291  shm_mq_handle *mqh;
1292  char *libraryspace;
1293  char *entrypointstate;
1294  char *library_name;
1295  char *function_name;
1296  parallel_worker_main_type entrypt;
1297  char *gucspace;
1298  char *combocidspace;
1299  char *tsnapspace;
1300  char *asnapspace;
1301  char *tstatespace;
1302  char *pendingsyncsspace;
1303  char *reindexspace;
1304  char *relmapperspace;
1305  char *uncommittedenumsspace;
1306  char *clientconninfospace;
1307  StringInfoData msgbuf;
1308  char *session_dsm_handle_space;
1309  Snapshot tsnapshot;
1310  Snapshot asnapshot;
1311 
1312  /* Set flag to indicate that we're initializing a parallel worker. */
1314 
1315  /* Establish signal handlers. */
1316  pqsignal(SIGTERM, die);
1318 
1319  /* Determine and set our parallel worker number. */
1321  memcpy(&ParallelWorkerNumber, MyBgworkerEntry->bgw_extra, sizeof(int));
1322 
1323  /* Set up a memory context to work in, just for cleanliness. */
1325  "Parallel worker",
1327 
1328  /*
1329  * Attach to the dynamic shared memory segment for the parallel query, and
1330  * find its table of contents.
1331  *
1332  * Note: at this point, we have not created any ResourceOwner in this
1333  * process. This will result in our DSM mapping surviving until process
1334  * exit, which is fine. If there were a ResourceOwner, it would acquire
1335  * ownership of the mapping, but we have no need for that.
1336  */
1337  seg = dsm_attach(DatumGetUInt32(main_arg));
1338  if (seg == NULL)
1339  ereport(ERROR,
1340  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1341  errmsg("could not map dynamic shared memory segment")));
1343  if (toc == NULL)
1344  ereport(ERROR,
1345  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1346  errmsg("invalid magic number in dynamic shared memory segment")));
1347 
1348  /* Look up fixed parallel state. */
1349  fps = shm_toc_lookup(toc, PARALLEL_KEY_FIXED, false);
1350  MyFixedParallelState = fps;
1351 
1352  /* Arrange to signal the leader if we exit. */
1356 
1357  /*
1358  * Now we can find and attach to the error queue provided for us. That's
1359  * good, because until we do that, any errors that happen here will not be
1360  * reported back to the process that requested that this worker be
1361  * launched.
1362  */
1363  error_queue_space = shm_toc_lookup(toc, PARALLEL_KEY_ERROR_QUEUE, false);
1364  mq = (shm_mq *) (error_queue_space +
1367  mqh = shm_mq_attach(mq, seg, NULL);
1368  pq_redirect_to_shm_mq(seg, mqh);
1371 
1372  /*
1373  * Send a BackendKeyData message to the process that initiated parallelism
1374  * so that it has access to our PID before it receives any other messages
1375  * from us. Our cancel key is sent, too, since that's the way the
1376  * protocol message is defined, but it won't actually be used for anything
1377  * in this case.
1378  */
1380  pq_sendint32(&msgbuf, (int32) MyProcPid);
1381  pq_sendint32(&msgbuf, (int32) MyCancelKey);
1382  pq_endmessage(&msgbuf);
1383 
1384  /*
1385  * Hooray! Primary initialization is complete. Now, we need to set up our
1386  * backend-local state to match the original backend.
1387  */
1388 
1389  /*
1390  * Join locking group. We must do this before anything that could try to
1391  * acquire a heavyweight lock, because any heavyweight locks acquired to
1392  * this point could block either directly against the parallel group
1393  * leader or against some process which in turn waits for a lock that
1394  * conflicts with the parallel group leader, causing an undetected
1395  * deadlock. (If we can't join the lock group, the leader has gone away,
1396  * so just exit quietly.)
1397  */
1399  fps->parallel_leader_pid))
1400  return;
1401 
1402  /*
1403  * Restore transaction and statement start-time timestamps. This must
1404  * happen before anything that would start a transaction, else asserts in
1405  * xact.c will fire.
1406  */
1408 
1409  /*
1410  * Identify the entry point to be called. In theory this could result in
1411  * loading an additional library, though most likely the entry point is in
1412  * the core backend or in a library we just loaded.
1413  */
1414  entrypointstate = shm_toc_lookup(toc, PARALLEL_KEY_ENTRYPOINT, false);
1415  library_name = entrypointstate;
1416  function_name = entrypointstate + strlen(library_name) + 1;
1417 
1418  entrypt = LookupParallelWorkerFunction(library_name, function_name);
1419 
1420  /* Restore database connection. */
1422  fps->authenticated_user_id,
1423  0);
1424 
1425  /*
1426  * Set the client encoding to the database encoding, since that is what
1427  * the leader will expect.
1428  */
1430 
1431  /*
1432  * Load libraries that were loaded by original backend. We want to do
1433  * this before restoring GUCs, because the libraries might define custom
1434  * variables.
1435  */
1436  libraryspace = shm_toc_lookup(toc, PARALLEL_KEY_LIBRARY, false);
1438  RestoreLibraryState(libraryspace);
1439 
1440  /* Restore GUC values from launching backend. */
1441  gucspace = shm_toc_lookup(toc, PARALLEL_KEY_GUC, false);
1442  RestoreGUCState(gucspace);
1444 
1445  /* Crank up a transaction state appropriate to a parallel worker. */
1446  tstatespace = shm_toc_lookup(toc, PARALLEL_KEY_TRANSACTION_STATE, false);
1447  StartParallelWorkerTransaction(tstatespace);
1448 
1449  /* Restore combo CID state. */
1450  combocidspace = shm_toc_lookup(toc, PARALLEL_KEY_COMBO_CID, false);
1451  RestoreComboCIDState(combocidspace);
1452 
1453  /* Attach to the per-session DSM segment and contained objects. */
1454  session_dsm_handle_space =
1456  AttachSession(*(dsm_handle *) session_dsm_handle_space);
1457 
1458  /*
1459  * If the transaction isolation level is REPEATABLE READ or SERIALIZABLE,
1460  * the leader has serialized the transaction snapshot and we must restore
1461  * it. At lower isolation levels, there is no transaction-lifetime
1462  * snapshot, but we need TransactionXmin to get set to a value which is
1463  * less than or equal to the xmin of every snapshot that will be used by
1464  * this worker. The easiest way to accomplish that is to install the
1465  * active snapshot as the transaction snapshot. Code running in this
1466  * parallel worker might take new snapshots via GetTransactionSnapshot()
1467  * or GetLatestSnapshot(), but it shouldn't have any way of acquiring a
1468  * snapshot older than the active snapshot.
1469  */
1470  asnapspace = shm_toc_lookup(toc, PARALLEL_KEY_ACTIVE_SNAPSHOT, false);
1471  tsnapspace = shm_toc_lookup(toc, PARALLEL_KEY_TRANSACTION_SNAPSHOT, true);
1472  asnapshot = RestoreSnapshot(asnapspace);
1473  tsnapshot = tsnapspace ? RestoreSnapshot(tsnapspace) : asnapshot;
1474  RestoreTransactionSnapshot(tsnapshot,
1475  fps->parallel_leader_pgproc);
1476  PushActiveSnapshot(asnapshot);
1477 
1478  /*
1479  * We've changed which tuples we can see, and must therefore invalidate
1480  * system caches.
1481  */
1483 
1484  /*
1485  * Restore current role id. Skip verifying whether session user is
1486  * allowed to become this role and blindly restore the leader's state for
1487  * current role.
1488  */
1490 
1491  /* Restore user ID and security context. */
1493 
1494  /* Restore temp-namespace state to ensure search path matches leader's. */
1497 
1498  /* Restore pending syncs. */
1499  pendingsyncsspace = shm_toc_lookup(toc, PARALLEL_KEY_PENDING_SYNCS,
1500  false);
1501  RestorePendingSyncs(pendingsyncsspace);
1502 
1503  /* Restore reindex state. */
1504  reindexspace = shm_toc_lookup(toc, PARALLEL_KEY_REINDEX_STATE, false);
1505  RestoreReindexState(reindexspace);
1506 
1507  /* Restore relmapper state. */
1508  relmapperspace = shm_toc_lookup(toc, PARALLEL_KEY_RELMAPPER_STATE, false);
1509  RestoreRelationMap(relmapperspace);
1510 
1511  /* Restore uncommitted enums. */
1512  uncommittedenumsspace = shm_toc_lookup(toc, PARALLEL_KEY_UNCOMMITTEDENUMS,
1513  false);
1514  RestoreUncommittedEnums(uncommittedenumsspace);
1515 
1516  /* Restore the ClientConnectionInfo. */
1517  clientconninfospace = shm_toc_lookup(toc, PARALLEL_KEY_CLIENTCONNINFO,
1518  false);
1519  RestoreClientConnectionInfo(clientconninfospace);
1520 
1521  /*
1522  * Initialize SystemUser now that MyClientConnectionInfo is restored. Also
1523  * ensure that auth_method is actually valid, aka authn_id is not NULL.
1524  */
1528 
1529  /* Attach to the leader's serializable transaction, if SERIALIZABLE. */
1531 
1532  /*
1533  * We've initialized all of our state now; nothing should change
1534  * hereafter.
1535  */
1538 
1539  /*
1540  * Time to do the real work: invoke the caller-supplied code.
1541  */
1542  entrypt(seg, toc);
1543 
1544  /* Must exit parallel mode to pop active snapshot. */
1545  ExitParallelMode();
1546 
1547  /* Must pop active snapshot so snapmgr.c doesn't complain. */
1549 
1550  /* Shut down the parallel-worker transaction. */
1552 
1553  /* Detach from the per-session DSM segment. */
1554  DetachSession();
1555 
1556  /* Report success. */
1557  pq_putmessage(PqMsg_Terminate, NULL, 0);
1558 }
static parallel_worker_main_type LookupParallelWorkerFunction(const char *libraryname, const char *funcname)
Definition: parallel.c:1621
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:1593
signed int int32
Definition: c.h:483
void RestoreComboCIDState(char *comboCIDstate)
Definition: combocid.c:342
void RestoreLibraryState(char *start_address)
Definition: dfmgr.c:676
dsm_segment * dsm_attach(dsm_handle h)
Definition: dsm.c:666
int32 MyCancelKey
Definition: globals.c:49
BackendId ParallelLeaderBackendId
Definition: globals.c:88
void RestoreGUCState(void *gucstate)
Definition: guc.c:6118
const char * hba_authname(UserAuth auth_method)
Definition: hba.c:3066
void(* parallel_worker_main_type)(dsm_segment *seg, shm_toc *toc)
Definition: parallel.h:23
void RestoreReindexState(const void *reindexstate)
Definition: index.c:4228
void InvalidateSystemCaches(void)
Definition: inval.c:793
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:1268
int SetClientEncoding(int encoding)
Definition: mbutils.c:209
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
void InitializeSystemUser(const char *authn_id, const char *auth_method)
Definition: miscinit.c:863
void SetCurrentRoleId(Oid roleid, bool is_superuser)
Definition: miscinit.c:941
ClientConnectionInfo MyClientConnectionInfo
Definition: miscinit.c:1006
void RestoreClientConnectionInfo(char *conninfo)
Definition: miscinit.c:1071
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:639
void SetTempNamespaceState(Oid tempNamespaceId, Oid tempToastNamespaceId)
Definition: namespace.c:3806
void RestoreUncommittedEnums(void *space)
Definition: pg_enum.c:770
#define die(msg)
pqsigfunc pqsignal(int signo, pqsigfunc func)
static uint32 DatumGetUInt32(Datum X)
Definition: postgres.h:222
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
void BackgroundWorkerUnblockSignals(void)
Definition: postmaster.c:5633
void BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, uint32 flags)
Definition: postmaster.c:5593
BackgroundWorker * MyBgworkerEntry
Definition: postmaster.c:193
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:299
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:88
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
void pq_set_parallel_leader(pid_t pid, BackendId backend_id)
Definition: pqmq.c:78
void pq_redirect_to_shm_mq(dsm_segment *seg, shm_mq_handle *mqh)
Definition: pqmq.c:53
void AttachSerializableXact(SerializableXactHandle handle)
Definition: predicate.c:5025
#define PqMsg_BackendKeyData
Definition: protocol.h:48
#define PqMsg_Terminate
Definition: protocol.h:28
void RestoreRelationMap(char *startAddress)
Definition: relmapper.c:742
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:225
shm_toc * shm_toc_attach(uint64 magic, void *address)
Definition: shm_toc.c:64
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:655
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:1781
void RestoreTransactionSnapshot(Snapshot snapshot, void *source_pgproc)
Definition: snapmgr.c:1846
void PopActiveSnapshot(void)
Definition: snapmgr.c:750
bool BecomeLockGroupMember(PGPROC *leader, int pid)
Definition: proc.c:1890
void RestorePendingSyncs(char *startAddress)
Definition: storage.c:628
const char * authn_id
Definition: libpq-be.h:114
UserAuth auth_method
Definition: libpq-be.h:120
void ExitParallelMode(void)
Definition: xact.c:1049
void EnterParallelMode(void)
Definition: xact.c:1036
void StartTransactionCommand(void)
Definition: xact.c:2953
void StartParallelWorkerTransaction(char *tstatespace)
Definition: xact.c:5473
void SetParallelStartTimestamps(TimestampTz xact_ts, TimestampTz stmt_ts)
Definition: xact.c:844
void EndParallelWorkerTransaction(void)
Definition: xact.c:5498
void CommitTransactionCommand(void)
Definition: xact.c:3050

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, CommitTransactionCommand(), FixedParallelState::current_user_id, CurrentMemoryContext, FixedParallelState::database_id, DatumGetUInt32(), DetachSession(), die, dsm_attach(), dsm_segment_address(), EndParallelWorkerTransaction(), EnterParallelMode(), ereport, errcode(), errmsg(), ERROR, ExitParallelMode(), GetDatabaseEncoding(), hba_authname(), InitializeSystemUser(), InitializingParallelWorker, InvalidateSystemCaches(), FixedParallelState::is_superuser, LookupParallelWorkerFunction(), MyBgworkerEntry, MyCancelKey, MyClientConnectionInfo, MyFixedParallelState, MyProc, MyProcPid, 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_backend_id, FixedParallelState::parallel_leader_pgproc, FixedParallelState::parallel_leader_pid, PARALLEL_MAGIC, ParallelLeaderBackendId, ParallelLeaderPid, ParallelWorkerNumber, ParallelWorkerShutdown(), PointerGetDatum(), PopActiveSnapshot(), pq_beginmessage(), pq_endmessage(), pq_putmessage, pq_redirect_to_shm_mq(), pq_sendint32(), pq_set_parallel_leader(), PqMsg_BackendKeyData, PqMsg_Terminate, pqsignal(), PushActiveSnapshot(), RestoreClientConnectionInfo(), RestoreComboCIDState(), RestoreGUCState(), RestoreLibraryState(), RestorePendingSyncs(), RestoreReindexState(), RestoreRelationMap(), RestoreSnapshot(), RestoreTransactionSnapshot(), RestoreUncommittedEnums(), FixedParallelState::sec_context, FixedParallelState::serializable_xact_handle, SetClientEncoding(), SetCurrentRoleId(), SetParallelStartTimestamps(), 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 1565 of file parallel.c.

1566 {
1568 
1569  Assert(fps != NULL);
1570  SpinLockAcquire(&fps->mutex);
1571  if (fps->last_xlog_end < last_xlog_end)
1572  fps->last_xlog_end = last_xlog_end;
1573  SpinLockRelease(&fps->mutex);
1574 }
#define SpinLockRelease(lock)
Definition: spin.h:64
#define SpinLockAcquire(lock)
Definition: spin.h:62

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

Referenced by CommitTransaction().

◆ ReinitializeParallelDSM()

void ReinitializeParallelDSM ( ParallelContext pcxt)

Definition at line 491 of file parallel.c.

492 {
493  FixedParallelState *fps;
494 
495  /* Wait for any old workers to exit. */
496  if (pcxt->nworkers_launched > 0)
497  {
500  pcxt->nworkers_launched = 0;
501  if (pcxt->known_attached_workers)
502  {
504  pcxt->known_attached_workers = NULL;
505  pcxt->nknown_attached_workers = 0;
506  }
507  }
508 
509  /* Reset a few bits of fixed parallel state to a clean state. */
510  fps = shm_toc_lookup(pcxt->toc, PARALLEL_KEY_FIXED, false);
511  fps->last_xlog_end = 0;
512 
513  /* Recreate error queues (if they exist). */
514  if (pcxt->nworkers > 0)
515  {
516  char *error_queue_space;
517  int i;
518 
519  error_queue_space =
521  for (i = 0; i < pcxt->nworkers; ++i)
522  {
523  char *start;
524  shm_mq *mq;
525 
526  start = error_queue_space + i * PARALLEL_ERROR_QUEUE_SIZE;
529  pcxt->worker[i].error_mqh = shm_mq_attach(mq, pcxt->seg, NULL);
530  }
531  }
532 }
void WaitForParallelWorkersToFinish(ParallelContext *pcxt)
Definition: parallel.c:778

References ParallelWorkerInfo::error_mqh, i, ParallelContext::known_attached_workers, FixedParallelState::last_xlog_end, 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(), ParallelContext::toc, 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 541 of file parallel.c.

542 {
543  /*
544  * The number of workers that need to be launched must be less than the
545  * number of workers with which the parallel context is initialized.
546  */
547  Assert(pcxt->nworkers >= nworkers_to_launch);
548  pcxt->nworkers_to_launch = nworkers_to_launch;
549 }

References Assert(), ParallelContext::nworkers, and ParallelContext::nworkers_to_launch.

Referenced by parallel_vacuum_process_all_indexes().

◆ WaitForParallelWorkersToAttach()

void WaitForParallelWorkersToAttach ( ParallelContext pcxt)

Definition at line 675 of file parallel.c.

676 {
677  int i;
678 
679  /* Skip this if we have no launched workers. */
680  if (pcxt->nworkers_launched == 0)
681  return;
682 
683  for (;;)
684  {
685  /*
686  * This will process any parallel messages that are pending and it may
687  * also throw an error propagated from a worker.
688  */
690 
691  for (i = 0; i < pcxt->nworkers_launched; ++i)
692  {
693  BgwHandleStatus status;
694  shm_mq *mq;
695  int rc;
696  pid_t pid;
697 
698  if (pcxt->known_attached_workers[i])
699  continue;
700 
701  /*
702  * If error_mqh is NULL, then the worker has already exited
703  * cleanly.
704  */
705  if (pcxt->worker[i].error_mqh == NULL)
706  {
707  pcxt->known_attached_workers[i] = true;
708  ++pcxt->nknown_attached_workers;
709  continue;
710  }
711 
712  status = GetBackgroundWorkerPid(pcxt->worker[i].bgwhandle, &pid);
713  if (status == BGWH_STARTED)
714  {
715  /* Has the worker attached to the error queue? */
716  mq = shm_mq_get_queue(pcxt->worker[i].error_mqh);
717  if (shm_mq_get_sender(mq) != NULL)
718  {
719  /* Yes, so it is known to be attached. */
720  pcxt->known_attached_workers[i] = true;
721  ++pcxt->nknown_attached_workers;
722  }
723  }
724  else if (status == BGWH_STOPPED)
725  {
726  /*
727  * If the worker stopped without attaching to the error queue,
728  * throw an error.
729  */
730  mq = shm_mq_get_queue(pcxt->worker[i].error_mqh);
731  if (shm_mq_get_sender(mq) == NULL)
732  ereport(ERROR,
733  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
734  errmsg("parallel worker failed to initialize"),
735  errhint("More details may be available in the server log.")));
736 
737  pcxt->known_attached_workers[i] = true;
738  ++pcxt->nknown_attached_workers;
739  }
740  else
741  {
742  /*
743  * Worker not yet started, so we must wait. The postmaster
744  * will notify us if the worker's state changes. Our latch
745  * might also get set for some other reason, but if so we'll
746  * just end up waiting for the same worker again.
747  */
748  rc = WaitLatch(MyLatch,
750  -1, WAIT_EVENT_BGWORKER_STARTUP);
751 
752  if (rc & WL_LATCH_SET)
754  }
755  }
756 
757  /* If all workers are known to have started, we're done. */
758  if (pcxt->nknown_attached_workers >= pcxt->nworkers_launched)
759  {
761  break;
762  }
763  }
764 }
BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle, pid_t *pidp)
Definition: bgworker.c:1072
BgwHandleStatus
Definition: bgworker.h:104
@ BGWH_STARTED
Definition: bgworker.h:105
@ BGWH_STOPPED
Definition: bgworker.h:107
int errhint(const char *fmt,...)
Definition: elog.c:1322
void ResetLatch(Latch *latch)
Definition: latch.c:725
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:518
#define WL_EXIT_ON_PM_DEATH
Definition: latch.h:132
#define WL_LATCH_SET
Definition: latch.h:127
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
shm_mq * shm_mq_get_queue(shm_mq_handle *mqh)
Definition: shm_mq.c:906
PGPROC * shm_mq_get_sender(shm_mq *mq)
Definition: shm_mq.c:258

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(), and _bt_begin_parallel().

◆ WaitForParallelWorkersToFinish()

void WaitForParallelWorkersToFinish ( ParallelContext pcxt)

Definition at line 778 of file parallel.c.

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

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(), ExecParallelFinish(), parallel_vacuum_process_all_indexes(), and ReinitializeParallelDSM().

Variable Documentation

◆ InitializingParallelWorker

PGDLLIMPORT bool InitializingParallelWorker
extern

◆ ParallelMessagePending

PGDLLIMPORT volatile sig_atomic_t ParallelMessagePending
extern

◆ ParallelWorkerNumber