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.
pull/4573/head
Onur Tirtir 2021-01-25 19:11:49 +03:00
parent cd6f381d3c
commit 2f30be823e
13 changed files with 58 additions and 17 deletions

View File

@ -405,7 +405,7 @@ ExecuteCascadeOperationForRelationIdList(List *relationIdList,
break; break;
} }
case CASCADE_FKEY_CREATE_CITUS_LOCAL_TABLE: case CASCADE_FKEY_ADD_LOCAL_TABLE_TO_METADATA:
{ {
if (!IsCitusTable(relationId)) if (!IsCitusTable(relationId))
{ {

View File

@ -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. * 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. * Copyright (c) Citus Data, Inc.
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
@ -70,17 +75,18 @@ static void InsertMetadataForCitusLocalTable(Oid citusLocalTableId, uint64 shard
static void FinalizeCitusLocalTableCreation(Oid relationId); 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(create_citus_local_table);
PG_FUNCTION_INFO_V1(remove_local_tables_from_metadata); 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. * relationId by executing the internal method CreateCitusLocalTable.
* (See CreateCitusLocalTable function's comment.) * (See CreateCitusLocalTable function's comment.)
*/ */
Datum Datum
create_citus_local_table(PG_FUNCTION_ARGS) citus_add_local_table_to_metadata(PG_FUNCTION_ARGS)
{ {
CheckCitusVersion(ERROR); 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 * remove_local_tables_from_metadata undistributes citus local
* tables that are not chained with any reference tables via foreign keys. * tables that are not chained with any reference tables via foreign keys.
@ -148,7 +171,7 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys)
EnsureCoordinator(); EnsureCoordinator();
EnsureTableOwner(relationId); EnsureTableOwner(relationId);
/* enable create_citus_local_table on an empty node */ /* enable citus_add_local_table_to_metadata on an empty node */
InsertCoordinatorIfClusterEmpty(); InsertCoordinatorIfClusterEmpty();
/* /*
@ -189,7 +212,7 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys)
* on the relations. * on the relations.
*/ */
CascadeOperationForConnectedRelations(relationId, lockMode, 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 * 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 " errhint("Use cascade_via_foreign_keys option to add "
"all the relations involved in a foreign key " "all the relations involved in a foreign key "
"relationship with %s to citus metadata by " "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)", "cascade_via_foreign_keys=>true)",
qualifiedRelationName, qualifiedRelationName))); qualifiedRelationName, qualifiedRelationName)));
} }
@ -296,7 +319,7 @@ ErrorIfUnsupportedCreateCitusLocalTable(Relation relation)
* EnsureTableNotDistributed already errors out if the given relation implies * 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 * 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 * 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. * Hence we need to error out for shard relations too.
*/ */
ErrorIfRelationIsAKnownShard(relationId); ErrorIfRelationIsAKnownShard(relationId);

View File

@ -436,7 +436,7 @@ ErrorOutForFKeyBetweenPostgresAndCitusLocalTable(Oid localTableId)
errmsg("cannot create foreign key constraint as \"%s\" is " errmsg("cannot create foreign key constraint as \"%s\" is "
"a postgres local table", localTableName), "a postgres local table", localTableName),
errhint("first add local table to citus metadata " 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 " "and execute the ALTER TABLE command to create the "
"foreign key to local table", localTableName))); "foreign key to local table", localTableName)));
} }

View File

