mirror of
https://github.com/postgres/postgres.git
synced 2025-10-22 14:32:25 +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:
@@ -245,6 +245,11 @@ static bool check_default_with_oids(bool *newval, void **extra, GucSource source
|
||||
static ConfigVariable *ProcessConfigFileInternal(GucContext context,
|
||||
bool applySettings, int elevel);
|
||||
|
||||
/*
|
||||
* Track whether there were any deferred checks for custom resource managers
|
||||
* specified in wal_consistency_checking.
|
||||
*/
|
||||
static bool check_wal_consistency_checking_deferred = false;
|
||||
|
||||
/*
|
||||
* Options for enum values defined in this module.
|
||||
@@ -5835,6 +5840,36 @@ InitializeGUCOptions(void)
|
||||
InitializeGUCOptionsFromEnvironment();
|
||||
}
|
||||
|
||||
/*
|
||||
* If any custom resource managers were specified in the
|
||||
* wal_consistency_checking GUC, processing was deferred. Now that
|
||||
* shared_preload_libraries have been loaded, process wal_consistency_checking
|
||||
* again.
|
||||
*/
|
||||
void
|
||||
InitializeWalConsistencyChecking(void)
|
||||
{
|
||||
Assert(process_shared_preload_libraries_done);
|
||||
|
||||
if (check_wal_consistency_checking_deferred)
|
||||
{
|
||||
struct config_generic *guc;
|
||||
|
||||
guc = find_option("wal_consistency_checking", false, false, ERROR);
|
||||
|
||||
check_wal_consistency_checking_deferred = false;
|
||||
|
||||
set_config_option("wal_consistency_checking",
|
||||
wal_consistency_checking_string,
|
||||
PGC_POSTMASTER, guc->source,
|
||||
GUC_ACTION_SET, true, ERROR, false);
|
||||
|
||||
/* checking should not be deferred again */
|
||||
Assert(!check_wal_consistency_checking_deferred);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Assign any GUC values that can come from the server's environment.
|
||||
*
|
||||
@@ -11882,13 +11917,13 @@ check_wal_consistency_checking(char **newval, void **extra, GucSource source)
|
||||
{
|
||||
char *tok = (char *) lfirst(l);
|
||||
bool found = false;
|
||||
RmgrId rmid;
|
||||
int rmid;
|
||||
|
||||
/* Check for 'all'. */
|
||||
if (pg_strcasecmp(tok, "all") == 0)
|
||||
{
|
||||
for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
|
||||
if (RmgrTable[rmid].rm_mask != NULL)
|
||||
if (RmgrIdExists(rmid) && GetRmgr(rmid).rm_mask != NULL)
|
||||
newwalconsistency[rmid] = true;
|
||||
found = true;
|
||||
}
|
||||
@@ -11900,8 +11935,8 @@ check_wal_consistency_checking(char **newval, void **extra, GucSource source)
|
||||
*/
|
||||
for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
|
||||
{
|
||||
if (pg_strcasecmp(tok, RmgrTable[rmid].rm_name) == 0 &&
|
||||
RmgrTable[rmid].rm_mask != NULL)
|
||||
if (RmgrIdExists(rmid) && GetRmgr(rmid).rm_mask != NULL &&
|
||||
pg_strcasecmp(tok, GetRmgr(rmid).rm_name) == 0)
|
||||
{
|
||||
newwalconsistency[rmid] = true;
|
||||
found = true;
|
||||
@@ -11912,10 +11947,21 @@ check_wal_consistency_checking(char **newval, void **extra, GucSource source)
|
||||
/* If a valid resource manager is found, check for the next one. */
|
||||
if (!found)
|
||||
{
|
||||
GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
|
||||
pfree(rawstring);
|
||||
list_free(elemlist);
|
||||
return false;
|
||||
/*
|
||||
* Perhaps it's a custom resource manager. If so, defer checking
|
||||
* until InitializeWalConsistencyChecking().
|
||||
*/
|
||||
if (!process_shared_preload_libraries_done)
|
||||
{
|
||||
check_wal_consistency_checking_deferred = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
|
||||
pfree(rawstring);
|
||||
list_free(elemlist);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11931,7 +11977,20 @@ check_wal_consistency_checking(char **newval, void **extra, GucSource source)
|
||||
static void
|
||||
assign_wal_consistency_checking(const char *newval, void *extra)
|
||||
{
|
||||
wal_consistency_checking = (bool *) extra;
|
||||
/*
|
||||
* If some checks were deferred, it's possible that the checks will fail
|
||||
* later during InitializeWalConsistencyChecking(). But in that case, the
|
||||
* postmaster will exit anyway, so it's safe to proceed with the
|
||||
* assignment.
|
||||
*
|
||||
* Any built-in resource managers specified are assigned immediately,
|
||||
* which affects WAL created before shared_preload_libraries are
|
||||
* processed. Any custom resource managers specified won't be assigned
|
||||
* until after shared_preload_libraries are processed, but that's OK
|
||||
* because WAL for a custom resource manager can't be written before the
|
||||
* module is loaded anyway.
|
||||
*/
|
||||
wal_consistency_checking = extra;
|
||||
}
|
||||
|
||||
static bool
|
||||
|
Reference in New Issue
Block a user