Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shmem_request_hook #4411

Merged
merged 1 commit into from Jun 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/loader/loader.c
Expand Up @@ -114,6 +114,9 @@ int ts_guc_bgw_launcher_poll_time = BGW_LAUNCHER_POLL_TIME_MS;
/* This is the hook that existed before the loader was installed */
static post_parse_analyze_hook_type prev_post_parse_analyze_hook;
static shmem_startup_hook_type prev_shmem_startup_hook;
#if PG15_GE
static shmem_request_hook_type prev_shmem_request_hook;
#endif
static ProcessUtility_hook_type prev_ProcessUtility_hook;

/* This is timescaleDB's versioned-extension's post_parse_analyze_hook */
Expand Down Expand Up @@ -609,6 +612,25 @@ timescaledb_shmem_startup_hook(void)
ts_function_telemetry_shmem_startup();
}

/*
* PG15 requires all shared memory requests to be requested in a dedicated
* hook. We group all our shared memory requests in this function and use
* it as a normal function for PG < 14 and as a hook for PG 15+.
*/
static void
timescaledb_shmem_request_hook(void)
{
#if PG15_GE
if (prev_shmem_request_hook)
prev_shmem_request_hook();
#endif

ts_bgw_counter_shmem_alloc();
ts_bgw_message_queue_alloc();
ts_lwlocks_shmem_alloc();
ts_function_telemetry_shmem_alloc();
}

static void
extension_mark_loader_present()
{
Expand All @@ -628,14 +650,14 @@ _PG_init(void)

elog(INFO, "timescaledb loaded");

ts_bgw_counter_shmem_alloc();
ts_bgw_message_queue_alloc();
ts_lwlocks_shmem_alloc();
#if PG15_LT
timescaledb_shmem_request_hook();
#endif

ts_bgw_cluster_launcher_register();
ts_bgw_counter_setup_gucs();
ts_bgw_interface_register_api_version();
ts_seclabel_init();
ts_function_telemetry_shmem_alloc();

/* This is a safety-valve variable to prevent loading the full extension */
DefineCustomBoolVariable(GUC_DISABLE_LOAD_NAME,
Expand Down Expand Up @@ -676,6 +698,11 @@ _PG_init(void)
post_parse_analyze_hook = post_analyze_hook;
shmem_startup_hook = timescaledb_shmem_startup_hook;

#if PG15_GE
prev_shmem_request_hook = shmem_request_hook;
shmem_request_hook = timescaledb_shmem_request_hook;
#endif

/* register utility hook to handle a distributed database drop */
prev_ProcessUtility_hook = ProcessUtility_hook;
ProcessUtility_hook = loader_process_utility_hook;
Expand Down