@ -789,7 +789,7 @@ ShouldUndistributeCitusLocalTables(void)
{ {
/* /*
* If foreign keys between reference tables and local tables are * 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 * their own purposes. In that case, we should not undistribute
* citus local tables. * citus local tables.
*/ */

View File

@ -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/alter_table_set_access_method/10.0-1.sql"
#include "udfs/undistribute_table/10.0-1.sql" #include "udfs/undistribute_table/10.0-1.sql"
#include "udfs/create_citus_local_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_set_coordinator_host/10.0-1.sql"
#include "udfs/citus_add_node/10.0-1.sql" #include "udfs/citus_add_node/10.0-1.sql"
#include "udfs/citus_activate_node/10.0-1.sql" #include "udfs/citus_activate_node/10.0-1.sql"

View File

@ -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.citus_total_relation_size(regclass,boolean);
DROP FUNCTION pg_catalog.undistribute_table(regclass,boolean); DROP FUNCTION pg_catalog.undistribute_table(regclass,boolean);
DROP FUNCTION pg_catalog.create_citus_local_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_add_node(text, integer, integer, noderole, name);
DROP FUNCTION pg_catalog.citus_activate_node(text, integer); DROP FUNCTION pg_catalog.citus_activate_node(text, integer);
DROP FUNCTION pg_catalog.citus_add_inactive_node(text, integer, integer, noderole, name); DROP FUNCTION pg_catalog.citus_add_inactive_node(text, integer, integer, noderole, name);

View File

@ -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';

View File

@ -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';

View File

@ -476,7 +476,7 @@ typedef enum CascadeOperationType
CASCADE_FKEY_UNDISTRIBUTE_TABLE = 1 << 1, CASCADE_FKEY_UNDISTRIBUTE_TABLE = 1 << 1,
/* execute CreateCitusLocalTable on each relation */ /* execute CreateCitusLocalTable on each relation */
CASCADE_FKEY_CREATE_CITUS_LOCAL_TABLE = 1 << 2, CASCADE_FKEY_ADD_LOCAL_TABLE_TO_METADATA = 1 << 2,
} CascadeOperationType; } CascadeOperationType;
extern void CascadeOperationForConnectedRelations(Oid relationId, LOCKMODE relLockMode, extern void CascadeOperationForConnectedRelations(Oid relationId, LOCKMODE relLockMode,

View File

@ -469,6 +469,7 @@ SELECT * FROM print_extension_changes();
| function alter_table_set_access_method(regclass,text) | function alter_table_set_access_method(regclass,text)
| function citus_activate_node(text,integer) | function citus_activate_node(text,integer)
| function citus_add_inactive_node(text,integer,integer,noderole,name) | 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_node(text,integer,integer,noderole,name)
| function citus_add_secondary_node(text,integer,text,integer,name) | function citus_add_secondary_node(text,integer,text,integer,name)
| function citus_conninfo_cache_invalidate() | function citus_conninfo_cache_invalidate()
@ -508,7 +509,7 @@ SELECT * FROM print_extension_changes();
| view citus_shards | view citus_shards
| view citus_tables | view citus_tables
| view time_partitions | view time_partitions
(63 rows) (64 rows)
DROP TABLE prev_objects, extension_diff; DROP TABLE prev_objects, extension_diff;
-- show running version -- show running version

View File

@ -466,6 +466,7 @@ SELECT * FROM print_extension_changes();
| function alter_table_set_access_method(regclass,text) | function alter_table_set_access_method(regclass,text)
| function citus_activate_node(text,integer) | function citus_activate_node(text,integer)
| function citus_add_inactive_node(text,integer,integer,noderole,name) | 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_node(text,integer,integer,noderole,name)
| function citus_add_secondary_node(text,integer,text,integer,name) | function citus_add_secondary_node(text,integer,text,integer,name)
| function citus_conninfo_cache_invalidate() | function citus_conninfo_cache_invalidate()
@ -504,7 +505,7 @@ SELECT * FROM print_extension_changes();
| view citus_shards | view citus_shards
| view citus_tables | view citus_tables
| view time_partitions | view time_partitions
(59 rows) (60 rows)
DROP TABLE prev_objects, extension_diff; DROP TABLE prev_objects, extension_diff;
-- show running version -- show running version

View File

@ -33,6 +33,7 @@ ORDER BY 1;
function check_distributed_deadlocks() function check_distributed_deadlocks()
function citus_activate_node(text,integer) function citus_activate_node(text,integer)
function citus_add_inactive_node(text,integer,integer,noderole,name) 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_node(text,integer,integer,noderole,name)
function citus_add_rebalance_strategy(name,regproc,regproc,regproc,real,real) function citus_add_rebalance_strategy(name,regproc,regproc,regproc,real,real)
function citus_add_secondary_node(text,integer,text,integer,name) function citus_add_secondary_node(text,integer,text,integer,name)
@ -238,5 +239,5 @@ ORDER BY 1;
view citus_worker_stat_activity view citus_worker_stat_activity
view pg_dist_shard_placement view pg_dist_shard_placement
view time_partitions view time_partitions
(222 rows) (223 rows)

View File

@ -30,6 +30,7 @@ ORDER BY 1;
function check_distributed_deadlocks() function check_distributed_deadlocks()
function citus_activate_node(text,integer) function citus_activate_node(text,integer)
function citus_add_inactive_node(text,integer,integer,noderole,name) 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_node(text,integer,integer,noderole,name)
function citus_add_rebalance_strategy(name,regproc,regproc,regproc,real,real) function citus_add_rebalance_strategy(name,regproc,regproc,regproc,real,real)
function citus_add_secondary_node(text,integer,text,integer,name) function citus_add_secondary_node(text,integer,text,integer,name)
@ -234,5 +235,5 @@ ORDER BY 1;
view citus_worker_stat_activity view citus_worker_stat_activity
view pg_dist_shard_placement view pg_dist_shard_placement
view time_partitions view time_partitions
(218 rows) (219 rows)