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, bool serializable_okay)
 
void InitializeParallelDSM (ParallelContext *pcxt)
 
void ReinitializeParallelDSM (ParallelContext *pcxt)
 
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

volatile bool ParallelMessagePending
 
PGDLLIMPORT int ParallelWorkerNumber
 
PGDLLIMPORT bool InitializingParallelWorker
 

Macro Definition Documentation

◆ IsParallelWorker

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

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

Referenced by AbortSubTransaction(), and CommitSubTransaction().

1162 {
1163  while (!dlist_is_empty(&pcxt_list))
1164  {
1165  ParallelContext *pcxt;
1166 
1168  if (pcxt->subid != mySubId)
1169  break;
1170  if (isCommit)
1171  elog(WARNING, "leaked parallel context");
1172  DestroyParallelContext(pcxt);
1173  }
1174 }
SubTransactionId subid
Definition: parallel.h:35
void DestroyParallelContext(ParallelContext *pcxt)
Definition: parallel.c:862
#define WARNING
Definition: elog.h:40
#define dlist_head_element(type, membername, lhead)
Definition: ilist.h:487
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289
static dlist_head pcxt_list
Definition: parallel.c:115
#define elog
Definition: elog.h:219

◆ AtEOXact_Parallel()

void AtEOXact_Parallel ( bool  isCommit)

Definition at line 1180 of file parallel.c.

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

Referenced by AbortTransaction(), and CommitTransaction().

1181 {
1182  while (!dlist_is_empty(&pcxt_list))
1183  {
1184  ParallelContext *pcxt;
1185 
1187  if (isCommit)
1188  elog(WARNING, "leaked parallel context");
1189  DestroyParallelContext(pcxt);
1190  }
1191 }
void DestroyParallelContext(ParallelContext *pcxt)
Definition: parallel.c:862
#define WARNING
Definition: elog.h:40
#define dlist_head_element(type, membername, lhead)
Definition: ilist.h:487
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289
static dlist_head pcxt_list
Definition: parallel.c:115
#define elog
Definition: elog.h:219

◆ CreateParallelContext()

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

Definition at line 152 of file parallel.c.

References Assert, dlist_push_head(), DSM_IMPL_NONE, dynamic_shared_memory_type, ParallelContext::error_context_stack, error_context_stack, ParallelContext::estimator, ParallelContext::function_name, GetCurrentSubTransactionId(), IsInParallelMode(), IsolationIsSerializable, ParallelContext::library_name, MemoryContextSwitchTo(), ParallelContext::node, ParallelContext::nworkers, palloc0(), pstrdup(), shm_toc_initialize_estimator, ParallelContext::subid, and TopTransactionContext.

Referenced by _bt_begin_parallel(), and ExecInitParallelPlan().

154 {
155  MemoryContext oldcontext;
156  ParallelContext *pcxt;
157 
158  /* It is unsafe to create a parallel context if not in parallel mode. */
160 
161  /* Number of workers should be non-negative. */
162  Assert(nworkers >= 0);
163 
164  /*
165  * If dynamic shared memory is not available, we won't be able to use
166  * background workers.
167  */
169  nworkers = 0;
170 
171  /*
172  * If we are running under serializable isolation, we can't use parallel
173  * workers, at least not until somebody enhances that mechanism to be
174  * parallel-aware. Utility statement callers may ask us to ignore this
175  * restriction because they're always able to safely ignore the fact that
176  * SIREAD locks do not work with parallelism.
177  */
178  if (IsolationIsSerializable() && !serializable_okay)
179  nworkers = 0;
180 
181  /* We might be running in a short-lived memory context. */
183 
184  /* Initialize a new ParallelContext. */
185  pcxt = palloc0(sizeof(ParallelContext));
187  pcxt->nworkers = nworkers;
188  pcxt->library_name = pstrdup(library_name);
189  pcxt->function_name = pstrdup(function_name);
192  dlist_push_head(&pcxt_list, &pcxt->node);
193 
194  /* Restore previous memory context. */
195  MemoryContextSwitchTo(oldcontext);
196 
197  return pcxt;
198 }
MemoryContext TopTransactionContext
Definition: mcxt.c:49
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition: ilist.h:300
char * pstrdup(const char *in)
Definition: mcxt.c:1161
shm_toc_estimator estimator
Definition: parallel.h:41
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
SubTransactionId subid
Definition: parallel.h:35
ErrorContextCallback * error_context_stack
Definition: elog.c:88
bool IsInParallelMode(void)
Definition: xact.c:905
char * function_name
Definition: parallel.h:39
int dynamic_shared_memory_type
Definition: dsm_impl.c:114
#define shm_toc_initialize_estimator(e)
Definition: shm_toc.h:49
void * palloc0(Size size)
Definition: mcxt.c:955
char * library_name
Definition: parallel.h:38
#define Assert(condition)
Definition: c.h:699
SubTransactionId GetCurrentSubTransactionId(void)
Definition: xact.c:641
#define DSM_IMPL_NONE
Definition: dsm_impl.h:17
dlist_node node
Definition: parallel.h:34
ErrorContextCallback * error_context_stack
Definition: parallel.h:40
#define IsolationIsSerializable()
Definition: xact.h:51
static dlist_head pcxt_list
Definition: parallel.c:115

◆ DestroyParallelContext()

void DestroyParallelContext ( ParallelContext pcxt)

Definition at line 862 of file parallel.c.

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 _bt_end_parallel(), AtEOSubXact_Parallel(), AtEOXact_Parallel(), and ExecParallelCleanup().

863 {
864  int i;
865 
866  /*
867  * Be careful about order of operations here! We remove the parallel
868  * context from the list before we do anything else; otherwise, if an
869  * error occurs during a subsequent step, we might try to nuke it again
870  * from AtEOXact_Parallel or AtEOSubXact_Parallel.
871  */
872  dlist_delete(&pcxt->node);
873 
874  /* Kill each worker in turn, and forget their error queues. */
875  if (pcxt->worker != NULL)
876  {
877  for (i = 0; i < pcxt->nworkers_launched; ++i)
878  {
879  if (pcxt->worker[i].error_mqh != NULL)
880  {
882 
883  shm_mq_detach(pcxt->worker[i].error_mqh);
884  pcxt->worker[i].error_mqh = NULL;
885  }
886  }
887  }
888 
889  /*
890  * If we have allocated a shared memory segment, detach it. This will
891  * implicitly detach the error queues, and any other shared memory queues,
892  * stored there.
893  */
894  if (pcxt->seg != NULL)
895  {
896  dsm_detach(pcxt->seg);
897  pcxt->seg = NULL;
898  }
899 
900  /*
901  * If this parallel context is actually in backend-private memory rather
902  * than shared memory, free that memory instead.
903  */
904  if (pcxt->private_memory != NULL)
905  {
906  pfree(pcxt->private_memory);
907  pcxt->private_memory = NULL;
908  }
909 
910  /*
911  * We can't finish transaction commit or abort until all of the workers
912  * have exited. This means, in particular, that we can't respond to
913  * interrupts at this stage.
914  */
915  HOLD_INTERRUPTS();
918 
919  /* Free the worker array itself. */
920  if (pcxt->worker != NULL)
921  {
922  pfree(pcxt->worker);
923  pcxt->worker = NULL;
924  }
925 
926  /* Free memory. */
927  pfree(pcxt->library_name);
928  pfree(pcxt->function_name);
929  pfree(pcxt);
930 }
void shm_mq_detach(shm_mq_handle *mqh)
Definition: shm_mq.c:793
dsm_segment * seg
Definition: parallel.h:42
static void WaitForParallelWorkersToExit(ParallelContext *pcxt)
Definition: parallel.c:822
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:117
ParallelWorkerInfo * worker
Definition: parallel.h:45
void pfree(void *pointer)
Definition: mcxt.c:1031
char * function_name
Definition: parallel.h:39
shm_mq_handle * error_mqh
Definition: parallel.h:28
BackgroundWorkerHandle * bgwhandle
Definition: parallel.h:27
static void dlist_delete(dlist_node *node)
Definition: ilist.h:358
int nworkers_launched
Definition: parallel.h:37
void TerminateBackgroundWorker(BackgroundWorkerHandle *handle)
Definition: bgworker.c:1184
char * library_name
Definition: parallel.h:38
dlist_node node
Definition: parallel.h:34
void dsm_detach(dsm_segment *seg)
Definition: dsm.c:713
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:115
int i
void * private_memory
Definition: parallel.h:43

