PostgreSQL Source Code git master
pqmq.h File Reference
#include "lib/stringinfo.h"
#include "storage/shm_mq.h"
Include dependency graph for pqmq.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void pq_redirect_to_shm_mq (dsm_segment *seg, shm_mq_handle *mqh)
 
void pq_set_parallel_leader (pid_t pid, ProcNumber procNumber)
 
void pq_parse_errornotice (StringInfo msg, ErrorData *edata)
 

Function Documentation

◆ pq_parse_errornotice()

void pq_parse_errornotice ( StringInfo  msg,
ErrorData edata 
)

Definition at line 216 of file pqmq.c.

217{
218 /* Initialize edata with reasonable defaults. */
219 MemSet(edata, 0, sizeof(ErrorData));
220 edata->elevel = ERROR;
222
223 /* Loop over fields and extract each one. */
224 for (;;)
225 {
226 char code = pq_getmsgbyte(msg);
227 const char *value;
228
229 if (code == '\0')
230 {
231 pq_getmsgend(msg);
232 break;
233 }
235
236 switch (code)
237 {
238 case PG_DIAG_SEVERITY:
239 /* ignore, trusting we'll get a nonlocalized version */
240 break;
242 if (strcmp(value, "DEBUG") == 0)
243 {
244 /*
245 * We can't reconstruct the exact DEBUG level, but
246 * presumably it was >= client_min_messages, so select
247 * DEBUG1 to ensure we'll pass it on to the client.
248 */
249 edata->elevel = DEBUG1;
250 }
251 else if (strcmp(value, "LOG") == 0)
252 {
253 /*
254 * It can't be LOG_SERVER_ONLY, or the worker wouldn't
255 * have sent it to us; so LOG is the correct value.
256 */
257 edata->elevel = LOG;
258 }
259 else if (strcmp(value, "INFO") == 0)
260 edata->elevel = INFO;
261 else if (strcmp(value, "NOTICE") == 0)
262 edata->elevel = NOTICE;
263 else if (strcmp(value, "WARNING") == 0)
264 edata->elevel = WARNING;
265 else if (strcmp(value, "ERROR") == 0)
266 edata->elevel = ERROR;
267 else if (strcmp(value, "FATAL") == 0)
268 edata->elevel = FATAL;
269 else if (strcmp(value, "PANIC") == 0)
270 edata->elevel = PANIC;
271 else
272 elog(ERROR, "unrecognized error severity: \"%s\"", value);
273 break;
274 case PG_DIAG_SQLSTATE:
275 if (strlen(value) != 5)
276 elog(ERROR, "invalid SQLSTATE: \"%s\"", value);
277 edata->sqlerrcode = MAKE_SQLSTATE(value[0], value[1], value[2],
278 value[3], value[4]);
279 break;
281 edata->message = pstrdup(value);
282 break;
284 edata->detail = pstrdup(value);
285 break;
287 edata->hint = pstrdup(value);
288 break;
290 edata->cursorpos = pg_strtoint32(value);
291 break;
294 break;
296 edata->internalquery = pstrdup(value);
297 break;
298 case PG_DIAG_CONTEXT:
299 edata->context = pstrdup(value);
300 break;
302 edata->schema_name = pstrdup(value);
303 break;
305 edata->table_name = pstrdup(value);
306 break;
308 edata->column_name = pstrdup(value);
309 break;
311 edata->datatype_name = pstrdup(value);
312 break;
314 edata->constraint_name = pstrdup(value);
315 break;
317 edata->filename = pstrdup(value);
318 break;
320 edata->lineno = pg_strtoint32(value);
321 break;
323 edata->funcname = pstrdup(value);
324 break;
325 default:
326 elog(ERROR, "unrecognized error field code: %d", (int) code);
327 break;
328 }
329 }
330}
#define MemSet(start, val, len)
Definition: c.h:977
#define LOG
Definition: elog.h:31
#define FATAL
Definition: elog.h:41
#define WARNING
Definition: elog.h:36
#define PANIC
Definition: elog.h:42
#define DEBUG1
Definition: elog.h:30
#define ERROR
Definition: elog.h:39
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
Definition: elog.h:56
#define elog(elevel,...)
Definition: elog.h:225
#define NOTICE
Definition: elog.h:35
#define INFO
Definition: elog.h:34
static struct @162 value
char * pstrdup(const char *in)
Definition: mcxt.c:1696
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
int32 pg_strtoint32(const char *s)
Definition: numutils.c:383
#define PG_DIAG_INTERNAL_QUERY
Definition: postgres_ext.h:63
#define PG_DIAG_SCHEMA_NAME
Definition: postgres_ext.h:65
#define PG_DIAG_CONSTRAINT_NAME
Definition: postgres_ext.h:69
#define PG_DIAG_DATATYPE_NAME
Definition: postgres_ext.h:68
#define PG_DIAG_SOURCE_LINE
Definition: postgres_ext.h:71
#define PG_DIAG_STATEMENT_POSITION
Definition: postgres_ext.h:61
#define PG_DIAG_SOURCE_FILE
Definition: postgres_ext.h:70
#define PG_DIAG_MESSAGE_HINT
Definition: postgres_ext.h:60
#define PG_DIAG_SQLSTATE
Definition: postgres_ext.h:57
#define PG_DIAG_SEVERITY_NONLOCALIZED
Definition: postgres_ext.h:56
#define PG_DIAG_TABLE_NAME
Definition: postgres_ext.h:66
#define PG_DIAG_MESSAGE_PRIMARY
Definition: postgres_ext.h:58
#define PG_DIAG_COLUMN_NAME
Definition: postgres_ext.h:67
#define PG_DIAG_MESSAGE_DETAIL
Definition: postgres_ext.h:59
#define PG_DIAG_CONTEXT
Definition: postgres_ext.h:64
#define PG_DIAG_SEVERITY
Definition: postgres_ext.h:55
#define PG_DIAG_SOURCE_FUNCTION
Definition: postgres_ext.h:72
#define PG_DIAG_INTERNAL_POSITION
Definition: postgres_ext.h:62
void pq_getmsgend(StringInfo msg)
Definition: pqformat.c:635
int pq_getmsgbyte(StringInfo msg)
Definition: pqformat.c:399
const char * pq_getmsgrawstring(StringInfo msg)
Definition: pqformat.c:608
int internalpos
Definition: elog.h:453
char * schema_name
Definition: elog.h:447
char * context
Definition: elog.h:444
char * internalquery
Definition: elog.h:454
int sqlerrcode
Definition: elog.h:439
struct MemoryContextData * assoc_context
Definition: elog.h:458
const char * filename
Definition: elog.h:434
int elevel
Definition: elog.h:429
char * datatype_name
Definition: elog.h:450
char * detail
Definition: elog.h:441
const char * funcname
Definition: elog.h:436
char * table_name
Definition: elog.h:448
char * message
Definition: elog.h:440
int lineno
Definition: elog.h:435
char * hint
Definition: elog.h:443
char * constraint_name
Definition: elog.h:451
int cursorpos
Definition: elog.h:452
char * column_name
Definition: elog.h:449

