From 2f30be823ef8e78371fd38005450755d7ee8c82f Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Mon, 25 Jan 2021 19:11:49 +0300 Subject: [PATCH] Rename create_citus_local_table to citus_add_local_table_to_metadata For simplicity in downgrade test in multi_extension, didn't actually remove create_citus_local_table udf. --- ..._table_operation_for_connected_relations.c | 2 +- .../commands/create_citus_local_table.c | 41 +++++++++++++++---- .../distributed/commands/foreign_constraint.c | 2 +- .../distributed/commands/utility_hook.c | 2 +- .../distributed/sql/citus--9.5-1--10.0-1.sql | 1 + .../sql/downgrades/citus--10.0-1--9.5-1.sql | 1 + .../10.0-1.sql | 6 +++ .../latest.sql | 6 +++ src/include/distributed/commands.h | 2 +- src/test/regress/expected/multi_extension.out | 3 +- .../regress/expected/multi_extension_0.out | 3 +- .../expected/upgrade_list_citus_objects.out | 3 +- .../expected/upgrade_list_citus_objects_0.out | 3 +- 13 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 src/backend/distributed/sql/udfs/citus_add_local_table_to_metadata/10.0-1.sql create mode 100644 src/backend/distributed/sql/udfs/citus_add_local_table_to_metadata/latest.sql diff --git a/src/backend/distributed/commands/cascade_table_operation_for_connected_relations.c b/src/backend/distributed/commands/cascade_table_operation_for_connected_relations.c index d85fabbf3..73a365571 100644 --- a/src/backend/distributed/commands/cascade_table_operation_for_connected_relations.c +++ b/src/backend/distributed/commands/cascade_table_operation_for_connected_relations.c @@ -405,7 +405,7 @@ ExecuteCascadeOperationForRelationIdList(List *relationIdList, break; } - case CASCADE_FKEY_CREATE_CITUS_LOCAL_TABLE: + case CASCADE_FKEY_ADD_LOCAL_TABLE_TO_METADATA: { if (!IsCitusTable(relationId)) { diff --git a/src/backend/distributed/commands/create_citus_local_table.c b/src/backend/distributed/commands/create_citus_local_table.c index 4a005775d..06c7e4064 100644 --- a/src/backend/distributed/commands/create_citus_local_table.c +++ b/src/backend/distributed/commands/create_citus_local_table.c @@ -1,12 +1,17 @@ /*------------------------------------------------------------------------- * - * create_citus_local_table.c + * citus_add_local_table_to_metadata.c * - * This file contains functions to create citus local tables. + * This file contains functions to add local table to citus metadata. * - * A citus local table is composed of a shell relation to wrap the + * A local table added to metadata is composed of a shell relation to wrap the * the regular postgres relation as its coordinator local shard. * + * As we want to hide "citus local table" concept from users, we renamed + * udf and re-branded that concept as "local tables added to metadata". + * Note that we might still call this local table concept as "citus local" in + * many places of the code base. + * * Copyright (c) Citus Data, Inc. * *------------------------------------------------------------------------- @@ -70,17 +75,18 @@ static void InsertMetadataForCitusLocalTable(Oid citusLocalTableId, uint64 shard static void FinalizeCitusLocalTableCreation(Oid relationId); +PG_FUNCTION_INFO_V1(citus_add_local_table_to_metadata); PG_FUNCTION_INFO_V1(create_citus_local_table); PG_FUNCTION_INFO_V1(remove_local_tables_from_metadata); /* - * create_citus_local_table creates a citus local table from the table with + * citus_add_local_table_to_metadata creates a citus local table from the table with * relationId by executing the internal method CreateCitusLocalTable. * (See CreateCitusLocalTable function's comment.) */ Datum -create_citus_local_table(PG_FUNCTION_ARGS) +citus_add_local_table_to_metadata(PG_FUNCTION_ARGS) { CheckCitusVersion(ERROR); @@ -109,6 +115,23 @@ create_citus_local_table(PG_FUNCTION_ARGS) } +/* + * create_citus_local_table is a wrapper function for old name of + * of citus_add_local_table_to_metadata. + * + * The only reason for having this udf in citus binary is to make + * multi_extension test happy as it uses this udf when testing the + * downgrade scenario from 9.5 to 9.4. + */ +Datum +create_citus_local_table(PG_FUNCTION_ARGS) +{ + ereport(NOTICE, (errmsg("create_citus_local_table is deprecated in favour of " + "citus_add_local_table_to_metadata"))); + return citus_add_local_table_to_metadata(fcinfo); +} + + /* * remove_local_tables_from_metadata undistributes citus local * tables that are not chained with any reference tables via foreign keys. @@ -148,7 +171,7 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys) EnsureCoordinator(); EnsureTableOwner(relationId); - /* enable create_citus_local_table on an empty node */ + /* enable citus_add_local_table_to_metadata on an empty node */ InsertCoordinatorIfClusterEmpty(); /* @@ -189,7 +212,7 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys) * on the relations. */ CascadeOperationForConnectedRelations(relationId, lockMode, - CASCADE_FKEY_CREATE_CITUS_LOCAL_TABLE); + CASCADE_FKEY_ADD_LOCAL_TABLE_TO_METADATA); /* * We converted every foreign key connected table in our subgraph @@ -211,7 +234,7 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys) errhint("Use cascade_via_foreign_keys option to add " "all the relations involved in a foreign key " "relationship with %s to citus metadata by " - "executing SELECT create_citus_local_table($$%s$$, " + "executing SELECT citus_add_local_table_to_metadata($$%s$$, " "cascade_via_foreign_keys=>true)", qualifiedRelationName, qualifiedRelationName))); } @@ -296,7 +319,7 @@ ErrorIfUnsupportedCreateCitusLocalTable(Relation relation) * EnsureTableNotDistributed already errors out if the given relation implies * a citus table. However, as we don't mark the relation as citus table, i.e we * do not use the relation with relationId as the shell relation, parallel - * create_citus_local_table executions would not error out for that relation. + * citus_add_local_table_to_metadata executions would not error out for that relation. * Hence we need to error out for shard relations too. */ ErrorIfRelationIsAKnownShard(relationId); diff --git a/src/backend/distributed/commands/foreign_constraint.c b/src/backend/distributed/commands/foreign_constraint.c index 7a7eb099e..36300cbff 100644 --- a/src/backend/distributed/commands/foreign_constraint.c +++ b/src/backend/distributed/commands/foreign_constraint.c @@ -436,7 +436,7 @@ ErrorOutForFKeyBetweenPostgresAndCitusLocalTable(Oid localTableId) errmsg("cannot create foreign key constraint as \"%s\" is " "a postgres local table", localTableName), errhint("first add local table to citus metadata " - "by using SELECT create_citus_local_table('%s') " + "by using SELECT citus_add_local_table_to_metadata('%s') " "and execute the ALTER TABLE command to create the " "foreign key to local table", localTableName))); } diff --git a/src/backend/distributed/commands/utility_hook.c b/src/backend/distributed/commands/utility_hook.c index 77c225495..d24551005 100644 --- a/src/backend/distributed/commands/utility_hook.c +++ b/src/backend/distributed/commands/utility_hook.c @@ -789,7 +789,7 @@ ShouldUndistributeCitusLocalTables(void) { /* * If foreign keys between reference tables and local tables are - * disabled, then user might be using create_citus_local_table for + * disabled, then user might be using citus_add_local_table_to_metadata for * their own purposes. In that case, we should not undistribute * citus local tables. */ diff --git a/src/backend/distributed/sql/citus--9.5-1--10.0-1.sql b/src/backend/distributed/sql/citus--9.5-1--10.0-1.sql index c305fec8d..d45e3362e 100644 --- a/src/backend/distributed/sql/citus--9.5-1--10.0-1.sql +++ b/src/backend/distributed/sql/citus--9.5-1--10.0-1.sql @@ -10,6 +10,7 @@ DROP FUNCTION IF EXISTS pg_catalog.citus_total_relation_size(regclass); #include "udfs/alter_table_set_access_method/10.0-1.sql" #include "udfs/undistribute_table/10.0-1.sql" #include "udfs/create_citus_local_table/10.0-1.sql" +#include "udfs/citus_add_local_table_to_metadata/10.0-1.sql" #include "udfs/citus_set_coordinator_host/10.0-1.sql" #include "udfs/citus_add_node/10.0-1.sql" #include "udfs/citus_activate_node/10.0-1.sql" diff --git a/src/backend/distributed/sql/downgrades/citus--10.0-1--9.5-1.sql b/src/backend/distributed/sql/downgrades/citus--10.0-1--9.5-1.sql index d89a5668c..1824d2ad8 100644 --- a/src/backend/distributed/sql/downgrades/citus--10.0-1--9.5-1.sql +++ b/src/backend/distributed/sql/downgrades/citus--10.0-1--9.5-1.sql @@ -24,6 +24,7 @@ DROP FUNCTION pg_catalog.alter_table_set_access_method(regclass, text); DROP FUNCTION pg_catalog.citus_total_relation_size(regclass,boolean); DROP FUNCTION pg_catalog.undistribute_table(regclass,boolean); DROP FUNCTION pg_catalog.create_citus_local_table(regclass,boolean); +DROP FUNCTION pg_catalog.citus_add_local_table_to_metadata(regclass,boolean); DROP FUNCTION pg_catalog.citus_add_node(text, integer, integer, noderole, name); DROP FUNCTION pg_catalog.citus_activate_node(text, integer); DROP FUNCTION pg_catalog.citus_add_inactive_node(text, integer, integer, noderole, name); diff --git a/src/backend/distributed/sql/udfs/citus_add_local_table_to_metadata/10.0-1.sql b/src/backend/distributed/sql/udfs/citus_add_local_table_to_metadata/10.0-1.sql new file mode 100644 index 000000000..608883de2 --- /dev/null +++ b/src/backend/distributed/sql/udfs/citus_add_local_table_to_metadata/10.0-1.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE FUNCTION pg_catalog.citus_add_local_table_to_metadata(table_name regclass, cascade_via_foreign_keys boolean default false) + RETURNS void + LANGUAGE C STRICT + AS 'MODULE_PATHNAME', $$citus_add_local_table_to_metadata$$; +COMMENT ON FUNCTION pg_catalog.citus_add_local_table_to_metadata(table_name regclass, cascade_via_foreign_keys boolean) + IS 'create a citus local table'; diff --git a/src/backend/distributed/sql/udfs/citus_add_local_table_to_metadata/latest.sql b/src/backend/distributed/sql/udfs/citus_add_local_table_to_metadata/latest.sql new file mode 100644 index 000000000..608883de2 --- /dev/null +++ b/src/backend/distributed/sql/udfs/citus_add_local_table_to_metadata/latest.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE FUNCTION pg_catalog.citus_add_local_table_to_metadata(table_name regclass, cascade_via_foreign_keys boolean default false) + RETURNS void + LANGUAGE C STRICT + AS 'MODULE_PATHNAME', $$citus_add_local_table_to_metadata$$; +COMMENT ON FUNCTION pg_catalog.citus_add_local_table_to_metadata(table_name regclass, cascade_via_foreign_keys boolean) + IS 'create a citus local table'; diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index 087bc1950..06365adb6 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -476,7 +476,7 @@ typedef enum CascadeOperationType CASCADE_FKEY_UNDISTRIBUTE_TABLE = 1 << 1, /* execute CreateCitusLocalTable on each relation */ - CASCADE_FKEY_CREATE_CITUS_LOCAL_TABLE = 1 << 2, + CASCADE_FKEY_ADD_LOCAL_TABLE_TO_METADATA = 1 << 2, } CascadeOperationType; extern void CascadeOperationForConnectedRelations(Oid relationId, LOCKMODE relLockMode, diff --git a/src/test/regress/expected/multi_extension.out b/src/test/regress/expected/multi_extension.out index b2e4b220e..b18e96106 100644 --- a/src/test/regress/expected/multi_extension.out +++ b/src/test/regress/expected/multi_extension.out @@ -469,6 +469,7 @@ SELECT * FROM print_extension_changes(); | function alter_table_set_access_method(regclass,text) | function citus_activate_node(text,integer) | function citus_add_inactive_node(text,integer,integer,noderole,name) + | function citus_add_local_table_to_metadata(regclass,boolean) | function citus_add_node(text,integer,integer,noderole,name) | function citus_add_secondary_node(text,integer,text,integer,name) | function citus_conninfo_cache_invalidate() @@ -508,7 +509,7 @@ SELECT * FROM print_extension_changes(); | view citus_shards | view citus_tables | view time_partitions -(63 rows) +(64 rows) DROP TABLE prev_objects, extension_diff; -- show running version diff --git a/src/test/regress/expected/multi_extension_0.out b/src/test/regress/expected/multi_extension_0.out index 425c64e1c..5bedcac82 100644 --- a/src/test/regress/expected/multi_extension_0.out +++ b/src/test/regress/expected/multi_extension_0.out @@ -466,6 +466,7 @@ SELECT * FROM print_extension_changes(); | function alter_table_set_access_method(regclass,text) | function citus_activate_node(text,integer) | function citus_add_inactive_node(text,integer,integer,noderole,name) + | function citus_add_local_table_to_metadata(regclass,boolean) | function citus_add_node(text,integer,integer,noderole,name) | function citus_add_secondary_node(text,integer,text,integer,name) | function citus_conninfo_cache_invalidate() @@ -504,7 +505,7 @@ SELECT * FROM print_extension_changes(); | view citus_shards | view citus_tables | view time_partitions -(59 rows) +(60 rows) DROP TABLE prev_objects, extension_diff; -- show running version diff --git a/src/test/regress/expected/upgrade_list_citus_objects.out b/src/test/regress/expected/upgrade_list_citus_objects.out index a449097ad..64ca826cc 100644 --- a/src/test/regress/expected/upgrade_list_citus_objects.out +++ b/src/test/regress/expected/upgrade_list_citus_objects.out @@ -33,6 +33,7 @@ ORDER BY 1; function check_distributed_deadlocks() function citus_activate_node(text,integer) function citus_add_inactive_node(text,integer,integer,noderole,name) + function citus_add_local_table_to_metadata(regclass,boolean) function citus_add_node(text,integer,integer,noderole,name) function citus_add_rebalance_strategy(name,regproc,regproc,regproc,real,real) function citus_add_secondary_node(text,integer,text,integer,name) @@ -238,5 +239,5 @@ ORDER BY 1; view citus_worker_stat_activity view pg_dist_shard_placement view time_partitions -(222 rows) +(223 rows) diff --git a/src/test/regress/expected/upgrade_list_citus_objects_0.out b/src/test/regress/expected/upgrade_list_citus_objects_0.out index 76ddf36e0..8d450dfa1 100644 --- a/src/test/regress/expected/upgrade_list_citus_objects_0.out +++ b/src/test/regress/expected/upgrade_list_citus_objects_0.out @@ -30,6 +30,7 @@ ORDER BY 1; function check_distributed_deadlocks() function citus_activate_node(text,integer) function citus_add_inactive_node(text,integer,integer,noderole,name) + function citus_add_local_table_to_metadata(regclass,boolean) function citus_add_node(text,integer,integer,noderole,name) function citus_add_rebalance_strategy(name,regproc,regproc,regproc,real,real) function citus_add_secondary_node(text,integer,text,integer,name) @@ -234,5 +235,5 @@ ORDER BY 1; view citus_worker_stat_activity view pg_dist_shard_placement view time_partitions -(218 rows) +(219 rows)