PostgreSQL Source Code  git master
rmgr.c File Reference
#include "postgres.h"
#include "access/brin_xlog.h"
#include "access/clog.h"
#include "access/commit_ts.h"
#include "access/generic_xlog.h"
#include "access/ginxlog.h"
#include "access/gistxlog.h"
#include "access/hash_xlog.h"
#include "access/heapam_xlog.h"
#include "access/multixact.h"
#include "access/nbtxlog.h"
#include "access/spgxlog.h"
#include "access/xact.h"
#include "access/xlog_internal.h"
#include "catalog/storage_xlog.h"
#include "commands/dbcommands_xlog.h"
#include "commands/sequence.h"
#include "commands/tablespace.h"
#include "fmgr.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "replication/decode.h"
#include "replication/message.h"
#include "replication/origin.h"
#include "storage/standby.h"
#include "utils/builtins.h"
#include "utils/relmapper.h"
#include "access/rmgrlist.h"
Include dependency graph for rmgr.c:

Go to the source code of this file.

Macros

#define PG_RMGR(symname, name, redo, desc, identify, startup, cleanup, mask, decode)    { name, redo, desc, identify, startup, cleanup, mask, decode },
 
#define PG_GET_RESOURCE_MANAGERS_COLS   3
 

Functions

void RmgrStartup (void)
 
void RmgrCleanup (void)
 
void RmgrNotFound (RmgrId rmid)
 
void RegisterCustomRmgr (RmgrId rmid, const RmgrData *rmgr)
 
Datum pg_get_wal_resource_managers (PG_FUNCTION_ARGS)
 

Variables

RmgrData RmgrTable [RM_MAX_ID+1]
 

Macro Definition Documentation

◆ PG_GET_RESOURCE_MANAGERS_COLS

#define PG_GET_RESOURCE_MANAGERS_COLS   3

◆ PG_RMGR

#define PG_RMGR (   symname,
  name,
  redo,
  desc,
  identify,
  startup,
  cleanup,
  mask,
  decode 
)     { name, redo, desc, identify, startup, cleanup, mask, decode },

Definition at line 38 of file rmgr.c.

Function Documentation

◆ pg_get_wal_resource_managers()

Datum pg_get_wal_resource_managers ( PG_FUNCTION_ARGS  )

Definition at line 141 of file rmgr.c.