◆ HandleParallelMessageInterrupt()

void HandleParallelMessageInterrupt ( void  )

Definition at line 949 of file parallel.c.

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

Referenced by procsignal_sigusr1_handler().

950 {
951  InterruptPending = true;
952  ParallelMessagePending = true;
953  SetLatch(MyLatch);
954 }
volatile bool ParallelMessagePending
Definition: parallel.c:106
volatile bool InterruptPending
Definition: globals.c:32
void SetLatch(volatile Latch *latch)
Definition: latch.c:414
struct Latch * MyLatch
Definition: globals.c:55

◆ HandleParallelMessages()

void HandleParallelMessages ( void  )

Definition at line 960 of file parallel.c.

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

Referenced by ProcessInterrupts().

961 {
962  dlist_iter iter;
963  MemoryContext oldcontext;
964 
965  static MemoryContext hpm_context = NULL;
966 
967  /*
968  * This is invoked from ProcessInterrupts(), and since some of the
969  * functions it calls contain CHECK_FOR_INTERRUPTS(), there is a potential
970  * for recursive calls if more signals are received while this runs. It's
971  * unclear that recursive entry would be safe, and it doesn't seem useful
972  * even if it is safe, so let's block interrupts until done.
973  */
974  HOLD_INTERRUPTS();
975 
976  /*
977  * Moreover, CurrentMemoryContext might be pointing almost anywhere. We
978  * don't want to risk leaking data into long-lived contexts, so let's do
979  * our work here in a private context that we can reset on each use.
980  */
981  if (hpm_context == NULL) /* first time through? */
983  "HandleParallelMessages",
985  else
986  MemoryContextReset(hpm_context);
987 
988  oldcontext = MemoryContextSwitchTo(hpm_context);
989 
990  /* OK to process messages. Reset the flag saying there are more to do. */
991  ParallelMessagePending = false;
992 
993  dlist_foreach(iter, &pcxt_list)
994  {
995  ParallelContext *pcxt;
996  int i;
997 
998  pcxt = dlist_container(ParallelContext, node, iter.cur);
999  if (pcxt->worker == NULL)
1000  continue;
1001 
1002  for (i = 0; i < pcxt->nworkers_launched; ++i)
1003  {
1004  /*
1005  * Read as many messages as we can from each worker, but stop when
1006  * either (1) the worker's error queue goes away, which can happen
1007  * if we receive a Terminate message from the worker; or (2) no
1008  * more messages can be read from the worker without blocking.
1009  */
1010  while (pcxt->worker[i].error_mqh != NULL)
1011  {
1012  shm_mq_result res;
1013  Size nbytes;
1014  void *data;
1015 
1016  res = shm_mq_receive(pcxt->worker[i].error_mqh, &nbytes,
1017  &data, true);
1018  if (res == SHM_MQ_WOULD_BLOCK)
1019  break;
1020  else if (res == SHM_MQ_SUCCESS)
1021  {
1022  StringInfoData msg;
1023 
1024  initStringInfo(&msg);
1025  appendBinaryStringInfo(&msg, data, nbytes);
1026  HandleParallelMessage(pcxt, i, &msg);
1027  pfree(msg.data);
1028  }
1029  else
1030  ereport(ERROR,
1031  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1032  errmsg("lost connection to parallel worker")));
1033  }
1034  }
1035  }
1036 
1037  MemoryContextSwitchTo(oldcontext);
1038 
1039  /* Might as well clear the context on our way out */
1040  MemoryContextReset(hpm_context);
1041 
1043 }
#define dlist_foreach(iter, lhead)
Definition: ilist.h:507
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:575
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:136
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:117
volatile bool ParallelMessagePending
Definition: parallel.c:106
#define dlist_container(type, membername, ptr)
Definition: ilist.h:477
ParallelWorkerInfo * worker
Definition: parallel.h:45
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
static void HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
Definition: parallel.c:1049
shm_mq_handle * error_mqh
Definition: parallel.h:28
int nworkers_launched
Definition: parallel.h:37
#define ereport(elevel, rest)
Definition: elog.h:122
MemoryContext TopMemoryContext
Definition: mcxt.c:44
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:170
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
dlist_node * cur
Definition: ilist.h:161
shm_mq_result
Definition: shm_mq.h:36
size_t Size
Definition: c.h:433
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:115
int i
static dlist_head pcxt_list
Definition: parallel.c:115
shm_mq_result shm_mq_receive(shm_mq_handle *mqh, Size *nbytesp, void **datap, bool nowait)
Definition: shm_mq.c:540
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:208

◆ InitializeParallelDSM()

void InitializeParallelDSM ( ParallelContext pcxt)

Definition at line 206 of file parallel.c.

References FixedParallelState::authenticated_user_id, BUFFERALIGN, FixedParallelState::current_user_id, FixedParallelState::database_id, dsm_create(), DSM_CREATE_NULL_IF_MAXSEGMENTS, DSM_HANDLE_INVALID, dsm_segment_address(), ParallelWorkerInfo::error_mqh, EstimateComboCIDStateSpace(), EstimateGUCStateSpace(), EstimateLibraryStateSpace(), EstimateReindexStateSpace(), EstimateSnapshotSpace(), EstimateTransactionStateSpace(), ParallelContext::estimator, ParallelContext::function_name, GetActiveSnapshot(), GetAuthenticatedUserId(), GetCurrentRoleId(), GetSessionDsmHandle(), GetTempNamespaceState(), GetTransactionSnapshot(), GetUserIdAndSecContext(), i, FixedParallelState::is_superuser, 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_COMBO_CID, PARALLEL_KEY_ENTRYPOINT, PARALLEL_KEY_ERROR_QUEUE, PARALLEL_KEY_FIXED, PARALLEL_KEY_GUC, PARALLEL_KEY_LIBRARY, PARALLEL_KEY_REINDEX_STATE, PARALLEL_KEY_SESSION_DSM, PARALLEL_KEY_TRANSACTION_SNAPSHOT, PARALLEL_KEY_TRANSACTION_STATE, PARALLEL_MAGIC, FixedParallelState::parallel_master_backend_id, FixedParallelState::parallel_master_pgproc, FixedParallelState::parallel_master_pid, ParallelContext::private_memory, FixedParallelState::sec_context, ParallelContext::seg, SerializeComboCIDState(), SerializeGUCState(), SerializeLibraryState(), SerializeReindexState(), SerializeSnapshot(), SerializeTransactionState(), session_auth_is_superuser, 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::temp_namespace_id, FixedParallelState::temp_toast_namespace_id, ParallelContext::toc, TopMemoryContext, TopTransactionContext, and ParallelContext::worker.

Referenced by _bt_begin_parallel(), and ExecInitParallelPlan().

