PostgreSQL Source Code  git master
message.h File Reference
#include "access/xlog.h"
#include "access/xlogdefs.h"
#include "access/xlogreader.h"
Include dependency graph for message.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  xl_logical_message
 

Macros

#define SizeOfLogicalMessage   (offsetof(xl_logical_message, message))
 
#define XLOG_LOGICAL_MESSAGE   0x00
 

Typedefs

typedef struct xl_logical_message xl_logical_message
 

Functions

XLogRecPtr LogLogicalMessage (const char *prefix, const char *message, size_t size, bool transactional)
 
void logicalmsg_redo (XLogReaderState *record)
 
void logicalmsg_desc (StringInfo buf, XLogReaderState *record)
 
const char * logicalmsg_identify (uint8 info)
 

Macro Definition Documentation

◆ SizeOfLogicalMessage

#define SizeOfLogicalMessage   (offsetof(xl_logical_message, message))

Definition at line 30 of file message.h.

◆ XLOG_LOGICAL_MESSAGE

#define XLOG_LOGICAL_MESSAGE   0x00

Definition at line 36 of file message.h.

Typedef Documentation

◆ xl_logical_message

Function Documentation

◆ logicalmsg_desc()

void logicalmsg_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 19 of file logicalmsgdesc.c.

20 {
21  char *rec = XLogRecGetData(record);
22  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
23 
24  if (info == XLOG_LOGICAL_MESSAGE)
25  {
26  xl_logical_message *xlrec = (xl_logical_message *) rec;
27  char *prefix = xlrec->message;
28  char *message = xlrec->message + xlrec->prefix_size;
29  char *sep = "";
30 
31  Assert(prefix[xlrec->prefix_size - 1] == '\0');
32 
33  appendStringInfo(buf, "%s, prefix \"%s\"; payload (%zu bytes): ",
34  xlrec->transactional ? "transactional" : "non-transactional",
35  prefix, xlrec->message_size);
36  /* Write message payload as a series of hex bytes */
37  for (int cnt = 0; cnt < xlrec->message_size; cnt++)
38  {
39  appendStringInfo(buf, "%s%02X", sep, (unsigned char) message[cnt]);
40  sep = " ";
41  }
42  }
43 }
unsigned char uint8
Definition: c.h:440
Assert(fmt[strlen(fmt) - 1] !='\n')
#define XLOG_LOGICAL_MESSAGE
Definition: message.h:36
static char * buf
Definition: pg_test_fsync.c:67
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
bool transactional
Definition: message.h:23
char message[FLEXIBLE_ARRAY_MEMBER]
Definition: message.h:27
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:411
#define XLogRecGetData(decoder)
Definition: xlogreader.h:416
#define XLR_INFO_MASK
Definition: xlogrecord.h:62

References appendStringInfo(), Assert(), buf, xl_logical_message::message, xl_logical_message::message_size, xl_logical_message::prefix_size, xl_logical_message::transactional, XLOG_LOGICAL_MESSAGE, XLogRecGetData, XLogRecGetInfo, and XLR_INFO_MASK.

◆ logicalmsg_identify()

const char* logicalmsg_identify ( uint8  info)

Definition at line 46 of file logicalmsgdesc.c.

47 {
48  if ((info & ~XLR_INFO_MASK) == XLOG_LOGICAL_MESSAGE)
49  return "MESSAGE";
50 
51  return NULL;
52 }

References XLOG_LOGICAL_MESSAGE, and XLR_INFO_MASK.

◆ logicalmsg_redo()

void logicalmsg_redo ( XLogReaderState record)

Definition at line 81 of file message.c.

82 {
83  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
84 
85  if (info != XLOG_LOGICAL_MESSAGE)
86  elog(PANIC, "logicalmsg_redo: unknown op code %u", info);
87 
88  /* This is only interesting for logical decoding, see decode.c. */
89 }
#define PANIC
Definition: elog.h:38

References elog(), PANIC, XLOG_LOGICAL_MESSAGE, XLogRecGetInfo, and XLR_INFO_MASK.

◆ LogLogicalMessage()

XLogRecPtr LogLogicalMessage ( const char *  prefix,
const char *  message,
size_t  size,
bool  transactional 
)

Definition at line 46 of file message.c.

48 {
49  xl_logical_message xlrec;
50 
51  /*
52  * Force xid to be allocated if we're emitting a transactional message.
53  */
54  if (transactional)
55  {
58  }
59 
60  xlrec.dbId = MyDatabaseId;
61  xlrec.transactional = transactional;
62  /* trailing zero is critical; see logicalmsg_desc */
63  xlrec.prefix_size = strlen(prefix) + 1;
64  xlrec.message_size = size;
65 
67  XLogRegisterData((char *) &xlrec, SizeOfLogicalMessage);
68  XLogRegisterData(unconstify(char *, prefix), xlrec.prefix_size);
69  XLogRegisterData(unconstify(char *, message), size);
70 
71  /* allow origin filtering */
73 
74  return XLogInsert(RM_LOGICALMSG_ID, XLOG_LOGICAL_MESSAGE);
75 }
#define unconstify(underlying_type, expr)
Definition: c.h:1181
Oid MyDatabaseId
Definition: globals.c:89
#define SizeOfLogicalMessage
Definition: message.h:30
bool IsTransactionState(void)
Definition: xact.c:377
TransactionId GetCurrentTransactionId(void)
Definition: xact.c:444
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:149
void XLogRegisterData(char *data, uint32 len)
Definition: xloginsert.c:351
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:451
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:433
void XLogBeginInsert(void)
Definition: xloginsert.c:150

References Assert(), xl_logical_message::dbId, GetCurrentTransactionId(), IsTransactionState(), xl_logical_message::message_size, MyDatabaseId, xl_logical_message::prefix_size, SizeOfLogicalMessage, xl_logical_message::transactional, unconstify, XLOG_INCLUDE_ORIGIN, XLOG_LOGICAL_MESSAGE, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), and XLogSetRecordFlags().

Referenced by pg_logical_emit_message_bytea().