From f372e93d225e6690f3b04a2c13e36bb0b5575dda Mon Sep 17 00:00:00 2001 From: aykut-bozkurt <51649454+aykut-bozkurt@users.noreply.github.com> Date: Mon, 1 Aug 2022 10:14:35 +0300 Subject: [PATCH] we supress notice log during looking up function oid to not break pg vanilla tests. (#6082) --- src/backend/distributed/commands/function.c | 13 ++++++++++- src/backend/distributed/shared_library_init.c | 15 ++++++++++++ .../distributed/utils/citus_depended_object.c | 23 +++++++++++++++++++ .../distributed/citus_depended_object.h | 2 ++ src/include/distributed/shared_library_init.h | 1 + 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/commands/function.c b/src/backend/distributed/commands/function.c index e02f68aa4..318f6242f 100644 --- a/src/backend/distributed/commands/function.c +++ b/src/backend/distributed/commands/function.c @@ -32,6 +32,7 @@ #include "catalog/pg_proc.h" #include "catalog/pg_type.h" #include "commands/extension.h" +#include "distributed/citus_depended_object.h" #include "distributed/citus_ruleutils.h" #include "distributed/citus_safe_lib.h" #include "distributed/colocation_utils.h" @@ -1438,7 +1439,17 @@ CreateFunctionStmtObjectAddress(Node *node, bool missing_ok) } } - return FunctionToObjectAddress(objectType, objectWithArgs, missing_ok); + int OldClientMinMessage = client_min_messages; + + /* suppress NOTICE if running under pg vanilla tests */ + SetLocalClientMinMessagesIfRunningPGTests(WARNING); + + List *funcAddresses = FunctionToObjectAddress(objectType, objectWithArgs, missing_ok); + + /* set it back */ + SetLocalClientMinMessagesIfRunningPGTests(OldClientMinMessage); + + return funcAddresses; } diff --git a/src/backend/distributed/shared_library_init.c b/src/backend/distributed/shared_library_init.c index 600b62b69..6a9d1fa51 100644 --- a/src/backend/distributed/shared_library_init.c +++ b/src/backend/distributed/shared_library_init.c @@ -595,6 +595,21 @@ StartupCitusBackend(void) } +/* + * GetCurrentClientMinMessageLevelName returns the name of the + * the GUC client_min_messages for its specified value. + */ +const char * +GetClientMinMessageLevelNameForValue(int minMessageLevel) +{ + struct config_enum record = { 0 }; + record.options = log_level_options; + const char *clientMinMessageLevelName = config_enum_lookup_by_value(&record, + minMessageLevel); + return clientMinMessageLevelName; +} + + /* * RegisterConnectionCleanup cleans up any resources left at the end of the * session. We prefer to cleanup before shared memory exit to make sure that diff --git a/src/backend/distributed/utils/citus_depended_object.c b/src/backend/distributed/utils/citus_depended_object.c index b844c3515..6424595bf 100644 --- a/src/backend/distributed/utils/citus_depended_object.c +++ b/src/backend/distributed/utils/citus_depended_object.c @@ -33,6 +33,8 @@ #include "distributed/citus_depended_object.h" #include "distributed/metadata_cache.h" #include "distributed/listutils.h" +#include "distributed/log_utils.h" +#include "distributed/shared_library_init.h" #include "nodes/makefuncs.h" #include "nodes/nodeFuncs.h" #include "nodes/parsenodes.h" @@ -76,6 +78,27 @@ SetLocalHideCitusDependentObjectsDisabledWhenAlreadyEnabled(void) } +/* + * SetLocalClientMinMessagesIfRunningPGTests sets client_min_message locally to the given value + * if EnableUnsupportedFeatureMessages is set to false. + */ +void +SetLocalClientMinMessagesIfRunningPGTests(int clientMinMessageLevel) +{ + if (EnableUnsupportedFeatureMessages) + { + return; + } + + const char *clientMinMessageLevelName = GetClientMinMessageLevelNameForValue( + clientMinMessageLevel); + + set_config_option("client_min_messages", clientMinMessageLevelName, + (superuser() ? PGC_SUSET : PGC_USERSET), PGC_S_SESSION, + GUC_ACTION_LOCAL, true, 0, false); +} + + /* * HideCitusDependentObjectsOnQueriesOfPgMetaTables adds a NOT is_citus_depended_object(oid, oid) expr * to the quals of meta class RTEs that we are interested in. diff --git a/src/include/distributed/citus_depended_object.h b/src/include/distributed/citus_depended_object.h index 61abfa68a..027186f4e 100644 --- a/src/include/distributed/citus_depended_object.h +++ b/src/include/distributed/citus_depended_object.h @@ -17,6 +17,8 @@ extern bool HideCitusDependentObjects; +extern void SetLocalClientMinMessagesIfRunningPGTests(int + clientMinMessageLevel); extern void SetLocalHideCitusDependentObjectsDisabledWhenAlreadyEnabled(void); extern bool HideCitusDependentObjectsOnQueriesOfPgMetaTables(Node *node, void *context); extern bool IsPgLocksTable(RangeTblEntry *rte); diff --git a/src/include/distributed/shared_library_init.h b/src/include/distributed/shared_library_init.h index 485ab553f..63a7147af 100644 --- a/src/include/distributed/shared_library_init.h +++ b/src/include/distributed/shared_library_init.h @@ -23,5 +23,6 @@ extern IsColumnarTableAmTable_type extern_IsColumnarTableAmTable; extern ReadColumnarOptions_type extern_ReadColumnarOptions; extern void StartupCitusBackend(void); +extern const char * GetClientMinMessageLevelNameForValue(int minMessageLevel); #endif /* SHARED_LIBRARY_INIT_H */