207 {
208  MemoryContext oldcontext;
209  Size library_len = 0;
210  Size guc_len = 0;
211  Size combocidlen = 0;
212  Size tsnaplen = 0;
213  Size asnaplen = 0;
214  Size tstatelen = 0;
215  Size reindexlen = 0;
216  Size segsize = 0;
217  int i;
218  FixedParallelState *fps;
219  dsm_handle session_dsm_handle = DSM_HANDLE_INVALID;
220  Snapshot transaction_snapshot = GetTransactionSnapshot();
221  Snapshot active_snapshot = GetActiveSnapshot();
222 
223  /* We might be running in a very short-lived memory context. */
225 
226  /* Allow space to store the fixed-size parallel state. */
228  shm_toc_estimate_keys(&pcxt->estimator, 1);
229 
230  /*
231  * Normally, the user will have requested at least one worker process, but
232  * if by chance they have not, we can skip a bunch of things here.
233  */
234  if (pcxt->nworkers > 0)
235  {
236  /* Get (or create) the per-session DSM segment's handle. */
237  session_dsm_handle = GetSessionDsmHandle();
238 
239  /*
240  * If we weren't able to create a per-session DSM segment, then we can
241  * continue but we can't safely launch any workers because their
242  * record typmods would be incompatible so they couldn't exchange
243  * tuples.
244  */
245  if (session_dsm_handle == DSM_HANDLE_INVALID)
246  pcxt->nworkers = 0;
247  }
248 
249  if (pcxt->nworkers > 0)
250  {
251  /* Estimate space for various kinds of state sharing. */
252  library_len = EstimateLibraryStateSpace();
253  shm_toc_estimate_chunk(&pcxt->estimator, library_len);
254  guc_len = EstimateGUCStateSpace();
255  shm_toc_estimate_chunk(&pcxt->estimator, guc_len);
256  combocidlen = EstimateComboCIDStateSpace();
257  shm_toc_estimate_chunk(&pcxt->estimator, combocidlen);
258  tsnaplen = EstimateSnapshotSpace(transaction_snapshot);
259  shm_toc_estimate_chunk(&pcxt->estimator, tsnaplen);
260  asnaplen = EstimateSnapshotSpace(active_snapshot);
261  shm_toc_estimate_chunk(&pcxt->estimator, asnaplen);
262  tstatelen = EstimateTransactionStateSpace();
263  shm_toc_estimate_chunk(&pcxt->estimator, tstatelen);
265  reindexlen = EstimateReindexStateSpace();
266  shm_toc_estimate_chunk(&pcxt->estimator, reindexlen);
267  /* If you add more chunks here, you probably need to add keys. */
268  shm_toc_estimate_keys(&pcxt->estimator, 8);
269 
270  /* Estimate space need for error queues. */
273  "parallel error queue size not buffer-aligned");
276  pcxt->nworkers));
277  shm_toc_estimate_keys(&pcxt->estimator, 1);
278 
279  /* Estimate how much we'll need for the entrypoint info. */
280  shm_toc_estimate_chunk(&pcxt->estimator, strlen(pcxt->library_name) +
281  strlen(pcxt->function_name) + 2);
282  shm_toc_estimate_keys(&pcxt->estimator, 1);
283  }
284 
285  /*
286  * Create DSM and initialize with new table of contents. But if the user
287  * didn't request any workers, then don't bother creating a dynamic shared
288  * memory segment; instead, just use backend-private memory.
289  *
290  * Also, if we can't create a dynamic shared memory segment because the
291  * maximum number of segments have already been created, then fall back to
292  * backend-private memory, and plan not to use any workers. We hope this
293  * won't happen very often, but it's better to abandon the use of
294  * parallelism than to fail outright.
295  */
296  segsize = shm_toc_estimate(&pcxt->estimator);
297  if (pcxt->nworkers > 0)
299  if (pcxt->seg != NULL)
301  dsm_segment_address(pcxt->seg),
302  segsize);
303  else
304  {
305  pcxt->nworkers = 0;
308  segsize);
309  }
310 
311  /* Initialize fixed-size state in shared memory. */
312  fps = (FixedParallelState *)
313  shm_toc_allocate(pcxt->toc, sizeof(FixedParallelState));
314  fps->database_id = MyDatabaseId;
324  SpinLockInit(&fps->mutex);
325  fps->last_xlog_end = 0;
327 
328  /* We can skip the rest of this if we're not budgeting for any workers. */
329  if (pcxt->nworkers > 0)
330  {
331  char *libraryspace;
332  char *gucspace;
333  char *combocidspace;
334  char *tsnapspace;
335  char *asnapspace;
336  char *tstatespace;
337  char *reindexspace;
338  char *error_queue_space;
339  char *session_dsm_handle_space;
340  char *entrypointstate;
341  Size lnamelen;
342 
343  /* Serialize shared libraries we have loaded. */
344  libraryspace = shm_toc_allocate(pcxt->toc, library_len);
345  SerializeLibraryState(library_len, libraryspace);
346  shm_toc_insert(pcxt->toc, PARALLEL_KEY_LIBRARY, libraryspace);
347 
348  /* Serialize GUC settings. */
349  gucspace = shm_toc_allocate(pcxt->toc, guc_len);
350  SerializeGUCState(guc_len, gucspace);
351  shm_toc_insert(pcxt->toc, PARALLEL_KEY_GUC, gucspace);
352 
353  /* Serialize combo CID state. */
354  combocidspace = shm_toc_allocate(pcxt->toc, combocidlen);
355  SerializeComboCIDState(combocidlen, combocidspace);
356  shm_toc_insert(pcxt->toc, PARALLEL_KEY_COMBO_CID, combocidspace);
357 
358  /* Serialize transaction snapshot and active snapshot. */
359  tsnapspace = shm_toc_allocate(pcxt->toc, tsnaplen);
360  SerializeSnapshot(transaction_snapshot, tsnapspace);
362  tsnapspace);
363  asnapspace = shm_toc_allocate(pcxt->toc, asnaplen);
364  SerializeSnapshot(active_snapshot, asnapspace);
365  shm_toc_insert(pcxt->toc, PARALLEL_KEY_ACTIVE_SNAPSHOT, asnapspace);
366 
367  /* Provide the handle for per-session segment. */
368  session_dsm_handle_space = shm_toc_allocate(pcxt->toc,
369  sizeof(dsm_handle));
370  *(dsm_handle *) session_dsm_handle_space = session_dsm_handle;
372  session_dsm_handle_space);
373 
374  /* Serialize transaction state. */
375  tstatespace = shm_toc_allocate(pcxt->toc, tstatelen);
376  SerializeTransactionState(tstatelen, tstatespace);
378 
379  /* Serialize reindex state. */
380  reindexspace = shm_toc_allocate(pcxt->toc, reindexlen);
381  SerializeReindexState(reindexlen, reindexspace);
382  shm_toc_insert(pcxt->toc, PARALLEL_KEY_REINDEX_STATE, reindexspace);
383 
384  /* Allocate space for worker information. */
385  pcxt->worker = palloc0(sizeof(ParallelWorkerInfo) * pcxt->nworkers);
386 
387  /*
388  * Establish error queues in dynamic shared memory.
389  *
390  * These queues should be used only for transmitting ErrorResponse,
391  * NoticeResponse, and NotifyResponse protocol messages. Tuple data
392  * should be transmitted via separate (possibly larger?) queues.
393  */
394  error_queue_space =
395  shm_toc_allocate(pcxt->toc,
397  pcxt->nworkers));
398  for (i = 0; i < pcxt->nworkers; ++i)
399  {
400  char *start;
401  shm_mq *mq;
402 
403  start = error_queue_space + i * PARALLEL_ERROR_QUEUE_SIZE;
404  mq = shm_mq_create(start, PARALLEL_ERROR_QUEUE_SIZE);
406  pcxt->worker[i].error_mqh = shm_mq_attach(mq, pcxt->seg, NULL);
407  }
408  shm_toc_insert(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, error_queue_space);
409 
410  /*
411  * Serialize entrypoint information. It's unsafe to pass function
412  * pointers across processes, as the function pointer may be different
413  * in each process in EXEC_BACKEND builds, so we always pass library
414  * and function name. (We use library name "postgres" for functions
415  * in the core backend.)
416  */
417  lnamelen = strlen(pcxt->library_name);
418  entrypointstate = shm_toc_allocate(pcxt->toc, lnamelen +
419  strlen(pcxt->function_name) + 2);
420  strcpy(entrypointstate, pcxt->library_name);
421  strcpy(entrypointstate + lnamelen + 1, pcxt->function_name);
422  shm_toc_insert(pcxt->toc, PARALLEL_KEY_ENTRYPOINT, entrypointstate);
423  }
424 
425  /* Restore previous memory context. */
426  MemoryContextSwitchTo(oldcontext);
427 }
#define PARALLEL_ERROR_QUEUE_SIZE
Definition: parallel.c:52
shm_toc * shm_toc_create(uint64 magic, void *address, Size nbytes)
Definition: shm_toc.c:40
int MyProcPid
Definition: globals.c:42
BackendId MyBackendId
Definition: globals.c:82
MemoryContext TopTransactionContext
Definition: mcxt.c:49
uint32 dsm_handle
Definition: dsm_impl.h:55
PGPROC * MyProc
Definition: proc.c:67
dsm_segment * seg
Definition: parallel.h:42
void SerializeReindexState(Size maxsize, char *start_address)
Definition: index.c:4118
shm_toc_estimator estimator
Definition: parallel.h:41
#define SpinLockInit(lock)
Definition: spin.h:60
void GetTempNamespaceState(Oid *tempNamespaceId, Oid *tempToastNamespaceId)
Definition: namespace.c:3253
Oid authenticated_user_id
Definition: parallel.c:79
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:839
PGPROC * parallel_master_pgproc
Definition: parallel.c:86
Oid temp_toast_namespace_id
Definition: parallel.c:83
Size shm_toc_estimate(shm_toc_estimator *e)
Definition: shm_toc.c:263
void SerializeTransactionState(Size maxsize, char *start_address)
Definition: xact.c:4971
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:304
Oid GetCurrentRoleId(void)
Definition: miscinit.c:731
#define DSM_HANDLE_INVALID
Definition: dsm.h:23
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:795
ParallelWorkerInfo * worker
Definition: parallel.h:45
void SerializeLibraryState(Size maxsize, char *start_address)
Definition: dfmgr.c:728
Oid GetAuthenticatedUserId(void)
Definition: miscinit.c:438
#define PARALLEL_KEY_TRANSACTION_SNAPSHOT
Definition: parallel.c:67
char * function_name
Definition: parallel.h:39
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2068
shm_mq * shm_mq_create(void *address, Size size)
Definition: shm_mq.c:169
#define PARALLEL_KEY_FIXED
Definition: parallel.c:62
#define PARALLEL_KEY_ERROR_QUEUE
Definition: parallel.c:63
#define DSM_CREATE_NULL_IF_MAXSEGMENTS
Definition: dsm.h:20
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:484
shm_mq_handle * error_mqh
Definition: parallel.h:28
#define PARALLEL_KEY_GUC
Definition: parallel.c:65
Size EstimateGUCStateSpace(void)
Definition: guc.c:9367
Size EstimateComboCIDStateSpace(void)
Definition: combocid.c:299
XLogRecPtr last_xlog_end
Definition: parallel.c:94
Size EstimateReindexStateSpace(void)
Definition: index.c:4107
MemoryContext TopMemoryContext
Definition: mcxt.c:44
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:2044
Size mul_size(Size s1, Size s2)
Definition: shmem.c:492
void * palloc0(Size size)
Definition: mcxt.c:955
dsm_segment * dsm_create(Size size, int flags)
Definition: dsm.c:452
Oid MyDatabaseId
Definition: globals.c:86
pid_t parallel_master_pid
Definition: parallel.c:87
Size EstimateLibraryStateSpace(void)
Definition: dfmgr.c:711
#define PARALLEL_MAGIC
Definition: parallel.c:55
char * library_name
Definition: parallel.h:38
BackendId parallel_master_backend_id
Definition: parallel.c:88
void * dsm_segment_address(dsm_segment *seg)
Definition: dsm.c:987
Size EstimateTransactionStateSpace(void)
Definition: xact.c:4938
#define PARALLEL_KEY_REINDEX_STATE
Definition: parallel.c:72
size_t Size
Definition: c.h:433
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
shm_mq_handle * shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:282
#define PARALLEL_KEY_TRANSACTION_STATE
Definition: parallel.c:69
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:771
int i
Definition: shm_mq.c:70
#define PARALLEL_KEY_SESSION_DSM
Definition: parallel.c:71
#define BUFFERALIGN(LEN)
Definition: c.h:654
void shm_mq_set_receiver(shm_mq *mq, PGPROC *proc)
Definition: shm_mq.c:198
dsm_handle GetSessionDsmHandle(void)
Definition: session.c:70
bool session_auth_is_superuser
Definition: guc.c:451
#define PARALLEL_KEY_ENTRYPOINT
Definition: parallel.c:70
#define PARALLEL_KEY_COMBO_CID
Definition: parallel.c:66
void SerializeGUCState(Size maxsize, char *start_address)
Definition: guc.c:9514
#define PARALLEL_KEY_ACTIVE_SNAPSHOT
Definition: parallel.c:68
void SerializeComboCIDState(Size maxsize, char *start_address)
Definition: combocid.c:318
#define PARALLEL_KEY_LIBRARY
Definition: parallel.c:64
shm_toc * toc
Definition: parallel.h:44
void * private_memory
Definition: parallel.h:43

◆ LaunchParallelWorkers()

void LaunchParallelWorkers ( ParallelContext pcxt)

Definition at line 481 of file parallel.c.

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, palloc0(), RegisterDynamicBackgroundWorker(), ParallelContext::seg, shm_mq_detach(), shm_mq_set_handle(), snprintf(), TopTransactionContext, UInt32GetDatum, and ParallelContext::worker.

Referenced by _bt_begin_parallel(), ExecGather(), and ExecGatherMerge().

482 {
483  MemoryContext oldcontext;
484  BackgroundWorker worker;
485  int i;
486  bool any_registrations_failed = false;
487 
488  /* Skip this if we have no workers. */
489  if (pcxt->nworkers == 0)
490  return;
491 
492  /* We need to be a lock group leader. */
494 
495  /* If we do have workers, we'd better have a DSM segment. */
496  Assert(pcxt->seg != NULL);
497 
498  /* We might be running in a short-lived memory context. */
500 
501  /* Configure a worker. */
502  memset(&worker, 0, sizeof(worker));
503  snprintf(worker.bgw_name, BGW_MAXLEN, "parallel worker for PID %d",
504  MyProcPid);
505  snprintf(worker.bgw_type, BGW_MAXLEN, "parallel worker");
506  worker.bgw_flags =
511  sprintf(worker.bgw_library_name, "postgres");
512  sprintf(worker.bgw_function_name, "ParallelWorkerMain");
514  worker.bgw_notify_pid = MyProcPid;
515 
516  /*
517  * Start workers.
518  *
519  * The caller must be able to tolerate ending up with fewer workers than
520  * expected, so there is no need to throw an error here if registration
521  * fails. It wouldn't help much anyway, because registering the worker in
522  * no way guarantees that it will start up and initialize successfully.
523  */
524  for (i = 0; i < pcxt->nworkers; ++i)
525  {
526  memcpy(worker.bgw_extra, &i, sizeof(int));
527  if (!any_registrations_failed &&
529  &pcxt->worker[i].bgwhandle))
530  {
532  pcxt->worker[i].bgwhandle);
533  pcxt->nworkers_launched++;
534  }
535  else
536  {
537  /*
538  * If we weren't able to register the worker, then we've bumped up
539  * against the max_worker_processes limit, and future
540  * registrations will probably fail too, so arrange to skip them.
541  * But we still have to execute this code for the remaining slots
542  * to make sure that we forget about the error queues we budgeted
543  * for those workers. Otherwise, we'll wait for them to start,
544  * but they never will.
545  */
546  any_registrations_failed = true;
547  pcxt->worker[i].bgwhandle = NULL;
548  shm_mq_detach(pcxt->worker[i].error_mqh);
549  pcxt->worker[i].error_mqh = NULL;
550  }
551  }
552 
553  /*
554  * Now that nworkers_launched has taken its final value, we can initialize
555  * known_attached_workers.
556  */
557  if (pcxt->nworkers_launched > 0)
558  {
559  pcxt->known_attached_workers =
560  palloc0(sizeof(bool) * pcxt->nworkers_launched);
561  pcxt->nknown_attached_workers = 0;
562  }
563 
564  /* Restore previous memory context. */
565  MemoryContextSwitchTo(oldcontext);
566 }
char bgw_extra[BGW_EXTRALEN]
Definition: bgworker.h:98
int MyProcPid
Definition: globals.c:42
MemoryContext TopTransactionContext
Definition: mcxt.c:49
void shm_mq_detach(shm_mq_handle *mqh)
Definition: shm_mq.c:793
dsm_segment * seg
Definition: parallel.h:42
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
dsm_handle dsm_segment_handle(dsm_segment *seg)
Definition: dsm.c:1015
int bgw_restart_time
Definition: bgworker.h:94
#define BGWORKER_CLASS_PARALLEL
Definition: bgworker.h:67
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
int nknown_attached_workers
Definition: parallel.h:46
#define BGWORKER_SHMEM_ACCESS
Definition: bgworker.h:52
char bgw_function_name[BGW_MAXLEN]
Definition: bgworker.h:96
ParallelWorkerInfo * worker
Definition: parallel.h:45
Datum bgw_main_arg
Definition: bgworker.h:97
shm_mq_handle * error_mqh
Definition: parallel.h:28
BackgroundWorkerHandle * bgwhandle
Definition: parallel.h:27
#define BGW_NEVER_RESTART
Definition: bgworker.h:84
#define UInt32GetDatum(X)
Definition: postgres.h:478
int nworkers_launched
Definition: parallel.h:37
void BecomeLockGroupLeader(void)
Definition: proc.c:1824
bool * known_attached_workers
Definition: parallel.h:47
void * palloc0(Size size)
Definition: mcxt.c:955
void shm_mq_set_handle(shm_mq_handle *mqh, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:310
char bgw_name[BGW_MAXLEN]
Definition: bgworker.h:90
#define Assert(condition)
Definition: c.h:699
#define BGWORKER_BACKEND_DATABASE_CONNECTION
Definition: bgworker.h:59
#define BGW_MAXLEN
Definition: bgworker.h:85
BgWorkerStartTime bgw_start_time
Definition: bgworker.h:93
bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker, BackgroundWorkerHandle **handle)
Definition: bgworker.c:939
char bgw_type[BGW_MAXLEN]
Definition: bgworker.h:91
pid_t bgw_notify_pid
Definition: bgworker.h:99
int i
char bgw_library_name[BGW_MAXLEN]
Definition: bgworker.h:95

