From d157496513b8cd441cd9e484ba65e6856c59aee9 Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Tue, 15 Mar 2022 16:48:49 -0700 Subject: [PATCH] add rendezvous variable --- src/backend/columnar/columnar_tableam.c | 9 ++++-- src/backend/distributed/shared_library_init.c | 29 ++++++++++++++----- src/include/columnar/columnar.h | 1 - 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/backend/columnar/columnar_tableam.c b/src/backend/columnar/columnar_tableam.c index 916962b4a..6d87a1855 100644 --- a/src/backend/columnar/columnar_tableam.c +++ b/src/backend/columnar/columnar_tableam.c @@ -103,8 +103,8 @@ typedef struct IndexFetchColumnarData MemoryContext scanContext; } IndexFetchColumnarData; - -ColumnarTableSetOptions_hook_type ColumnarTableSetOptions_hook = NULL; +/* available to other extensions using find_rendezvous_variable() */ +static ColumnarTableSetOptions_hook_type ColumnarTableSetOptions_hook = NULL; static object_access_hook_type PrevObjectAccessHook = NULL; static ProcessUtility_hook_type PrevProcessUtilityHook = NULL; @@ -1910,6 +1910,11 @@ ColumnarSubXactCallback(SubXactEvent event, SubTransactionId mySubid, void columnar_tableam_init() { + ColumnarTableSetOptions_hook_type **ColumnarTableSetOptions_hook_ptr = + (ColumnarTableSetOptions_hook_type **) find_rendezvous_variable( + "ColumnarTableSetOptions_hook"); + *ColumnarTableSetOptions_hook_ptr = &ColumnarTableSetOptions_hook; + RegisterXactCallback(ColumnarXactCallback, NULL); RegisterSubXactCallback(ColumnarSubXactCallback, NULL); diff --git a/src/backend/distributed/shared_library_init.c b/src/backend/distributed/shared_library_init.c index ee93b961d..35909dad9 100644 --- a/src/backend/distributed/shared_library_init.c +++ b/src/backend/distributed/shared_library_init.c @@ -323,12 +323,6 @@ _PG_init(void) original_client_auth_hook = ClientAuthentication_hook; ClientAuthentication_hook = CitusAuthHook; - /* - * When the options change on a columnar table, we may need to propagate - * the changes to shards. - */ - ColumnarTableSetOptions_hook = ColumnarTableSetOptionsHook; - InitializeMaintenanceDaemon(); /* initialize coordinated transaction management */ @@ -357,7 +351,28 @@ _PG_init(void) { DoInitialCleanup(); } - columnar_init(); + + /* + * For convenience and backwards compatibility, we avoid users + * having to add both citus and columnar to + * shared_preload_libraries by loading citus_columnar.so as + * part of loading citus.so. + */ + load_file(COLUMNAR_LIB_NAME, false); + + ColumnarTableSetOptions_hook_type **ColumnarTableSetOptions_hook_ptr = + (ColumnarTableSetOptions_hook_type **) find_rendezvous_variable( + "ColumnarTableSetOptions_hook"); + + /* rendezvous variable registered during columnar initialization */ + Assert(ColumnarTableSetOptions_hook_ptr != NULL); + Assert(*ColumnarTableSetOptions_hook_ptr != NULL); + + /* + * Set the hook, so that when the options change on a columnar + * table, we propagate the changes to shards. + */ + **ColumnarTableSetOptions_hook_ptr = ColumnarTableSetOptionsHook; } diff --git a/src/include/columnar/columnar.h b/src/include/columnar/columnar.h index 67a7b3966..f4fb993be 100644 --- a/src/include/columnar/columnar.h +++ b/src/include/columnar/columnar.h @@ -205,7 +205,6 @@ extern int columnar_compression_level; /* called when the user changes options on the given relation */ typedef void (*ColumnarTableSetOptions_hook_type)(Oid relid, ColumnarOptions options); -extern ColumnarTableSetOptions_hook_type ColumnarTableSetOptions_hook; extern void columnar_init(void); extern void columnar_init_gucs(void);