From 0b4ccd2fd0393ed43edf39f018b2dabd9ca2b001 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 10 Nov 2025 11:43:51 -0600 Subject: [PATCH v2 1/2] DSM registry: ERROR if entry was not initialized. --- src/backend/storage/ipc/dsm_registry.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/backend/storage/ipc/dsm_registry.c b/src/backend/storage/ipc/dsm_registry.c index a926b9c3f32..ec8b48ad9a0 100644 --- a/src/backend/storage/ipc/dsm_registry.c +++ b/src/backend/storage/ipc/dsm_registry.c @@ -93,6 +93,7 @@ typedef struct DSMRegistryEntry { char name[NAMEDATALEN]; DSMREntryType type; + bool initialized; union { NamedDSMState dsm; @@ -216,6 +217,7 @@ 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); @@ -228,7 +230,12 @@ GetNamedDSMSegment(const char *name, size_t size, if (init_callback) (*init_callback) (ret); + + entry->initialized = true; } + else if (!entry->initialized) + ereport(ERROR, + (errmsg("requested DSM segment failed initialization"))); else if (entry->type != DSMR_ENTRY_TYPE_DSM) ereport(ERROR, (errmsg("requested DSM segment does not match type of existing entry"))); @@ -297,6 +304,7 @@ 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); @@ -308,7 +316,12 @@ 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->initialized) + ereport(ERROR, + (errmsg("requested DSA failed initialization"))); else if (entry->type != DSMR_ENTRY_TYPE_DSA) ereport(ERROR, (errmsg("requested DSA does not match type of existing entry"))); @@ -372,6 +385,7 @@ 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); @@ -389,7 +403,12 @@ 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->initialized) + ereport(ERROR, + (errmsg("requested DSHash failed initialization"))); else if (entry->type != DSMR_ENTRY_TYPE_DSH) ereport(ERROR, (errmsg("requested DSHash does not match type of existing entry"))); -- 2.39.5 (Apple Git-154)