◆ ParallelContextActive()

bool ParallelContextActive ( void  )

Definition at line 936 of file parallel.c.

References dlist_is_empty().

Referenced by ExitParallelMode().

937 {
938  return !dlist_is_empty(&pcxt_list);
939 }
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289
static dlist_head pcxt_list
Definition: parallel.c:115

◆ ParallelWorkerMain()

void ParallelWorkerMain ( Datum  main_arg)

Definition at line 1197 of file parallel.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, AttachSession(), FixedParallelState::authenticated_user_id, BackgroundWorkerInitializeConnectionByOid(), BackgroundWorkerUnblockSignals(), BecomeLockGroupMember(), BackgroundWorker::bgw_extra, CommitTransactionCommand(), FixedParallelState::current_user_id, CurrentMemoryContext, CurrentResourceOwner, FixedParallelState::database_id, DatumGetUInt32, DetachSession(), die(), dsm_attach(), dsm_segment_address(), EndParallelWorkerTransaction(), EnterParallelMode(), ereport, errcode(), errmsg(), ERROR, ExitParallelMode(), GetDatabaseEncoding(), InitializingParallelWorker, InvalidateSystemCaches(), FixedParallelState::is_superuser, LookupParallelWorkerFunction(), MyBgworkerEntry, MyCancelKey, MyProc, MyProcPid, on_shmem_exit(), FixedParallelState::outer_user_id, PARALLEL_ERROR_QUEUE_SIZE, PARALLEL_KEY_ACTIVE_SNAPSHOT, PARALLEL_KEY_COMBO_CID, PARALLEL_KEY_ENTRYPOINT, PARALLEL_KEY_ERROR_QUEUE, PARALLEL_KEY_FIXED, PARALLEL_KEY_GUC, PARALLEL_KEY_LIBRARY, PARALLEL_KEY_REINDEX_STATE, PARALLEL_KEY_SESSION_DSM, PARALLEL_KEY_TRANSACTION_SNAPSHOT, PARALLEL_KEY_TRANSACTION_STATE, PARALLEL_MAGIC, FixedParallelState::parallel_master_backend_id, FixedParallelState::parallel_master_pgproc, FixedParallelState::parallel_master_pid, ParallelMasterBackendId, ParallelMasterPid, ParallelWorkerNumber, ParallelWorkerShutdown(), PopActiveSnapshot(), pq_beginmessage(), pq_endmessage(), pq_putmessage, pq_redirect_to_shm_mq(), pq_sendint32(), pq_set_parallel_master(), pqsignal(), PushActiveSnapshot(), ResourceOwnerCreate(), RestoreComboCIDState(), RestoreGUCState(), RestoreLibraryState(), RestoreReindexState(), RestoreSnapshot(), RestoreTransactionSnapshot(), FixedParallelState::sec_context, SetClientEncoding(), SetCurrentRoleId(), SetTempNamespaceState(), SetUserIdAndSecContext(), shm_mq_attach(), shm_mq_set_sender(), shm_toc_attach(), shm_toc_lookup(), StartParallelWorkerTransaction(), StartTransactionCommand(), FixedParallelState::temp_namespace_id, FixedParallelState::temp_toast_namespace_id, and TopMemoryContext.

