parallel.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*-------------------------------------------------------------------------
  2. *
  3. * parallel.h
  4. * Infrastructure for launching parallel workers
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/access/parallel.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef PARALLEL_H
  14. #define PARALLEL_H
  15. #include "access/xlogdefs.h"
  16. #include "lib/ilist.h"
  17. #include "postmaster/bgworker.h"
  18. #include "storage/shm_mq.h"
  19. #include "storage/shm_toc.h"
  20. typedef void (*parallel_worker_main_type) (dsm_segment *seg, shm_toc *toc);
  21. typedef struct ParallelWorkerInfo
  22. {
  23. BackgroundWorkerHandle *bgwhandle;
  24. shm_mq_handle *error_mqh;
  25. int32 pid;
  26. } ParallelWorkerInfo;
  27. typedef struct ParallelContext
  28. {
  29. dlist_node node;
  30. SubTransactionId subid;
  31. int nworkers; /* Maximum number of workers to launch */
  32. int nworkers_to_launch; /* Actual number of workers to launch */
  33. int nworkers_launched;
  34. char *library_name;
  35. char *function_name;
  36. ErrorContextCallback *error_context_stack;
  37. shm_toc_estimator estimator;
  38. dsm_segment *seg;
  39. void *private_memory;
  40. shm_toc *toc;
  41. ParallelWorkerInfo *worker;
  42. int nknown_attached_workers;
  43. bool *known_attached_workers;
  44. } ParallelContext;
  45. typedef struct ParallelWorkerContext
  46. {
  47. dsm_segment *seg;
  48. shm_toc *toc;
  49. } ParallelWorkerContext;
  50. extern PGDLLIMPORT volatile bool ParallelMessagePending;
  51. extern PGDLLIMPORT int ParallelWorkerNumber;
  52. extern PGDLLIMPORT bool InitializingParallelWorker;
  53. #define IsParallelWorker() (ParallelWorkerNumber >= 0)
  54. extern ParallelContext *CreateParallelContext(const char *library_name,
  55. const char *function_name, int nworkers);
  56. extern void InitializeParallelDSM(ParallelContext *pcxt);
  57. extern void ReinitializeParallelDSM(ParallelContext *pcxt);
  58. extern void ReinitializeParallelWorkers(ParallelContext *pcxt, int nworkers_to_launch);
  59. extern void LaunchParallelWorkers(ParallelContext *pcxt);
  60. extern void WaitForParallelWorkersToAttach(ParallelContext *pcxt);
  61. extern void WaitForParallelWorkersToFinish(ParallelContext *pcxt);
  62. extern void DestroyParallelContext(ParallelContext *pcxt);
  63. extern bool ParallelContextActive(void);
  64. extern void HandleParallelMessageInterrupt(void);
  65. extern void HandleParallelMessages(void);
  66. extern void AtEOXact_Parallel(bool isCommit);
  67. extern void AtEOSubXact_Parallel(bool isCommit, SubTransactionId mySubId);
  68. extern void ParallelWorkerReportLastRecEnd(XLogRecPtr last_xlog_end);
  69. extern void ParallelWorkerMain(Datum main_arg);
  70. #endif /* PARALLEL_H */