mirror of
https://github.com/postgres/postgres.git
synced 2025-11-21 00:42:43 +03:00
Create an infrastructure for parallel computation in PostgreSQL.
This does four basic things. First, it provides convenience routines to coordinate the startup and shutdown of parallel workers. Second, it synchronizes various pieces of state (e.g. GUCs, combo CID mappings, transaction snapshot) from the parallel group leader to the worker processes. Third, it prohibits various operations that would result in unsafe changes to that state while parallelism is active. Finally, it propagates events that would result in an ErrorResponse, NoticeResponse, or NotifyResponse message being sent to the client from the parallel workers back to the master, from which they can then be sent on to the client. Robert Haas, Amit Kapila, Noah Misch, Rushabh Lathia, Jeevan Chalke. Suggestions and review from Andres Freund, Heikki Linnakangas, Noah Misch, Simon Riggs, Euler Taveira, and Jim Nasby.
This commit is contained in:
@@ -16,12 +16,15 @@
|
||||
#include "libpq/libpq.h"
|
||||
#include "libpq/pqformat.h"
|
||||
#include "libpq/pqmq.h"
|
||||
#include "miscadmin.h"
|
||||
#include "tcop/tcopprot.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
static shm_mq *pq_mq;
|
||||
static shm_mq_handle *pq_mq_handle;
|
||||
static bool pq_mq_busy = false;
|
||||
static pid_t pq_mq_parallel_master_pid = 0;
|
||||
static pid_t pq_mq_parallel_master_backend_id = InvalidBackendId;
|
||||
|
||||
static void mq_comm_reset(void);
|
||||
static int mq_flush(void);
|
||||
@@ -57,6 +60,18 @@ pq_redirect_to_shm_mq(shm_mq *mq, shm_mq_handle *mqh)
|
||||
FrontendProtocol = PG_PROTOCOL_LATEST;
|
||||
}
|
||||
|
||||
/*
|
||||
* Arrange to SendProcSignal() to the parallel master each time we transmit
|
||||
* message data via the shm_mq.
|
||||
*/
|
||||
void
|
||||
pq_set_parallel_master(pid_t pid, BackendId backend_id)
|
||||
{
|
||||
Assert(PqCommMethods == &PqCommMqMethods);
|
||||
pq_mq_parallel_master_pid = pid;
|
||||
pq_mq_parallel_master_backend_id = backend_id;
|
||||
}
|
||||
|
||||
static void
|
||||
mq_comm_reset(void)
|
||||
{
|
||||
@@ -120,7 +135,23 @@ mq_putmessage(char msgtype, const char *s, size_t len)
|
||||
iov[1].len = len;
|
||||
|
||||
Assert(pq_mq_handle != NULL);
|
||||
result = shm_mq_sendv(pq_mq_handle, iov, 2, false);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
result = shm_mq_sendv(pq_mq_handle, iov, 2, true);
|
||||
|
||||
if (pq_mq_parallel_master_pid != 0)
|
||||
SendProcSignal(pq_mq_parallel_master_pid,
|
||||
PROCSIG_PARALLEL_MESSAGE,
|
||||
pq_mq_parallel_master_backend_id);
|
||||
|
||||
if (result != SHM_MQ_WOULD_BLOCK)
|
||||
break;
|
||||
|
||||
WaitLatch(&MyProc->procLatch, WL_LATCH_SET, 0);
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
ResetLatch(&MyProc->procLatch);
|
||||
}
|
||||
|
||||
pq_mq_busy = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user