1198 {
1199  dsm_segment *seg;
1200  shm_toc *toc;
1201  FixedParallelState *fps;
1202  char *error_queue_space;
1203  shm_mq *mq;
1204  shm_mq_handle *mqh;
1205  char *libraryspace;
1206  char *entrypointstate;
1207  char *library_name;
1208  char *function_name;
1209  parallel_worker_main_type entrypt;
1210  char *gucspace;
1211  char *combocidspace;
1212  char *tsnapspace;
1213  char *asnapspace;
1214  char *tstatespace;
1215  char *reindexspace;
1216  StringInfoData msgbuf;
1217  char *session_dsm_handle_space;
1218 
1219  /* Set flag to indicate that we're initializing a parallel worker. */
1221 
1222  /* Establish signal handlers. */
1223  pqsignal(SIGTERM, die);
1225 
1226  /* Determine and set our parallel worker number. */
1228  memcpy(&ParallelWorkerNumber, MyBgworkerEntry->bgw_extra, sizeof(int));
1229 
1230  /* Set up a memory context and resource owner. */
1231  Assert(CurrentResourceOwner == NULL);
1232  CurrentResourceOwner = ResourceOwnerCreate(NULL, "parallel toplevel");
1234  "Parallel worker",
1236 
1237  /*
1238  * Now that we have a resource owner, we can attach to the dynamic shared
1239  * memory segment and read the table of contents.
1240  */
1241  seg = dsm_attach(DatumGetUInt32(main_arg));
1242  if (seg == NULL)
1243  ereport(ERROR,
1244  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1245  errmsg("could not map dynamic shared memory segment")));
1247  if (toc == NULL)
1248  ereport(ERROR,
1249  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1250  errmsg("invalid magic number in dynamic shared memory segment")));
1251 
1252  /* Look up fixed parallel state. */
1253  fps = shm_toc_lookup(toc, PARALLEL_KEY_FIXED, false);
1254  MyFixedParallelState = fps;
1255 
1256  /* Arrange to signal the leader if we exit. */
1260 
1261  /*
1262  * Now we can find and attach to the error queue provided for us. That's
1263  * good, because until we do that, any errors that happen here will not be
1264  * reported back to the process that requested that this worker be
1265  * launched.
1266  */
1267  error_queue_space = shm_toc_lookup(toc, PARALLEL_KEY_ERROR_QUEUE, false);
1268  mq = (shm_mq *) (error_queue_space +
1271  mqh = shm_mq_attach(mq, seg, NULL);
1272  pq_redirect_to_shm_mq(seg, mqh);
1275 
1276  /*
1277  * Send a BackendKeyData message to the process that initiated parallelism
1278  * so that it has access to our PID before it receives any other messages
1279  * from us. Our cancel key is sent, too, since that's the way the
1280  * protocol message is defined, but it won't actually be used for anything
1281  * in this case.
1282  */
1283  pq_beginmessage(&msgbuf, 'K');
1284  pq_sendint32(&msgbuf, (int32) MyProcPid);
1285  pq_sendint32(&msgbuf, (int32) MyCancelKey);
1286  pq_endmessage(&msgbuf);
1287 
1288  /*
1289  * Hooray! Primary initialization is complete. Now, we need to set up our
1290  * backend-local state to match the original backend.
1291  */
1292 
1293  /*
1294  * Join locking group. We must do this before anything that could try to
1295  * acquire a heavyweight lock, because any heavyweight locks acquired to
1296  * this point could block either directly against the parallel group
1297  * leader or against some process which in turn waits for a lock that
1298  * conflicts with the parallel group leader, causing an undetected
1299  * deadlock. (If we can't join the lock group, the leader has gone away,
1300  * so just exit quietly.)
1301  */
1303  fps->parallel_master_pid))
1304  return;
1305 
1306  /*
1307  * Load libraries that were loaded by original backend. We want to do
1308  * this before restoring GUCs, because the libraries might define custom
1309  * variables.
1310  */
1311  libraryspace = shm_toc_lookup(toc, PARALLEL_KEY_LIBRARY, false);
1312  RestoreLibraryState(libraryspace);
1313 
1314  /*
1315  * Identify the entry point to be called. In theory this could result in
1316  * loading an additional library, though most likely the entry point is in
1317  * the core backend or in a library we just loaded.
1318  */
1319  entrypointstate = shm_toc_lookup(toc, PARALLEL_KEY_ENTRYPOINT, false);
1320  library_name = entrypointstate;
1321  function_name = entrypointstate + strlen(library_name) + 1;
1322 
1323  entrypt = LookupParallelWorkerFunction(library_name, function_name);
1324 
1325  /* Restore database connection. */
1327  fps->authenticated_user_id,
1328  0);
1329 
1330  /*
1331  * Set the client encoding to the database encoding, since that is what
1332  * the leader will expect.
1333  */
1335 
1336  /* Restore GUC values from launching backend. */
1337  gucspace = shm_toc_lookup(toc, PARALLEL_KEY_GUC, false);
1339  RestoreGUCState(gucspace);
1341 
1342  /* Crank up a transaction state appropriate to a parallel worker. */
1343  tstatespace = shm_toc_lookup(toc, PARALLEL_KEY_TRANSACTION_STATE, false);
1344  StartParallelWorkerTransaction(tstatespace);
1345 
1346  /* Restore combo CID state. */
1347  combocidspace = shm_toc_lookup(toc, PARALLEL_KEY_COMBO_CID, false);
1348  RestoreComboCIDState(combocidspace);
1349 
1350  /* Attach to the per-session DSM segment and contained objects. */
1351  session_dsm_handle_space =
1353  AttachSession(*(dsm_handle *) session_dsm_handle_space);
1354 
1355  /* Restore transaction snapshot. */
1356  tsnapspace = shm_toc_lookup(toc, PARALLEL_KEY_TRANSACTION_SNAPSHOT, false);
1358  fps->parallel_master_pgproc);
1359 
1360  /* Restore active snapshot. */
1361  asnapspace = shm_toc_lookup(toc, PARALLEL_KEY_ACTIVE_SNAPSHOT, false);
1362  PushActiveSnapshot(RestoreSnapshot(asnapspace));
1363 
1364  /*
1365  * We've changed which tuples we can see, and must therefore invalidate
1366  * system caches.
1367  */
1369 
1370  /*
1371  * Restore current role id. Skip verifying whether session user is
1372  * allowed to become this role and blindly restore the leader's state for
1373  * current role.
1374  */
1376 
1377  /* Restore user ID and security context. */
1379 
1380  /* Restore temp-namespace state to ensure search path matches leader's. */
1383 
1384  /* Restore reindex state. */
1385  reindexspace = shm_toc_lookup(toc, PARALLEL_KEY_REINDEX_STATE, false);
1386  RestoreReindexState(reindexspace);
1387 
1388  /*
1389  * We've initialized all of our state now; nothing should change
1390  * hereafter.
1391  */
1394 
1395  /*
1396  * Time to do the real work: invoke the caller-supplied code.
1397  */
1398  entrypt(seg, toc);
1399 
1400  /* Must exit parallel mode to pop active snapshot. */
1401  ExitParallelMode();
1402 
1403  /* Must pop active snapshot so resowner.c doesn't complain. */
1405 
1406  /* Shut down the parallel-worker transaction. */
1408 
1409  /* Detach from the per-session DSM segment. */
1410  DetachSession();
1411 
1412  /* Report success. */
1413  pq_putmessage('X', NULL, 0);
1414 }
char bgw_extra[BGW_EXTRALEN]
Definition: bgworker.h:98
#define DatumGetUInt32(X)
Definition: postgres.h:471
#define PARALLEL_ERROR_QUEUE_SIZE
Definition: parallel.c:52
int MyProcPid
Definition: globals.c:42
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:2127
uint32 dsm_handle
Definition: dsm_impl.h:55
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:491
PGPROC * MyProc
Definition: proc.c:67
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
ResourceOwner CurrentResourceOwner
Definition: resowner.c:140
void CommitTransactionCommand(void)
Definition: xact.c:2744
void EndParallelWorkerTransaction(void)
Definition: xact.c:5062
void RestoreTransactionSnapshot(Snapshot snapshot, void *master_pgproc)
Definition: snapmgr.c:2191
dsm_segment * dsm_attach(dsm_handle h)
Definition: dsm.c:548
Oid authenticated_user_id
Definition: parallel.c:79
int errcode(int sqlerrcode)
Definition: elog.c:575
PGPROC * parallel_master_pgproc
Definition: parallel.c:86
Oid temp_toast_namespace_id
Definition: parallel.c:83
void DetachSession(void)
Definition: session.c:201
BackgroundWorker * MyBgworkerEntry
Definition: postmaster.c:191
bool BecomeLockGroupMember(PGPROC *leader, int pid)
Definition: proc.c:1854
void PopActiveSnapshot(void)
Definition: snapmgr.c:812
void InvalidateSystemCaches(void)
Definition: inval.c:641
static pid_t ParallelMasterPid
Definition: parallel.c:118
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:87
void RestoreComboCIDState(char *comboCIDstate)
Definition: combocid.c:344
signed int int32
Definition: c.h:313
#define ERROR
Definition: elog.h:43
#define PARALLEL_KEY_TRANSACTION_SNAPSHOT
Definition: parallel.c:67
int32 MyCancelKey
Definition: globals.c:45
void ExitParallelMode(void)
Definition: xact.c:885
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
#define PARALLEL_KEY_FIXED
Definition: parallel.c:62
#define PARALLEL_KEY_ERROR_QUEUE
Definition: parallel.c:63
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:359
void SetTempNamespaceState(Oid tempNamespaceId, Oid tempToastNamespaceId)
Definition: namespace.c:3269
void PushActiveSnapshot(Snapshot snap)
Definition: snapmgr.c:733
#define PARALLEL_KEY_GUC
Definition: parallel.c:65
int SetClientEncoding(int encoding)
Definition: mbutils.c:201
int ParallelWorkerNumber
Definition: parallel.c:103
void AttachSession(dsm_handle handle)
Definition: session.c:155
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
static void ParallelWorkerShutdown(int code, Datum arg)
Definition: parallel.c:1439
void shm_mq_set_sender(shm_mq *mq, PGPROC *proc)
Definition: shm_mq.c:216
#define ereport(elevel, rest)
Definition: elog.h:122
MemoryContext TopMemoryContext
Definition: mcxt.c:44
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:170
static parallel_worker_main_type LookupParallelWorkerFunction(const char *libraryname, const char *funcname)
Definition: parallel.c:1465
void RestoreLibraryState(char *start_address)
Definition: dfmgr.c:750
uintptr_t Datum
Definition: postgres.h:367
shm_toc * shm_toc_attach(uint64 magic, void *address)
Definition: shm_toc.c:64
int GetDatabaseEncoding(void)
Definition: mbutils.c:1004
pid_t parallel_master_pid
Definition: parallel.c:87
void BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, uint32 flags)
Definition: postmaster.c:5568
#define PARALLEL_MAGIC
Definition: parallel.c:55
void pq_redirect_to_shm_mq(dsm_segment *seg, shm_mq_handle *mqh)
Definition: pqmq.c:55
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
BackendId parallel_master_backend_id
Definition: parallel.c:88
void * dsm_segment_address(dsm_segment *seg)
Definition: dsm.c:987
#define Assert(condition)
Definition: c.h:699
BackendId ParallelMasterBackendId
Definition: globals.c:84
void StartParallelWorkerTransaction(char *tstatespace)
Definition: xact.c:5039
void StartTransactionCommand(void)
Definition: xact.c:2673
#define PARALLEL_KEY_REINDEX_STATE
Definition: parallel.c:72
void EnterParallelMode(void)
Definition: xact.c:872
shm_mq_handle * shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:282
void pq_set_parallel_master(pid_t pid, BackendId backend_id)
Definition: pqmq.c:80
#define PARALLEL_KEY_TRANSACTION_STATE
Definition: parallel.c:69
void RestoreReindexState(void *reindexstate)
Definition: index.c:4136
int errmsg(const char *fmt,...)
Definition: elog.c:797
void(* parallel_worker_main_type)(dsm_segment *seg, shm_toc *toc)
Definition: parallel.h:23
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:298
static FixedParallelState * MyFixedParallelState
Definition: parallel.c:112
void die(SIGNAL_ARGS)
Definition: postgres.c:2658
void SetCurrentRoleId(Oid roleid, bool is_superuser)
Definition: miscinit.c:752
bool InitializingParallelWorker
Definition: parallel.c:109
Definition: shm_mq.c:70
#define PARALLEL_KEY_SESSION_DSM
Definition: parallel.c:71
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:42
#define PARALLEL_KEY_ENTRYPOINT
Definition: parallel.c:70
#define PARALLEL_KEY_COMBO_CID
Definition: parallel.c:66
#define PARALLEL_KEY_ACTIVE_SNAPSHOT
Definition: parallel.c:68
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
#define PARALLEL_KEY_LIBRARY
Definition: parallel.c:64
void RestoreGUCState(void *gucstate)
Definition: guc.c:9579
ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char *name)
Definition: resowner.c:418
void BackgroundWorkerUnblockSignals(void)
Definition: postmaster.c:5597