References ErrorData::assoc_context, ErrorData::column_name, ErrorData::constraint_name, ErrorData::context, CurrentMemoryContext, ErrorData::cursorpos, ErrorData::datatype_name, DEBUG1, ErrorData::detail, ErrorData::elevel, elog, ERROR, FATAL, ErrorData::filename, ErrorData::funcname, ErrorData::hint, INFO, ErrorData::internalpos, ErrorData::internalquery, ErrorData::lineno, LOG, MAKE_SQLSTATE, MemSet, ErrorData::message, NOTICE, PANIC, PG_DIAG_COLUMN_NAME, PG_DIAG_CONSTRAINT_NAME, PG_DIAG_CONTEXT, PG_DIAG_DATATYPE_NAME, PG_DIAG_INTERNAL_POSITION, PG_DIAG_INTERNAL_QUERY, PG_DIAG_MESSAGE_DETAIL, PG_DIAG_MESSAGE_HINT, PG_DIAG_MESSAGE_PRIMARY, PG_DIAG_SCHEMA_NAME, PG_DIAG_SEVERITY, PG_DIAG_SEVERITY_NONLOCALIZED, PG_DIAG_SOURCE_FILE, PG_DIAG_SOURCE_FUNCTION, PG_DIAG_SOURCE_LINE, PG_DIAG_SQLSTATE, PG_DIAG_STATEMENT_POSITION, PG_DIAG_TABLE_NAME, pg_strtoint32(), pq_getmsgbyte(), pq_getmsgend(), pq_getmsgrawstring(), pstrdup(), ErrorData::schema_name, ErrorData::sqlerrcode, ErrorData::table_name, value, and WARNING.

Referenced by HandleParallelApplyMessage(), and HandleParallelMessage().

◆ pq_redirect_to_shm_mq()

void pq_redirect_to_shm_mq ( dsm_segment seg,
shm_mq_handle mqh 
)

Definition at line 53 of file pqmq.c.

54{
56 pq_mq_handle = mqh;
60}
@ DestRemote
Definition: dest.h:89
void on_dsm_detach(dsm_segment *seg, on_dsm_detach_callback function, Datum arg)
Definition: dsm.c:1132
ProtocolVersion FrontendProtocol
Definition: globals.c:29
CommandDest whereToSendOutput
Definition: postgres.c:90
uintptr_t Datum
Definition: postgres.h:69
const PQcommMethods * PqCommMethods
Definition: pqcomm.c:164
#define PG_PROTOCOL_LATEST
Definition: pqcomm.h:98
static void pq_cleanup_redirect_to_shm_mq(dsm_segment *seg, Datum arg)
Definition: pqmq.c:67
static const PQcommMethods PqCommMqMethods
Definition: pqmq.c:39
static shm_mq_handle * pq_mq_handle
Definition: pqmq.c:26

References DestRemote, FrontendProtocol, on_dsm_detach(), PG_PROTOCOL_LATEST, pq_cleanup_redirect_to_shm_mq(), pq_mq_handle, PqCommMethods, PqCommMqMethods, and whereToSendOutput.

Referenced by ParallelApplyWorkerMain(), and ParallelWorkerMain().

◆ pq_set_parallel_leader()

void pq_set_parallel_leader ( pid_t  pid,
ProcNumber  procNumber 
)

Definition at line 78 of file pqmq.c.

79{
83}
#define Assert(condition)
Definition: c.h:815
static ProcNumber pq_mq_parallel_leader_proc_number
Definition: pqmq.c:29
static pid_t pq_mq_parallel_leader_pid
Definition: pqmq.c:28

References Assert, pq_mq_parallel_leader_pid, pq_mq_parallel_leader_proc_number, PqCommMethods, and PqCommMqMethods.

Referenced by ParallelApplyWorkerMain(), and ParallelWorkerMain().