From bf18e7db0b78fe78cc58093bdc5cf55fc7f7bc96 Mon Sep 17 00:00:00 2001 From: Ahmet Gedemenli Date: Mon, 25 Oct 2021 15:30:03 +0300 Subject: [PATCH] Move auto converting notice to a separate func --- .../citus_add_local_table_to_metadata.c | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c index 0ba6d69f6..e5303b284 100644 --- a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c +++ b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c @@ -52,6 +52,7 @@ static void ErrorIfAddingPartitionTableToMetadata(Oid relationId); static void ErrorIfUnsupportedCreateCitusLocalTable(Relation relation); static void ErrorIfUnsupportedCitusLocalTableKind(Oid relationId); static void ErrorIfUnsupportedCitusLocalColumnDefinition(Relation relation); +static void NoticeIfAutoConvertingLocalTables(bool autoConverted); static CascadeOperationType GetCascadeTypeForCitusLocalTables(bool autoConverted); static List * GetShellTableDDLEventsForCitusLocalTable(Oid relationId); static uint64 ConvertLocalTableToShard(Oid relationId); @@ -179,22 +180,6 @@ remove_local_tables_from_metadata(PG_FUNCTION_ARGS) void CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys, bool autoConverted) { - if (autoConverted && ShouldEnableLocalReferenceForeignKeys()) - { - /* - * When foreign keys between reference tables and postgres tables are - * enabled, we automatically undistribute citus local tables that are - * not chained with any reference tables back to postgres tables. - * So give a warning to user for that. - */ - ereport(WARNING, (errmsg("local tables that are added to metadata but not " - "chained with reference tables via foreign keys might " - "be automatically converted back to postgres tables"), - errhint("Consider setting " - "citus.enable_local_reference_table_foreign_keys " - "to 'off' to disable this behavior"))); - } - /* * These checks should be done before acquiring any locks on relation. * This is because we don't allow creating citus local tables in worker @@ -255,6 +240,8 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys, bool autoConve */ relation_close(relation, NoLock); + NoticeIfAutoConvertingLocalTables(autoConverted); + if (TableHasExternalForeignKeys(relationId)) { if (!cascadeViaForeignKeys) @@ -570,6 +557,32 @@ ErrorIfUnsupportedCitusLocalColumnDefinition(Relation relation) } +/* + * NoticeIfAutoConvertingLocalTables logs a NOTICE message to inform the user that we are + * automatically adding local tables to metadata. The user should know that this table + * will be undistributed automatically, if it gets disconnected from reference table(s). + */ +static void +NoticeIfAutoConvertingLocalTables(bool autoConverted) +{ + if (autoConverted && ShouldEnableLocalReferenceForeignKeys()) + { + /* + * When foreign keys between reference tables and postgres tables are + * enabled, we automatically undistribute citus local tables that are + * not chained with any reference tables back to postgres tables. + * So give a warning to user for that. + */ + ereport(NOTICE, (errmsg("local tables that are added to metadata but not " + "chained with reference tables via foreign keys might " + "be automatically converted back to postgres tables"), + errhint("Consider setting " + "citus.enable_local_reference_table_foreign_keys " + "to 'off' to disable this behavior"))); + } +} + + /* * GetCascadeTypeForCitusLocalTables returns CASCADE_AUTO_ADD_LOCAL_TABLE_TO_METADATA * if autoConverted is true. Returns CASCADE_USER_ADD_LOCAL_TABLE_TO_METADATA otherwise.