◆ ParallelWorkerReportLastRecEnd()

void ParallelWorkerReportLastRecEnd ( XLogRecPtr  last_xlog_end)

Definition at line 1421 of file parallel.c.

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

Referenced by CommitTransaction().

1422 {
1424 
1425  Assert(fps != NULL);
1426  SpinLockAcquire(&fps->mutex);
1427  if (fps->last_xlog_end < last_xlog_end)
1428  fps->last_xlog_end = last_xlog_end;
1429  SpinLockRelease(&fps->mutex);
1430 }
#define SpinLockAcquire(lock)
Definition: spin.h:62
XLogRecPtr last_xlog_end
Definition: parallel.c:94
#define SpinLockRelease(lock)
Definition: spin.h:64
#define Assert(condition)
Definition: c.h:699
static FixedParallelState * MyFixedParallelState
Definition: parallel.c:112

◆ ReinitializeParallelDSM()

void ReinitializeParallelDSM ( ParallelContext pcxt)

Definition at line 434 of file parallel.c.

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().

435 {
436  FixedParallelState *fps;
437 
438  /* Wait for any old workers to exit. */
439  if (pcxt->nworkers_launched > 0)
440  {
443  pcxt->nworkers_launched = 0;
444  if (pcxt->known_attached_workers)
445  {
447  pcxt->known_attached_workers = NULL;
448  pcxt->nknown_attached_workers = 0;
449  }
450  }
451 
452  /* Reset a few bits of fixed parallel state to a clean state. */
453  fps = shm_toc_lookup(pcxt->toc, PARALLEL_KEY_FIXED, false);
454  fps->last_xlog_end = 0;
455 
456  /* Recreate error queues (if they exist). */
457  if (pcxt->nworkers > 0)
458  {
459  char *error_queue_space;
460  int i;
461 
462  error_queue_space =
464  for (i = 0; i < pcxt->nworkers; ++i)
465  {
466  char *start;
467  shm_mq *mq;
468 
469  start = error_queue_space + i * PARALLEL_ERROR_QUEUE_SIZE;
470  mq = shm_mq_create(start, PARALLEL_ERROR_QUEUE_SIZE);
472  pcxt->worker[i].error_mqh = shm_mq_attach(mq, pcxt->seg, NULL);
473  }
474  }
475 }
#define PARALLEL_ERROR_QUEUE_SIZE
Definition: parallel.c:52
PGPROC * MyProc
Definition: proc.c:67
dsm_segment * seg
Definition: parallel.h:42
static void WaitForParallelWorkersToExit(ParallelContext *pcxt)
Definition: parallel.c:822
int nknown_attached_workers
Definition: parallel.h:46
void WaitForParallelWorkersToFinish(ParallelContext *pcxt)
Definition: parallel.c:708
ParallelWorkerInfo * worker
Definition: parallel.h:45
void pfree(void *pointer)
Definition: mcxt.c:1031
shm_mq * shm_mq_create(void *address, Size size)
Definition: shm_mq.c:169
#define PARALLEL_KEY_FIXED
Definition: parallel.c:62
#define PARALLEL_KEY_ERROR_QUEUE
Definition: parallel.c:63
shm_mq_handle * error_mqh
Definition: parallel.h:28
int nworkers_launched
Definition: parallel.h:37
XLogRecPtr last_xlog_end
Definition: parallel.c:94
bool * known_attached_workers
Definition: parallel.h:47
shm_mq_handle * shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle)
Definition: shm_mq.c:282
int i
Definition: shm_mq.c:70
void shm_mq_set_receiver(shm_mq *mq, PGPROC *proc)
Definition: shm_mq.c:198
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
shm_toc * toc
Definition: parallel.h:44

◆ WaitForParallelWorkersToAttach()

void WaitForParallelWorkersToAttach ( ParallelContext pcxt)

Definition at line 601 of file parallel.c.

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, proc_exit(), ResetLatch(), shm_mq_get_queue(), shm_mq_get_sender(), status(), WAIT_EVENT_BGWORKER_STARTUP, WaitLatch(), WL_LATCH_SET, WL_POSTMASTER_DEATH, and ParallelContext::worker.

Referenced by _bt_begin_parallel().

