PostgreSQL Source Code  git master
test_custom_rmgrs.c File Reference
#include "postgres.h"
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "access/xloginsert.h"
#include "fmgr.h"
#include "utils/pg_lsn.h"
#include "varatt.h"
Include dependency graph for test_custom_rmgrs.c:

Go to the source code of this file.

Data Structures

struct  xl_testcustomrmgrs_message
 

Macros

#define SizeOfTestCustomRmgrsMessage   (offsetof(xl_testcustomrmgrs_message, message))
 
#define XLOG_TEST_CUSTOM_RMGRS_MESSAGE   0x00
 
#define RM_TESTCUSTOMRMGRS_ID   RM_EXPERIMENTAL_ID
 
#define TESTCUSTOMRMGRS_NAME   "test_custom_rmgrs"
 

Typedefs

typedef struct xl_testcustomrmgrs_message xl_testcustomrmgrs_message
 

Functions

void testcustomrmgrs_redo (XLogReaderState *record)
 
void testcustomrmgrs_desc (StringInfo buf, XLogReaderState *record)
 
const char * testcustomrmgrs_identify (uint8 info)
 
void _PG_init (void)
 
 PG_FUNCTION_INFO_V1 (test_custom_rmgrs_insert_wal_record)
 
Datum test_custom_rmgrs_insert_wal_record (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static const RmgrData testcustomrmgrs_rmgr
 

Macro Definition Documentation

◆ RM_TESTCUSTOMRMGRS_ID

#define RM_TESTCUSTOMRMGRS_ID   RM_EXPERIMENTAL_ID

Definition at line 47 of file test_custom_rmgrs.c.

◆ SizeOfTestCustomRmgrsMessage

#define SizeOfTestCustomRmgrsMessage   (offsetof(xl_testcustomrmgrs_message, message))

Definition at line 38 of file test_custom_rmgrs.c.

◆ TESTCUSTOMRMGRS_NAME

#define TESTCUSTOMRMGRS_NAME   "test_custom_rmgrs"

Definition at line 48 of file test_custom_rmgrs.c.

◆ XLOG_TEST_CUSTOM_RMGRS_MESSAGE

#define XLOG_TEST_CUSTOM_RMGRS_MESSAGE   0x00

Definition at line 39 of file test_custom_rmgrs.c.

Typedef Documentation

◆ xl_testcustomrmgrs_message

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 66 of file test_custom_rmgrs.c.

67 {
68  /*
69  * In order to create our own custom resource manager, we have to be
70  * loaded via shared_preload_libraries. Otherwise, registration will fail.
71  */
73 }
void RegisterCustomRmgr(RmgrId rmid, const RmgrData *rmgr)
Definition: rmgr.c:107
static const RmgrData testcustomrmgrs_rmgr
#define RM_TESTCUSTOMRMGRS_ID

References RegisterCustomRmgr(), RM_TESTCUSTOMRMGRS_ID, and testcustomrmgrs_rmgr.

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( test_custom_rmgrs_insert_wal_record  )

◆ test_custom_rmgrs_insert_wal_record()

Datum test_custom_rmgrs_insert_wal_record ( PG_FUNCTION_ARGS  )

Definition at line 120 of file test_custom_rmgrs.c.

121 {
122  text *arg = PG_GETARG_TEXT_PP(0);
123  char *payload = VARDATA_ANY(arg);
125  XLogRecPtr lsn;
127 
128  xlrec.message_size = len;
129 
130  XLogBeginInsert();
132  XLogRegisterData((char *) payload, len);
133 
134  /* Let's mark this record as unimportant, just in case. */
136 
138 
139  PG_RETURN_LSN(lsn);
140 }
size_t Size
Definition: c.h:605
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
void * arg
const void size_t len
#define PG_RETURN_LSN(x)
Definition: pg_lsn.h:34
Definition: c.h:687
#define XLOG_TEST_CUSTOM_RMGRS_MESSAGE
#define SizeOfTestCustomRmgrsMessage
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317
#define XLOG_MARK_UNIMPORTANT
Definition: xlog.h:153
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 arg, len, xl_testcustomrmgrs_message::message_size, PG_GETARG_TEXT_PP, PG_RETURN_LSN, RM_TESTCUSTOMRMGRS_ID, SizeOfTestCustomRmgrsMessage, VARDATA_ANY, VARSIZE_ANY_EXHDR, XLOG_MARK_UNIMPORTANT, XLOG_TEST_CUSTOM_RMGRS_MESSAGE, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), and XLogSetRecordFlags().

◆ testcustomrmgrs_desc()

void testcustomrmgrs_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 91 of file test_custom_rmgrs.c.

92 {
93  char *rec = XLogRecGetData(record);
94  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
95 
97  {
99 
100  appendStringInfo(buf, "payload (%zu bytes): ", xlrec->message_size);
102  }
103 }
unsigned char uint8
Definition: c.h:504
static char * buf
Definition: pg_test_fsync.c:73
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition: stringinfo.c:233
char message[FLEXIBLE_ARRAY_MEMBER]
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:410
#define XLogRecGetData(decoder)
Definition: xlogreader.h:415
#define XLR_INFO_MASK
Definition: xlogrecord.h:62

References appendBinaryStringInfo(), appendStringInfo(), buf, xl_testcustomrmgrs_message::message, xl_testcustomrmgrs_message::message_size, XLOG_TEST_CUSTOM_RMGRS_MESSAGE, XLogRecGetData, XLogRecGetInfo, and XLR_INFO_MASK.

◆ testcustomrmgrs_identify()

const char * testcustomrmgrs_identify ( uint8  info)

Definition at line 106 of file test_custom_rmgrs.c.

107 {
109  return "TEST_CUSTOM_RMGRS_MESSAGE";
110 
111  return NULL;
112 }

References XLOG_TEST_CUSTOM_RMGRS_MESSAGE, and XLR_INFO_MASK.

◆ testcustomrmgrs_redo()

void testcustomrmgrs_redo ( XLogReaderState record)

Definition at line 82 of file test_custom_rmgrs.c.

83 {
84  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
85 
87  elog(PANIC, "testcustomrmgrs_redo: unknown op code %u", info);
88 }
#define PANIC
Definition: elog.h:42
#define elog(elevel,...)
Definition: elog.h:224

References elog, PANIC, XLOG_TEST_CUSTOM_RMGRS_MESSAGE, XLogRecGetInfo, and XLR_INFO_MASK.

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 27 of file test_custom_rmgrs.c.

◆ testcustomrmgrs_rmgr

const RmgrData testcustomrmgrs_rmgr
static
Initial value:
= {
.rm_identify = testcustomrmgrs_identify
}
void testcustomrmgrs_desc(StringInfo buf, XLogReaderState *record)
const char * testcustomrmgrs_identify(uint8 info)
#define TESTCUSTOMRMGRS_NAME
void testcustomrmgrs_redo(XLogReaderState *record)

Definition at line 55 of file test_custom_rmgrs.c.

Referenced by _PG_init().