agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH v18 1/3] Introduce archive modules infrastructure. 5+ messages / 2 participants [nested] [flat]
* [PATCH v18 1/3] Introduce archive modules infrastructure. @ 2021-11-19 01:04 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Nathan Bossart @ 2021-11-19 01:04 UTC (permalink / raw) --- src/backend/access/transam/xlog.c | 2 +- src/backend/postmaster/pgarch.c | 111 ++++++++++++++++-- src/backend/postmaster/shell_archive.c | 24 +++- src/backend/utils/init/miscinit.c | 1 + src/backend/utils/misc/guc.c | 12 +- src/backend/utils/misc/postgresql.conf.sample | 3 + src/include/access/xlog.h | 1 - src/include/postmaster/pgarch.h | 38 +++++- 8 files changed, 177 insertions(+), 15 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index dfe2a0bcce..958220c495 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8831,7 +8831,7 @@ ShutdownXLOG(int code, Datum arg) * process one more time at the end of shutdown). The checkpoint * record will go to the next XLOG file and won't be archived (yet). */ - if (XLogArchivingActive() && XLogArchiveCommandSet()) + if (XLogArchivingActive()) RequestXLogSwitch(false); CreateCheckPoint(CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_IMMEDIATE); diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index 6e3fcedc97..dfca746337 100644 --- a/src/backend/postmaster/pgarch.c +++ b/src/backend/postmaster/pgarch.c @@ -89,6 +89,8 @@ typedef struct PgArchData slock_t arch_lck; } PgArchData; +char *XLogArchiveLibrary = ""; + /* ---------- * Local data @@ -96,6 +98,8 @@ typedef struct PgArchData */ static time_t last_sigterm_time = 0; static PgArchData *PgArch = NULL; +static ArchiveModuleCallbacks ArchiveContext; + /* * Stuff for tracking multiple files to archive from each scan of @@ -140,6 +144,8 @@ static void pgarch_archiveDone(char *xlog); static void pgarch_die(int code, Datum arg); static void HandlePgArchInterrupts(void); static int ready_file_comparator(Datum a, Datum b, void *arg); +static void LoadArchiveLibrary(void); +static void call_archive_module_shutdown_callback(int code, Datum arg); /* Report shared memory space needed by PgArchShmemInit */ Size @@ -244,7 +250,16 @@ PgArchiverMain(void) arch_files->arch_heap = binaryheap_allocate(NUM_FILES_PER_DIRECTORY_SCAN, ready_file_comparator, NULL); - pgarch_MainLoop(); + /* Load the archive_library. */ + LoadArchiveLibrary(); + + PG_ENSURE_ERROR_CLEANUP(call_archive_module_shutdown_callback, 0); + { + pgarch_MainLoop(); + } + PG_END_ENSURE_ERROR_CLEANUP(call_archive_module_shutdown_callback, 0); + + call_archive_module_shutdown_callback(0, 0); proc_exit(0); } @@ -407,11 +422,12 @@ pgarch_ArchiverCopyLoop(void) */ HandlePgArchInterrupts(); - /* can't do anything if no command ... */ - if (!XLogArchiveCommandSet()) + /* can't do anything if not configured ... */ + if (ArchiveContext.check_configured_cb != NULL && + !ArchiveContext.check_configured_cb()) { ereport(WARNING, - (errmsg("archive_mode enabled, yet archive_command is not set"))); + (errmsg("archive_mode enabled, yet archiving is not configured"))); return; } @@ -492,7 +508,7 @@ pgarch_ArchiverCopyLoop(void) /* * pgarch_archiveXlog * - * Invokes system(3) to copy one archive file to wherever it should go + * Invokes archive_file_cb to copy one archive file to wherever it should go * * Returns true if successful */ @@ -509,7 +525,7 @@ pgarch_archiveXlog(char *xlog) snprintf(activitymsg, sizeof(activitymsg), "archiving %s", xlog); set_ps_display(activitymsg); - ret = shell_archive_file(xlog, pathname); + ret = ArchiveContext.archive_file_cb(xlog, pathname); if (ret) snprintf(activitymsg, sizeof(activitymsg), "last was %s", xlog); else @@ -759,13 +775,90 @@ HandlePgArchInterrupts(void) if (ProcSignalBarrierPending) ProcessProcSignalBarrier(); + /* Perform logging of memory contexts of this process */ + if (LogMemoryContextPending) + ProcessLogMemoryContextInterrupt(); + if (ConfigReloadPending) { + char *archiveLib = pstrdup(XLogArchiveLibrary); + bool archiveLibChanged; + ConfigReloadPending = false; ProcessConfigFile(PGC_SIGHUP); + + archiveLibChanged = strcmp(XLogArchiveLibrary, archiveLib) != 0; + pfree(archiveLib); + + if (archiveLibChanged) + { + /* + * Call the currently loaded archive module's shutdown callback, if + * one is defined. + */ + call_archive_module_shutdown_callback(0, 0); + + /* + * Ideally, we would simply unload the previous archive module and + * load the new one, but there is presently no mechanism for + * unloading a library (see the comment above + * internal_unload_library()). To deal with this, we simply restart + * the archiver. The new archive module will be loaded when the new + * archiver process starts up. + */ + ereport(LOG, + (errmsg("restarting archiver process because value of " + "\"archive_library\" was changed"))); + + proc_exit(0); + } } +} - /* Perform logging of memory contexts of this process */ - if (LogMemoryContextPending) - ProcessLogMemoryContextInterrupt(); +/* + * LoadArchiveLibrary + * + * Loads the archiving callbacks into our local ArchiveContext. + */ +static void +LoadArchiveLibrary(void) +{ + ArchiveModuleInit archive_init; + + memset(&ArchiveContext, 0, sizeof(ArchiveModuleCallbacks)); + + /* + * If shell archiving is enabled, use our special initialization + * function. Otherwise, load the library and call its + * _PG_archive_module_init(). + */ + if (XLogArchiveLibrary[0] == '\0') + archive_init = shell_archive_init; + else + archive_init = (ArchiveModuleInit) + load_external_function(XLogArchiveLibrary, + "_PG_archive_module_init", false, NULL); + + if (archive_init == NULL) + ereport(ERROR, + (errmsg("archive modules have to declare the " + "_PG_archive_module_init symbol"))); + + (*archive_init) (&ArchiveContext); + + if (ArchiveContext.archive_file_cb == NULL) + ereport(ERROR, + (errmsg("archive modules must register an archive callback"))); +} + +/* + * call_archive_module_shutdown_callback + * + * Calls the loaded archive module's shutdown callback, if one is defined. + */ +static void +call_archive_module_shutdown_callback(int code, Datum arg) +{ + if (ArchiveContext.shutdown_cb != NULL) + ArchiveContext.shutdown_cb(); } diff --git a/src/backend/postmaster/shell_archive.c b/src/backend/postmaster/shell_archive.c index b54e701da4..19e240c205 100644 --- a/src/backend/postmaster/shell_archive.c +++ b/src/backend/postmaster/shell_archive.c @@ -2,6 +2,10 @@ * * shell_archive.c * + * This archiving function uses a user-specified shell command (the + * archive_command GUC) to copy write-ahead log files. It is used as the + * default, but other modules may define their own custom archiving logic. + * * Copyright (c) 2022, PostgreSQL Global Development Group * * IDENTIFICATION @@ -17,7 +21,25 @@ #include "pgstat.h" #include "postmaster/pgarch.h" -bool +static bool shell_archive_configured(void); +static bool shell_archive_file(const char *file, const char *path); + +void +shell_archive_init(ArchiveModuleCallbacks *cb) +{ + AssertVariableIsOfType(&shell_archive_init, ArchiveModuleInit); + + cb->check_configured_cb = shell_archive_configured; + cb->archive_file_cb = shell_archive_file; +} + +static bool +shell_archive_configured(void) +{ + return XLogArchiveCommand[0] != '\0'; +} + +static bool shell_archive_file(const char *file, const char *path) { char xlogarchcmd[MAXPGPATH]; diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 0f2570d626..0868e5a24f 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -38,6 +38,7 @@ #include "pgstat.h" #include "postmaster/autovacuum.h" #include "postmaster/interrupt.h" +#include "postmaster/pgarch.h" #include "postmaster/postmaster.h" #include "storage/fd.h" #include "storage/ipc.h" diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index b3fd42e0f1..f505413a7f 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -3881,13 +3881,23 @@ static struct config_string ConfigureNamesString[] = { {"archive_command", PGC_SIGHUP, WAL_ARCHIVING, gettext_noop("Sets the shell command that will be called to archive a WAL file."), - NULL + gettext_noop("This is used only if \"archive_library\" is not set.") }, &XLogArchiveCommand, "", NULL, NULL, show_archive_command }, + { + {"archive_library", PGC_SIGHUP, WAL_ARCHIVING, + gettext_noop("Sets the library that will be called to archive a WAL file."), + gettext_noop("An empty string indicates that \"archive_command\" should be used.") + }, + &XLogArchiveLibrary, + "", + NULL, NULL, NULL + }, + { {"restore_command", PGC_SIGHUP, WAL_ARCHIVE_RECOVERY, gettext_noop("Sets the shell command that will be called to retrieve an archived WAL file."), diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 817d5f5324..56d0bee6d9 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -245,6 +245,9 @@ #archive_mode = off # enables archiving; off, on, or always # (change requires restart) +#archive_library = '' # library to use to archive a logfile segment + # (empty string indicates archive_command should + # be used) #archive_command = '' # command to use to archive a logfile segment # placeholders: %p = path of file to archive # %f = file name only diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index 5f934dd65a..a4b1c1286f 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -154,7 +154,6 @@ extern PGDLLIMPORT int wal_level; /* Is WAL archiving enabled always (even during recovery)? */ #define XLogArchivingAlways() \ (AssertMacro(XLogArchiveMode == ARCHIVE_MODE_OFF || wal_level >= WAL_LEVEL_REPLICA), XLogArchiveMode == ARCHIVE_MODE_ALWAYS) -#define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0') /* * Is WAL-logging necessary for archival or log-shipping, or can we skip diff --git a/src/include/postmaster/pgarch.h b/src/include/postmaster/pgarch.h index 991a6d0616..9bc7593a2d 100644 --- a/src/include/postmaster/pgarch.h +++ b/src/include/postmaster/pgarch.h @@ -33,7 +33,41 @@ extern void PgArchiverMain(void) pg_attribute_noreturn(); extern void PgArchWakeup(void); extern void PgArchForceDirScan(void); -/* in shell_archive.c */ -extern bool shell_archive_file(const char *file, const char *path); +/* + * The value of the archive_library GUC. + */ +extern char *XLogArchiveLibrary; + +/* + * Archive module callbacks + * + * These callback functions should be defined by archive libraries and returned + * via _PG_archive_module_init(). ArchiveFileCB is the only required callback. + * For more information about the purpose of each callback, refer to the + * archive modules documentation. + */ +typedef bool (*ArchiveCheckConfiguredCB) (void); +typedef bool (*ArchiveFileCB) (const char *file, const char *path); +typedef void (*ArchiveShutdownCB) (void); + +typedef struct ArchiveModuleCallbacks +{ + ArchiveCheckConfiguredCB check_configured_cb; + ArchiveFileCB archive_file_cb; + ArchiveShutdownCB shutdown_cb; +} ArchiveModuleCallbacks; + +/* + * Type of the shared library symbol _PG_archive_module_init that is looked + * up when loading an archive library. + */ +typedef void (*ArchiveModuleInit) (ArchiveModuleCallbacks *cb); + +/* + * Since the logic for archiving via a shell command is in the core server + * and does not need to be loaded via a shared library, it has a special + * initialization function. + */ +extern void shell_archive_init(ArchiveModuleCallbacks *cb); #endif /* _PGARCH_H */ -- 2.25.1 --6c2NcOVqGQ03X4Wi Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v18-0002-Add-test-archive-module.patch" ^ permalink raw reply [nested|flat] 5+ messages in thread
* [PATCH v1 1/2] Revert "Teach DSM registry to ERROR if attaching to an uninitialized entry." @ 2025-11-24 17:03 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Nathan Bossart @ 2025-11-24 17:03 UTC (permalink / raw) This reverts commit 1165a933aab1355757a43cfd9193b6cce06f573b. --- src/backend/storage/ipc/dsm_registry.c | 34 +++----------------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/src/backend/storage/ipc/dsm_registry.c b/src/backend/storage/ipc/dsm_registry.c index 7eba8a8cffb..a926b9c3f32 100644 --- a/src/backend/storage/ipc/dsm_registry.c +++ b/src/backend/storage/ipc/dsm_registry.c @@ -93,7 +93,6 @@ typedef struct DSMRegistryEntry { char name[NAMEDATALEN]; DSMREntryType type; - bool initialized; union { NamedDSMState dsm; @@ -217,7 +216,6 @@ GetNamedDSMSegment(const char *name, size_t size, dsm_segment *seg; entry->type = DSMR_ENTRY_TYPE_DSM; - entry->initialized = false; /* Initialize the segment. */ seg = dsm_create(size, 0); @@ -230,21 +228,13 @@ GetNamedDSMSegment(const char *name, size_t size, if (init_callback) (*init_callback) (ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSM) ereport(ERROR, - (errmsg("requested DSM segment \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSM segment \"%s\" failed initialization", - name))); + (errmsg("requested DSM segment does not match type of existing entry"))); else if (entry->dsm.size != size) ereport(ERROR, - (errmsg("requested DSM segment \"%s\" does not match size of existing entry", - name))); + (errmsg("requested DSM segment size does not match size of existing segment"))); else { NamedDSMState *state = &entry->dsm; @@ -307,7 +297,6 @@ GetNamedDSA(const char *name, bool *found) NamedDSAState *state = &entry->dsa; entry->type = DSMR_ENTRY_TYPE_DSA; - entry->initialized = false; /* Initialize the LWLock tranche for the DSA. */ state->tranche = LWLockNewTrancheId(name); @@ -319,17 +308,10 @@ GetNamedDSA(const char *name, bool *found) /* Store handle for other backends to use. */ state->handle = dsa_get_handle(ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSA) ereport(ERROR, - (errmsg("requested DSA \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSA \"%s\" failed initialization", - name))); + (errmsg("requested DSA does not match type of existing entry"))); else { NamedDSAState *state = &entry->dsa; @@ -390,7 +372,6 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) dsa_area *dsa; entry->type = DSMR_ENTRY_TYPE_DSH; - entry->initialized = false; /* Initialize the LWLock tranche for the hash table. */ dsh_state->tranche = LWLockNewTrancheId(name); @@ -408,17 +389,10 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) /* Store handles for other backends to use. */ dsh_state->dsa_handle = dsa_get_handle(dsa); dsh_state->dsh_handle = dshash_get_hash_table_handle(ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSH) ereport(ERROR, - (errmsg("requested DSHash \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSHash \"%s\" failed initialization", - name))); + (errmsg("requested DSHash does not match type of existing entry"))); else { NamedDSHState *dsh_state = &entry->dsh; -- 2.39.5 (Apple Git-154) --RrQwG/d5bOC9SOJ1 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0002-handle-ERRORs-in-DSM-registry-functions.patch ^ permalink raw reply [nested|flat] 5+ messages in thread
* [PATCH v2 1/2] Revert "Teach DSM registry to ERROR if attaching to an uninitialized entry." @ 2025-11-24 17:03 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Nathan Bossart @ 2025-11-24 17:03 UTC (permalink / raw) This reverts commit 1165a933aab1355757a43cfd9193b6cce06f573b. --- src/backend/storage/ipc/dsm_registry.c | 34 +++----------------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/src/backend/storage/ipc/dsm_registry.c b/src/backend/storage/ipc/dsm_registry.c index 7eba8a8cffb..a926b9c3f32 100644 --- a/src/backend/storage/ipc/dsm_registry.c +++ b/src/backend/storage/ipc/dsm_registry.c @@ -93,7 +93,6 @@ typedef struct DSMRegistryEntry { char name[NAMEDATALEN]; DSMREntryType type; - bool initialized; union { NamedDSMState dsm; @@ -217,7 +216,6 @@ GetNamedDSMSegment(const char *name, size_t size, dsm_segment *seg; entry->type = DSMR_ENTRY_TYPE_DSM; - entry->initialized = false; /* Initialize the segment. */ seg = dsm_create(size, 0); @@ -230,21 +228,13 @@ GetNamedDSMSegment(const char *name, size_t size, if (init_callback) (*init_callback) (ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSM) ereport(ERROR, - (errmsg("requested DSM segment \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSM segment \"%s\" failed initialization", - name))); + (errmsg("requested DSM segment does not match type of existing entry"))); else if (entry->dsm.size != size) ereport(ERROR, - (errmsg("requested DSM segment \"%s\" does not match size of existing entry", - name))); + (errmsg("requested DSM segment size does not match size of existing segment"))); else { NamedDSMState *state = &entry->dsm; @@ -307,7 +297,6 @@ GetNamedDSA(const char *name, bool *found) NamedDSAState *state = &entry->dsa; entry->type = DSMR_ENTRY_TYPE_DSA; - entry->initialized = false; /* Initialize the LWLock tranche for the DSA. */ state->tranche = LWLockNewTrancheId(name); @@ -319,17 +308,10 @@ GetNamedDSA(const char *name, bool *found) /* Store handle for other backends to use. */ state->handle = dsa_get_handle(ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSA) ereport(ERROR, - (errmsg("requested DSA \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSA \"%s\" failed initialization", - name))); + (errmsg("requested DSA does not match type of existing entry"))); else { NamedDSAState *state = &entry->dsa; @@ -390,7 +372,6 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) dsa_area *dsa; entry->type = DSMR_ENTRY_TYPE_DSH; - entry->initialized = false; /* Initialize the LWLock tranche for the hash table. */ dsh_state->tranche = LWLockNewTrancheId(name); @@ -408,17 +389,10 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) /* Store handles for other backends to use. */ dsh_state->dsa_handle = dsa_get_handle(dsa); dsh_state->dsh_handle = dshash_get_hash_table_handle(ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSH) ereport(ERROR, - (errmsg("requested DSHash \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSHash \"%s\" failed initialization", - name))); + (errmsg("requested DSHash does not match type of existing entry"))); else { NamedDSHState *dsh_state = &entry->dsh; -- 2.39.5 (Apple Git-154) --POf/bFZrFFck8lM9 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-handle-ERRORs-in-DSM-registry-functions.patch ^ permalink raw reply [nested|flat] 5+ messages in thread
* [PATCH v3 1/2] Revert "Teach DSM registry to ERROR if attaching to an uninitialized entry." @ 2025-11-24 17:03 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Nathan Bossart @ 2025-11-24 17:03 UTC (permalink / raw) This reverts commit 1165a933aab1355757a43cfd9193b6cce06f573b. --- src/backend/storage/ipc/dsm_registry.c | 34 +++----------------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/src/backend/storage/ipc/dsm_registry.c b/src/backend/storage/ipc/dsm_registry.c index 7eba8a8cffb..a926b9c3f32 100644 --- a/src/backend/storage/ipc/dsm_registry.c +++ b/src/backend/storage/ipc/dsm_registry.c @@ -93,7 +93,6 @@ typedef struct DSMRegistryEntry { char name[NAMEDATALEN]; DSMREntryType type; - bool initialized; union { NamedDSMState dsm; @@ -217,7 +216,6 @@ GetNamedDSMSegment(const char *name, size_t size, dsm_segment *seg; entry->type = DSMR_ENTRY_TYPE_DSM; - entry->initialized = false; /* Initialize the segment. */ seg = dsm_create(size, 0); @@ -230,21 +228,13 @@ GetNamedDSMSegment(const char *name, size_t size, if (init_callback) (*init_callback) (ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSM) ereport(ERROR, - (errmsg("requested DSM segment \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSM segment \"%s\" failed initialization", - name))); + (errmsg("requested DSM segment does not match type of existing entry"))); else if (entry->dsm.size != size) ereport(ERROR, - (errmsg("requested DSM segment \"%s\" does not match size of existing entry", - name))); + (errmsg("requested DSM segment size does not match size of existing segment"))); else { NamedDSMState *state = &entry->dsm; @@ -307,7 +297,6 @@ GetNamedDSA(const char *name, bool *found) NamedDSAState *state = &entry->dsa; entry->type = DSMR_ENTRY_TYPE_DSA; - entry->initialized = false; /* Initialize the LWLock tranche for the DSA. */ state->tranche = LWLockNewTrancheId(name); @@ -319,17 +308,10 @@ GetNamedDSA(const char *name, bool *found) /* Store handle for other backends to use. */ state->handle = dsa_get_handle(ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSA) ereport(ERROR, - (errmsg("requested DSA \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSA \"%s\" failed initialization", - name))); + (errmsg("requested DSA does not match type of existing entry"))); else { NamedDSAState *state = &entry->dsa; @@ -390,7 +372,6 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) dsa_area *dsa; entry->type = DSMR_ENTRY_TYPE_DSH; - entry->initialized = false; /* Initialize the LWLock tranche for the hash table. */ dsh_state->tranche = LWLockNewTrancheId(name); @@ -408,17 +389,10 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) /* Store handles for other backends to use. */ dsh_state->dsa_handle = dsa_get_handle(dsa); dsh_state->dsh_handle = dshash_get_hash_table_handle(ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSH) ereport(ERROR, - (errmsg("requested DSHash \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSHash \"%s\" failed initialization", - name))); + (errmsg("requested DSHash does not match type of existing entry"))); else { NamedDSHState *dsh_state = &entry->dsh; -- 2.39.5 (Apple Git-154) --c08aH/hgV4/mNMsI Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v3-0002-handle-ERRORs-in-DSM-registry-functions.patch ^ permalink raw reply [nested|flat] 5+ messages in thread
* [PATCH v4 1/2] Revert "Teach DSM registry to ERROR if attaching to an uninitialized entry." @ 2025-11-24 17:03 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Nathan Bossart @ 2025-11-24 17:03 UTC (permalink / raw) This reverts commit 1165a933aab1355757a43cfd9193b6cce06f573b. --- src/backend/storage/ipc/dsm_registry.c | 34 +++----------------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/src/backend/storage/ipc/dsm_registry.c b/src/backend/storage/ipc/dsm_registry.c index 7eba8a8cffb..a926b9c3f32 100644 --- a/src/backend/storage/ipc/dsm_registry.c +++ b/src/backend/storage/ipc/dsm_registry.c @@ -93,7 +93,6 @@ typedef struct DSMRegistryEntry { char name[NAMEDATALEN]; DSMREntryType type; - bool initialized; union { NamedDSMState dsm; @@ -217,7 +216,6 @@ GetNamedDSMSegment(const char *name, size_t size, dsm_segment *seg; entry->type = DSMR_ENTRY_TYPE_DSM; - entry->initialized = false; /* Initialize the segment. */ seg = dsm_create(size, 0); @@ -230,21 +228,13 @@ GetNamedDSMSegment(const char *name, size_t size, if (init_callback) (*init_callback) (ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSM) ereport(ERROR, - (errmsg("requested DSM segment \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSM segment \"%s\" failed initialization", - name))); + (errmsg("requested DSM segment does not match type of existing entry"))); else if (entry->dsm.size != size) ereport(ERROR, - (errmsg("requested DSM segment \"%s\" does not match size of existing entry", - name))); + (errmsg("requested DSM segment size does not match size of existing segment"))); else { NamedDSMState *state = &entry->dsm; @@ -307,7 +297,6 @@ GetNamedDSA(const char *name, bool *found) NamedDSAState *state = &entry->dsa; entry->type = DSMR_ENTRY_TYPE_DSA; - entry->initialized = false; /* Initialize the LWLock tranche for the DSA. */ state->tranche = LWLockNewTrancheId(name); @@ -319,17 +308,10 @@ GetNamedDSA(const char *name, bool *found) /* Store handle for other backends to use. */ state->handle = dsa_get_handle(ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSA) ereport(ERROR, - (errmsg("requested DSA \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSA \"%s\" failed initialization", - name))); + (errmsg("requested DSA does not match type of existing entry"))); else { NamedDSAState *state = &entry->dsa; @@ -390,7 +372,6 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) dsa_area *dsa; entry->type = DSMR_ENTRY_TYPE_DSH; - entry->initialized = false; /* Initialize the LWLock tranche for the hash table. */ dsh_state->tranche = LWLockNewTrancheId(name); @@ -408,17 +389,10 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) /* Store handles for other backends to use. */ dsh_state->dsa_handle = dsa_get_handle(dsa); dsh_state->dsh_handle = dshash_get_hash_table_handle(ret); - - entry->initialized = true; } else if (entry->type != DSMR_ENTRY_TYPE_DSH) ereport(ERROR, - (errmsg("requested DSHash \"%s\" does not match type of existing entry", - name))); - else if (!entry->initialized) - ereport(ERROR, - (errmsg("requested DSHash \"%s\" failed initialization", - name))); + (errmsg("requested DSHash does not match type of existing entry"))); else { NamedDSHState *dsh_state = &entry->dsh; -- 2.39.5 (Apple Git-154) --kUugHEtL9xji53W5 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v4-0002-handle-ERRORs-in-DSM-registry-functions.patch ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2025-11-24 17:03 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-11-19 01:04 [PATCH v18 1/3] Introduce archive modules infrastructure. Nathan Bossart <[email protected]> 2025-11-24 17:03 [PATCH v1 1/2] Revert "Teach DSM registry to ERROR if attaching to an uninitialized entry." Nathan Bossart <[email protected]> 2025-11-24 17:03 [PATCH v2 1/2] Revert "Teach DSM registry to ERROR if attaching to an uninitialized entry." Nathan Bossart <[email protected]> 2025-11-24 17:03 [PATCH v3 1/2] Revert "Teach DSM registry to ERROR if attaching to an uninitialized entry." Nathan Bossart <[email protected]> 2025-11-24 17:03 [PATCH v4 1/2] Revert "Teach DSM registry to ERROR if attaching to an uninitialized entry." Nathan Bossart <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox