PostgreSQL Source Code  git master
message.c File Reference
#include "postgres.h"
#include "access/xact.h"
#include "access/xloginsert.h"
#include "miscadmin.h"
#include "replication/message.h"
Include dependency graph for message.c:

Go to the source code of this file.

Functions

XLogRecPtr LogLogicalMessage (const char *prefix, const char *message, size_t size, bool transactional, bool flush)
 
void logicalmsg_redo (XLogReaderState *record)
 

Function Documentation

◆ logicalmsg_redo()

void logicalmsg_redo ( XLogReaderState record)

Definition at line 87 of file message.c.

88 {
89  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
90 
91  if (info != XLOG_LOGICAL_MESSAGE)
92  elog(PANIC, "logicalmsg_redo: unknown op code %u", info);
93 
94  /* This is only interesting for logical decoding, see decode.c. */
95 }
unsigned char uint8
Definition: c.h:504
#define PANIC
Definition: elog.h:42
#define elog(elevel,...)
Definition: elog.h:224
#define XLOG_LOGICAL_MESSAGE
Definition: message.h:37
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:410
#define XLR_INFO_MASK
Definition: xlogrecord.h:62

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,
bool  flush 
)

Definition at line 43 of file message.c.

45 {
46  xl_logical_message xlrec;
47  XLogRecPtr lsn;
48 
49  /*
50  * Force xid to be allocated if we're emitting a transactional message.
51  */
52  if (transactional)
53  {
56  }
57 
58  xlrec.dbId = MyDatabaseId;
59  xlrec.transactional = transactional;
60  /* trailing zero is critical; see logicalmsg_desc */
61  xlrec.prefix_size = strlen(prefix) + 1;
62  xlrec.message_size = size;
63 
65  XLogRegisterData((char *) &xlrec, SizeOfLogicalMessage);
66  XLogRegisterData(unconstify(char *, prefix), xlrec.prefix_size);
67  XLogRegisterData(unconstify(char *, message), size);
68 
69  /* allow origin filtering */
71 
72  lsn = XLogInsert(RM_LOGICALMSG_ID, XLOG_LOGICAL_MESSAGE);
73 
74  /*
75  * Make sure that the message hits disk before leaving if emitting a
76  * non-transactional message when flush is requested.
77  */
78  if (!transactional && flush)
79  XLogFlush(lsn);
80  return lsn;
81 }
#define unconstify(underlying_type, expr)
Definition: c.h:1245
#define Assert(condition)
Definition: c.h:858
Oid MyDatabaseId
Definition: globals.c:92
#define SizeOfLogicalMessage
Definition: message.h:30
static pg_noinline void Size size
Definition: slab.c:607
bool transactional
Definition: message.h:23
bool IsTransactionState(void)
Definition: xact.c:385
TransactionId GetCurrentTransactionId(void)
Definition: xact.c:452
void XLogFlush(XLogRecPtr record)
Definition: xlog.c:2791
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:152
uint64 XLogRecPtr
Definition: xlogdefs.h:21
void XLogRegisterData(char *data, uint32 len)
Definition: xloginsert.c:364
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:474
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:456
void XLogBeginInsert(void)
Definition: xloginsert.c:149

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

Referenced by pg_logical_emit_message_bytea().