1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-19 15:49:24 +03:00

Custom WAL Resource Managers.

Allow extensions to specify a new custom resource manager (rmgr),
which allows specialized WAL. This is meant to be used by a Table
Access Method or Index Access Method.

Prior to this commit, only Generic WAL was available, which offers
support for recovery and physical replication but not logical
replication.

Reviewed-by: Julien Rouhaud, Bharath Rupireddy, Andres Freund
Discussion: https://postgr.es/m/ed1fb2e22d15d3563ae0eb610f7b61bb15999c0a.camel%40j-davis.com
This commit is contained in:
Jeff Davis
2022-04-06 22:26:43 -07:00
parent a8cfb0c1a9
commit 5c279a6d35
24 changed files with 526 additions and 70 deletions

View File

@@ -30,6 +30,23 @@ typedef enum RmgrIds
#undef PG_RMGR
#define RM_MAX_ID (RM_NEXT_ID - 1)
#define RM_MAX_ID UINT8_MAX
#define RM_MAX_BUILTIN_ID (RM_NEXT_ID - 1)
#define RM_MIN_CUSTOM_ID 128
#define RM_MAX_CUSTOM_ID UINT8_MAX
#define RM_N_IDS (UINT8_MAX + 1)
#define RM_N_BUILTIN_IDS (RM_MAX_BUILTIN_ID + 1)
#define RM_N_CUSTOM_IDS (RM_MAX_CUSTOM_ID - RM_MIN_CUSTOM_ID + 1)
#define RMID_IS_BUILTIN(rmid) ((rmid) <= RM_MAX_BUILTIN_ID)
#define RMID_IS_CUSTOM(rmid) ((rmid) >= RM_MIN_CUSTOM_ID && \
(rmid) <= RM_MAX_CUSTOM_ID)
#define RMID_IS_VALID(rmid) (RMID_IS_BUILTIN((rmid)) || RMID_IS_CUSTOM((rmid)))
/*
* RmgrId to use for extensions that require an RmgrId, but are still in
* development and have not reserved their own unique RmgrId yet. See:
* https://wiki.postgresql.org/wiki/CustomWALResourceManagers
*/
#define RM_EXPERIMENTAL_ID 128
#endif /* RMGR_H */

View File

@@ -304,7 +304,8 @@ struct XLogRecordBuffer;
* rm_mask takes as input a page modified by the resource manager and masks
* out bits that shouldn't be flagged by wal_consistency_checking.
*
* RmgrTable[] is indexed by RmgrId values (see rmgrlist.h).
* RmgrTable[] is indexed by RmgrId values (see rmgrlist.h). If rm_name is
* NULL, the corresponding RmgrTable entry is considered invalid.
*/
typedef struct RmgrData
{
@@ -319,7 +320,25 @@ typedef struct RmgrData
struct XLogRecordBuffer *buf);
} RmgrData;
extern const RmgrData RmgrTable[];
extern RmgrData RmgrTable[];
extern void RmgrStartup(void);
extern void RmgrCleanup(void);
extern void RmgrNotFound(RmgrId rmid);
extern void RegisterCustomRmgr(RmgrId rmid, RmgrData *rmgr);
static inline bool
RmgrIdExists(RmgrId rmid)
{
return RmgrTable[rmid].rm_name != NULL;
}
static inline RmgrData
GetRmgr(RmgrId rmid)
{
if (unlikely(!RmgrIdExists(rmid)))
RmgrNotFound(rmid);
return RmgrTable[rmid];
}
/*
* Exported to support xlog switching from checkpointer