142 {
143 #define PG_GET_RESOURCE_MANAGERS_COLS 3
144  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
146  bool nulls[PG_GET_RESOURCE_MANAGERS_COLS] = {0};
147 
148  InitMaterializedSRF(fcinfo, 0);
149 
150  for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
151  {
152  if (!RmgrIdExists(rmid))
153  continue;
154  values[0] = Int32GetDatum(rmid);
155  values[1] = CStringGetTextDatum(GetRmgr(rmid).rm_name);
156  values[2] = BoolGetDatum(RmgrIdIsBuiltin(rmid));
157  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
158  }
159 
160  return (Datum) 0;
161 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:94
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition: funcapi.c:76
uintptr_t Datum
Definition: postgres.h:64
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
#define PG_GET_RESOURCE_MANAGERS_COLS
#define RM_MAX_ID
Definition: rmgr.h:33
static bool RmgrIdIsBuiltin(int rmid)
Definition: rmgr.h:42
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
static RmgrData GetRmgr(RmgrId rmid)
static bool RmgrIdExists(RmgrId rmid)

References PG_GET_RESOURCE_MANAGERS_COLS, and values.

◆ RegisterCustomRmgr()

void RegisterCustomRmgr ( RmgrId  rmid,
const RmgrData rmgr 
)

Definition at line 98 of file rmgr.c.

99 {
100  if (rmgr->rm_name == NULL || strlen(rmgr->rm_name) == 0)
101  ereport(ERROR, (errmsg("custom resource manager name is invalid"),
102  errhint("Provide a non-empty name for the custom resource manager.")));
103 
104  if (!RmgrIdIsCustom(rmid))
105  ereport(ERROR, (errmsg("custom resource manager ID %d is out of range", rmid),
106  errhint("Provide a custom resource manager ID between %d and %d.",
108 
110  ereport(ERROR,
111  (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
112  errdetail("Custom resource manager must be registered while initializing modules in shared_preload_libraries.")));
113 
114  if (RmgrTable[rmid].rm_name != NULL)
115  ereport(ERROR,
116  (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
117  errdetail("Custom resource manager \"%s\" already registered with the same ID.",
118  RmgrTable[rmid].rm_name)));
119 
120  /* check for existing rmgr with the same name */
121  for (int existing_rmid = 0; existing_rmid <= RM_MAX_ID; existing_rmid++)
122  {
123  if (!RmgrIdExists(existing_rmid))
124  continue;
125 
126  if (!pg_strcasecmp(RmgrTable[existing_rmid].rm_name, rmgr->rm_name))
127  ereport(ERROR,
128  (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
129  errdetail("Existing resource manager with ID %d has the same name.", existing_rmid)));
130  }
131 
132  /* register it */
133  RmgrTable[rmid] = *rmgr;
134  ereport(LOG,
135  (errmsg("registered custom resource manager \"%s\" with ID %d",
136  rmgr->rm_name, rmid)));
137 }
int errdetail(const char *fmt,...)
Definition: elog.c:1202
int errhint(const char *fmt,...)
Definition: elog.c:1316
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define LOG
Definition: elog.h:31
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
bool process_shared_preload_libraries_in_progress
Definition: miscinit.c:1764
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
RmgrData RmgrTable[RM_MAX_ID+1]
Definition: rmgr.c:41
static bool RmgrIdIsCustom(int rmid)
Definition: rmgr.h:48
#define RM_MAX_CUSTOM_ID
Definition: rmgr.h:36
#define RM_MIN_CUSTOM_ID
Definition: rmgr.h:35
const char * rm_name

References ereport, errdetail(), errhint(), errmsg(), ERROR, LOG, pg_strcasecmp(), process_shared_preload_libraries_in_progress, RM_MAX_CUSTOM_ID, RM_MAX_ID, RM_MIN_CUSTOM_ID, RmgrData::rm_name, RmgrIdExists(), RmgrIdIsCustom(), and RmgrTable.

Referenced by _PG_init().

◆ RmgrCleanup()

void RmgrCleanup ( void  )

Definition at line 65 of file rmgr.c.

66 {
67  for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
68  {
69  if (!RmgrIdExists(rmid))
70  continue;
71 
72  if (RmgrTable[rmid].rm_cleanup != NULL)
73  RmgrTable[rmid].rm_cleanup();
74  }
75 }
void(* rm_cleanup)(void)

References RmgrData::rm_cleanup, RM_MAX_ID, RmgrIdExists(), and RmgrTable.

Referenced by PerformWalRecovery().

◆ RmgrNotFound()

void RmgrNotFound ( RmgrId  rmid)

Definition at line 82 of file rmgr.c.

83 {
84  ereport(ERROR, (errmsg("resource manager with ID %d not registered", rmid),
85  errhint("Include the extension module that implements this resource manager in shared_preload_libraries.")));
86 }

References ereport, errhint(), errmsg(), and ERROR.

Referenced by GetRmgr().

◆ RmgrStartup()

void RmgrStartup ( void  )

Definition at line 49 of file rmgr.c.

50 {
51  for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
52  {
53  if (!RmgrIdExists(rmid))
54  continue;
55 
56  if (RmgrTable[rmid].rm_startup != NULL)
57  RmgrTable[rmid].rm_startup();
58  }
59 }
void(* rm_startup)(void)

References RM_MAX_ID, RmgrData::rm_startup, RmgrIdExists(), and RmgrTable.

Referenced by PerformWalRecovery().

Variable Documentation

◆ RmgrTable

RmgrData RmgrTable[RM_MAX_ID+1]
Initial value:
= {
}

Definition at line 41 of file rmgr.c.

Referenced by GetRmgr(), RegisterCustomRmgr(), RmgrCleanup(), RmgrIdExists(), and RmgrStartup().