602 {
603  int i;
604 
605  /* Skip this if we have no launched workers. */
606  if (pcxt->nworkers_launched == 0)
607  return;
608 
609  for (;;)
610  {
611  /*
612  * This will process any parallel messages that are pending and it may
613  * also throw an error propagated from a worker.
614  */
616 
617  for (i = 0; i < pcxt->nworkers_launched; ++i)
618  {
620  shm_mq *mq;
621  int rc;
622  pid_t pid;
623 
624  if (pcxt->known_attached_workers[i])
625  continue;
626 
627  /*
628  * If error_mqh is NULL, then the worker has already exited
629  * cleanly.
630  */
631  if (pcxt->worker[i].error_mqh == NULL)
632  {
633  pcxt->known_attached_workers[i] = true;
634  ++pcxt->nknown_attached_workers;
635  continue;
636  }
637 
638  status = GetBackgroundWorkerPid(pcxt->worker[i].bgwhandle, &pid);
639  if (status == BGWH_STARTED)
640  {
641  /* Has the worker attached to the error queue? */
642  mq = shm_mq_get_queue(pcxt->worker[i].error_mqh);
643  if (shm_mq_get_sender(mq) != NULL)
644  {
645  /* Yes, so it is known to be attached. */
646  pcxt->known_attached_workers[i] = true;
647  ++pcxt->nknown_attached_workers;
648  }
649  }
650  else if (status == BGWH_STOPPED)
651  {
652  /*
653  * If the worker stopped without attaching to the error queue,
654  * throw an error.
655  */
656  mq = shm_mq_get_queue(pcxt->worker[i].error_mqh);
657  if (shm_mq_get_sender(mq) == NULL)
658  ereport(ERROR,
659  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
660  errmsg("parallel worker failed to initialize"),
661  errhint("More details may be available in the server log.")));
662 
663  pcxt->known_attached_workers[i] = true;
664  ++pcxt->nknown_attached_workers;
665  }
666  else
667  {
668  /*
669  * Worker not yet started, so we must wait. The postmaster
670  * will notify us if the worker's state changes. Our latch
671  * might also get set for some other reason, but if so we'll
672  * just end up waiting for the same worker again.
673  */
674  rc = WaitLatch(MyLatch,
677 
678  /* emergency bailout if postmaster has died */
679  if (rc & WL_POSTMASTER_DEATH)
680  proc_exit(1);
681 
682  if (rc & WL_LATCH_SET)
684  }
685  }
686 
687  /* If all workers are known to have started, we're done. */
688  if (pcxt->nknown_attached_workers >= pcxt->nworkers_launched)
689  {
691  break;
692  }
693  }
694 }
int errhint(const char *fmt,...)
Definition: elog.c:987
PGPROC * shm_mq_get_sender(shm_mq *mq)
Definition: shm_mq.c:249
void proc_exit(int code)
Definition: ipc.c:104
int errcode(int sqlerrcode)
Definition: elog.c:575
int nknown_attached_workers
Definition: parallel.h:46
void ResetLatch(volatile Latch *latch)
Definition: latch.c:497
ParallelWorkerInfo * worker
Definition: parallel.h:45
int WaitLatch(volatile Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:336
#define ERROR
Definition: elog.h:43
shm_mq_handle * error_mqh
Definition: parallel.h:28
BackgroundWorkerHandle * bgwhandle
Definition: parallel.h:27
int nworkers_launched
Definition: parallel.h:37
BgwHandleStatus
Definition: bgworker.h:102
#define ereport(elevel, rest)
Definition: elog.h:122
bool * known_attached_workers
Definition: parallel.h:47
#define WL_POSTMASTER_DEATH
Definition: latch.h:128
#define Assert(condition)
Definition: c.h:699
shm_mq * shm_mq_get_queue(shm_mq_handle *mqh)
Definition: shm_mq.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
Definition: shm_mq.c:70
struct Latch * MyLatch
Definition: globals.c:55
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:98
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:225
#define WL_LATCH_SET
Definition: latch.h:124
BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle, pid_t *pidp)
Definition: bgworker.c:1051

◆ WaitForParallelWorkersToFinish()

void WaitForParallelWorkersToFinish ( ParallelContext pcxt)

Definition at line 708 of file parallel.c.

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, WAIT_EVENT_PARALLEL_FINISH, WaitLatch(), WL_LATCH_SET, ParallelContext::worker, and XactLastRecEnd.

Referenced by _bt_end_parallel(), ExecParallelFinish(), and ReinitializeParallelDSM().

709 {
710  for (;;)
711  {
712  bool anyone_alive = false;
713  int nfinished = 0;
714  int i;
715 
716  /*
717  * This will process any parallel messages that are pending, which may
718  * change the outcome of the loop that follows. It may also throw an
719  * error propagated from a worker.
720  */
722 
723  for (i = 0; i < pcxt->nworkers_launched; ++i)
724  {
725  /*
726  * If error_mqh is NULL, then the worker has already exited
727  * cleanly. If we have received a message through error_mqh from
728  * the worker, we know it started up cleanly, and therefore we're
729  * certain to be notified when it exits.
730  */
731  if (pcxt->worker[i].error_mqh == NULL)
732  ++nfinished;
733  else if (pcxt->known_attached_workers[i])
734  {
735  anyone_alive = true;
736  break;
737  }
738  }
739 
740  if (!anyone_alive)
741  {
742  /* If all workers are known to have finished, we're done. */
743  if (nfinished >= pcxt->nworkers_launched)
744  {
745  Assert(nfinished == pcxt->nworkers_launched);
746  break;
747  }
748 
749  /*
750  * We didn't detect any living workers, but not all workers are
751  * known to have exited cleanly. Either not all workers have
752  * launched yet, or maybe some of them failed to start or
753  * terminated abnormally.
754  */
755  for (i = 0; i < pcxt->nworkers_launched; ++i)
756  {
757  pid_t pid;
758  shm_mq *mq;
759 
760  /*
761  * If the worker is BGWH_NOT_YET_STARTED or BGWH_STARTED, we
762  * should just keep waiting. If it is BGWH_STOPPED, then
763  * further investigation is needed.
764  */
765  if (pcxt->worker[i].error_mqh == NULL ||
766  pcxt->worker[i].bgwhandle == NULL ||
768  &pid) != BGWH_STOPPED)
769  continue;
770 
771  /*
772  * Check whether the worker ended up stopped without ever
773  * attaching to the error queue. If so, the postmaster was
774  * unable to fork the worker or it exited without initializing
775  * properly. We must throw an error, since the caller may
776  * have been expecting the worker to do some work before
777  * exiting.
778  */
779  mq = shm_mq_get_queue(pcxt->worker[i].error_mqh);
780  if (shm_mq_get_sender(mq) == NULL)
781  ereport(ERROR,
782  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
783  errmsg("parallel worker failed to initialize"),
784  errhint("More details may be available in the server log.")));
785 
786  /*
787  * The worker is stopped, but is attached to the error queue.
788  * Unless there's a bug somewhere, this will only happen when
789  * the worker writes messages and terminates after the
790  * CHECK_FOR_INTERRUPTS() near the top of this function and
791  * before the call to GetBackgroundWorkerPid(). In that case,
792  * or latch should have been set as well and the right things
793  * will happen on the next pass through the loop.
794  */
795  }
796  }
797 
801  }
802 
803  if (pcxt->toc != NULL)
804  {
805  FixedParallelState *fps;
806 
807  fps = shm_toc_lookup(pcxt->toc, PARALLEL_KEY_FIXED, false);
808  if (fps->last_xlog_end > XactLastRecEnd)
810  }
811 }
int errhint(const char *fmt,...)
Definition: elog.c:987
XLogRecPtr XactLastRecEnd
Definition: xlog.c:339
PGPROC * shm_mq_get_sender(shm_mq *mq)
Definition: shm_mq.c:249
int errcode(int sqlerrcode)
Definition: elog.c:575
void ResetLatch(volatile Latch *latch)
Definition: latch.c:497
ParallelWorkerInfo * worker
Definition: parallel.h:45
int WaitLatch(volatile Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:336
#define ERROR
Definition: elog.h:43
#define PARALLEL_KEY_FIXED
Definition: parallel.c:62
shm_mq_handle * error_mqh
Definition: parallel.h:28
BackgroundWorkerHandle * bgwhandle
Definition: parallel.h:27
int nworkers_launched
Definition: parallel.h:37
XLogRecPtr last_xlog_end
Definition: parallel.c:94
#define ereport(elevel, rest)
Definition: elog.h:122
bool * known_attached_workers
Definition: parallel.h:47
#define Assert(condition)
Definition: c.h:699
shm_mq * shm_mq_get_queue(shm_mq_handle *mqh)
Definition: shm_mq.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
Definition: shm_mq.c:70
struct Latch * MyLatch
Definition: globals.c:55
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:98
#define WL_LATCH_SET
Definition: latch.h:124
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle, pid_t *pidp)
Definition: bgworker.c:1051
shm_toc * toc
Definition: parallel.h:44

Variable Documentation

◆ InitializingParallelWorker

PGDLLIMPORT bool InitializingParallelWorker

◆ ParallelMessagePending

volatile bool ParallelMessagePending

◆ ParallelWorkerNumber