Skip to content

Commit

Permalink
Move more citus internal functions (#7473)
Browse files Browse the repository at this point in the history
Moves the following functions:

 citus_internal_delete_colocation_metadata 
 citus_internal_delete_partition_metadata 
 citus_internal_delete_placement_metadata 
 citus_internal_delete_shard_metadata 
 citus_internal_delete_tenant_schema
  • Loading branch information
eaydingol authored Jan 31, 2024
1 parent d051740 commit 594cb6f
Show file tree
Hide file tree
Showing 23 changed files with 174 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/backend/distributed/metadata/metadata_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ DistributionDeleteMetadataCommand(Oid relationId)
char *qualifiedRelationName = generate_qualified_relation_name(relationId);

appendStringInfo(deleteCommand,
"SELECT pg_catalog.citus_internal_delete_partition_metadata(%s)",
"SELECT citus_internal.delete_partition_metadata(%s)",
quote_literal_cstr(qualifiedRelationName));

return deleteCommand->data;
Expand Down Expand Up @@ -1354,7 +1354,7 @@ ShardDeleteCommandList(ShardInterval *shardInterval)

StringInfo deleteShardCommand = makeStringInfo();
appendStringInfo(deleteShardCommand,
"SELECT citus_internal_delete_shard_metadata(%ld);", shardId);
"SELECT citus_internal.delete_shard_metadata(%ld);", shardId);

return list_make1(deleteShardCommand->data);
}
Expand Down Expand Up @@ -4209,7 +4209,7 @@ ColocationGroupDeleteCommand(uint32 colocationId)
StringInfo deleteColocationCommand = makeStringInfo();

appendStringInfo(deleteColocationCommand,
"SELECT pg_catalog.citus_internal_delete_colocation_metadata(%d)",
"SELECT citus_internal.delete_colocation_metadata(%d)",
colocationId);

return deleteColocationCommand->data;
Expand Down Expand Up @@ -4241,7 +4241,7 @@ TenantSchemaDeleteCommand(char *schemaName)
{
StringInfo command = makeStringInfo();
appendStringInfo(command,
"SELECT pg_catalog.citus_internal_delete_tenant_schema(%s)",
"SELECT citus_internal.delete_tenant_schema(%s)",
RemoteSchemaIdExpressionByName(schemaName));

return command->data;
Expand Down Expand Up @@ -4291,7 +4291,7 @@ DeletePlacementMetadataCommand(uint64 placementId)
{
StringInfo command = makeStringInfo();
appendStringInfo(command,
"SELECT pg_catalog.citus_internal_delete_placement_metadata(%ld)",
"SELECT citus_internal.delete_placement_metadata(%ld)",
placementId);
return command->data;
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/distributed/operations/shard_split.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ DropShardListMetadata(List *shardIntervalList)
{
ListCell *commandCell = NULL;

/* send the commands one by one (calls citus_internal_delete_shard_metadata internally) */
/* send the commands one by one (calls citus_internal.delete_shard_metadata internally) */
List *shardMetadataDeleteCommandList = ShardDeleteCommandList(shardInterval);
foreach(commandCell, shardMetadataDeleteCommandList)
{
Expand Down
5 changes: 5 additions & 0 deletions src/backend/distributed/sql/citus--12.1-1--12.2-1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ REVOKE ALL ON FUNCTION citus_internal.start_management_transaction FROM PUBLIC;
#include "udfs/citus_internal_add_shard_metadata/12.2-1.sql"
#include "udfs/citus_internal_add_tenant_schema/12.2-1.sql"
#include "udfs/citus_internal_adjust_local_clock_to_remote/12.2-1.sql"
#include "udfs/citus_internal_delete_colocation_metadata/12.2-1.sql"
#include "udfs/citus_internal_delete_partition_metadata/12.2-1.sql"
#include "udfs/citus_internal_delete_placement_metadata/12.2-1.sql"
#include "udfs/citus_internal_delete_shard_metadata/12.2-1.sql"
#include "udfs/citus_internal_delete_tenant_schema/12.2-1.sql"
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ DROP FUNCTION citus_internal.add_placement_metadata(bigint, bigint, integer, big
DROP FUNCTION citus_internal.add_shard_metadata(regclass, bigint, "char", text, text);
DROP FUNCTION citus_internal.add_tenant_schema(oid, integer);
DROP FUNCTION citus_internal.adjust_local_clock_to_remote(pg_catalog.cluster_clock);
DROP FUNCTION citus_internal.delete_colocation_metadata(int);
DROP FUNCTION citus_internal.delete_partition_metadata(regclass);
DROP FUNCTION citus_internal.delete_placement_metadata(bigint);
DROP FUNCTION citus_internal.delete_shard_metadata(bigint);
DROP FUNCTION citus_internal.delete_tenant_schema(oid);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
CREATE OR REPLACE FUNCTION citus_internal.delete_colocation_metadata(
colocation_id int)
RETURNS void
LANGUAGE C
STRICT
AS 'MODULE_PATHNAME', $$citus_internal_delete_colocation_metadata$$;

COMMENT ON FUNCTION citus_internal.delete_colocation_metadata(int) IS
'deletes a co-location group from pg_dist_colocation';

CREATE OR REPLACE FUNCTION pg_catalog.citus_internal_delete_colocation_metadata(
colocation_id int)
RETURNS void
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
CREATE OR REPLACE FUNCTION citus_internal.delete_partition_metadata(table_name regclass)
RETURNS void
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$citus_internal_delete_partition_metadata$$;
COMMENT ON FUNCTION citus_internal.delete_partition_metadata(regclass) IS
'Deletes a row from pg_dist_partition with table ownership checks';

CREATE OR REPLACE FUNCTION pg_catalog.citus_internal_delete_partition_metadata(table_name regclass)
RETURNS void
LANGUAGE C STRICT
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
CREATE OR REPLACE FUNCTION citus_internal.delete_placement_metadata(
placement_id bigint)
RETURNS void
LANGUAGE C
VOLATILE
AS 'MODULE_PATHNAME',
$$citus_internal_delete_placement_metadata$$;
COMMENT ON FUNCTION citus_internal.delete_placement_metadata(bigint)
IS 'Delete placement with given id from pg_dist_placement metadata table.';

CREATE OR REPLACE FUNCTION pg_catalog.citus_internal_delete_placement_metadata(
placement_id bigint)
RETURNS void
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
CREATE OR REPLACE FUNCTION citus_internal.delete_shard_metadata(shard_id bigint)
RETURNS void
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$citus_internal_delete_shard_metadata$$;
COMMENT ON FUNCTION citus_internal.delete_shard_metadata(bigint) IS
'Deletes rows from pg_dist_shard and pg_dist_shard_placement with user checks';

CREATE OR REPLACE FUNCTION pg_catalog.citus_internal_delete_shard_metadata(shard_id bigint)
RETURNS void
LANGUAGE C STRICT
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
CREATE OR REPLACE FUNCTION citus_internal.delete_tenant_schema(schema_id Oid)
RETURNS void
LANGUAGE C
VOLATILE
AS 'MODULE_PATHNAME', $$citus_internal_delete_tenant_schema$$;

COMMENT ON FUNCTION citus_internal.delete_tenant_schema(Oid) IS
'delete given tenant schema from pg_dist_schema';

CREATE OR REPLACE FUNCTION pg_catalog.citus_internal_delete_tenant_schema(schema_id Oid)
RETURNS void
LANGUAGE C
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ ROLLBACK;
-- reference tables.
SELECT pg_catalog.citus_internal_update_none_dist_table_metadata(1, 't', 1, true);
ERROR: This is an internal Citus function can only be used in a distributed transaction
SELECT pg_catalog.citus_internal_delete_placement_metadata(1);
SELECT citus_internal.delete_placement_metadata(1);
ERROR: This is an internal Citus function can only be used in a distributed transaction
CREATE ROLE test_user_create_ref_dist WITH LOGIN;
GRANT ALL ON SCHEMA create_ref_dist_from_citus_local TO test_user_create_ref_dist;
Expand Down Expand Up @@ -401,7 +401,7 @@ SELECT pg_catalog.citus_internal_update_none_dist_table_metadata(1, 't', null, t
ERROR: colocation_id cannot be NULL
SELECT pg_catalog.citus_internal_update_none_dist_table_metadata(1, 't', 1, null);
ERROR: auto_converted cannot be NULL
SELECT pg_catalog.citus_internal_delete_placement_metadata(null);
SELECT citus_internal.delete_placement_metadata(null);
ERROR: placement_id cannot be NULL
CREATE TABLE udf_test (col_1 int);
SELECT citus_add_local_table_to_metadata('udf_test');
Expand All @@ -426,8 +426,8 @@ BEGIN;

SELECT placementid AS udf_test_placementid FROM pg_dist_shard_placement
WHERE shardid = get_shard_id_for_distribution_column('create_ref_dist_from_citus_local.udf_test') \gset
SELECT pg_catalog.citus_internal_delete_placement_metadata(:udf_test_placementid);
citus_internal_delete_placement_metadata
SELECT citus_internal.delete_placement_metadata(:udf_test_placementid);
delete_placement_metadata
---------------------------------------------------------------------

(1 row)
Expand Down
8 changes: 4 additions & 4 deletions src/test/regress/expected/drop_partitioned_table.out
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ NOTICE: issuing SELECT worker_drop_distributed_table('drop_partitioned_table.pa
NOTICE: issuing DROP TABLE IF EXISTS drop_partitioned_table.parent_xxxxx CASCADE
NOTICE: issuing SELECT worker_drop_distributed_table('drop_partitioned_table.child1')
NOTICE: issuing SELECT worker_drop_distributed_table('drop_partitioned_table.child1')
NOTICE: issuing SELECT pg_catalog.citus_internal_delete_colocation_metadata(1344400)
NOTICE: issuing SELECT pg_catalog.citus_internal_delete_colocation_metadata(1344400)
NOTICE: issuing SELECT citus_internal.delete_colocation_metadata(1344400)
NOTICE: issuing SELECT citus_internal.delete_colocation_metadata(1344400)
ROLLBACK;
NOTICE: issuing ROLLBACK
NOTICE: issuing ROLLBACK
Expand All @@ -377,8 +377,8 @@ NOTICE: issuing DROP TABLE IF EXISTS drop_partitioned_table.parent_xxxxx CASCAD
NOTICE: issuing SELECT worker_drop_distributed_table('drop_partitioned_table.child1')
NOTICE: issuing SELECT worker_drop_distributed_table('drop_partitioned_table.child1')
NOTICE: issuing DROP TABLE IF EXISTS drop_partitioned_table.child1_xxxxx CASCADE
NOTICE: issuing SELECT pg_catalog.citus_internal_delete_colocation_metadata(1344400)
NOTICE: issuing SELECT pg_catalog.citus_internal_delete_colocation_metadata(1344400)
NOTICE: issuing SELECT citus_internal.delete_colocation_metadata(1344400)
NOTICE: issuing SELECT citus_internal.delete_colocation_metadata(1344400)
ROLLBACK;
NOTICE: issuing ROLLBACK
NOTICE: issuing ROLLBACK
Expand Down
8 changes: 4 additions & 4 deletions src/test/regress/expected/metadata_sync_helpers.out
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
\set VERBOSITY terse
WITH shard_data(shardid)
AS (VALUES (1420007))
SELECT citus_internal_delete_shard_metadata(shardid) FROM shard_data;
SELECT citus_internal.delete_shard_metadata(shardid) FROM shard_data;
ERROR: must be owner of table super_user_table
ROLLBACK;
-- the user cannot delete non-existing shards
Expand All @@ -1212,7 +1212,7 @@ BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
\set VERBOSITY terse
WITH shard_data(shardid)
AS (VALUES (1420100))
SELECT citus_internal_delete_shard_metadata(shardid) FROM shard_data;
SELECT citus_internal.delete_shard_metadata(shardid) FROM shard_data;
ERROR: Shard id does not exists: 1420100
ROLLBACK;
-- sucessfully delete shards
Expand All @@ -1239,8 +1239,8 @@ BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
\set VERBOSITY terse
WITH shard_data(shardid)
AS (VALUES (1420000))
SELECT citus_internal_delete_shard_metadata(shardid) FROM shard_data;
citus_internal_delete_shard_metadata
SELECT citus_internal.delete_shard_metadata(shardid) FROM shard_data;
delete_shard_metadata
---------------------------------------------------------------------

(1 row)
Expand Down
7 changes: 6 additions & 1 deletion src/test/regress/expected/multi_extension.out
Original file line number Diff line number Diff line change
Expand Up @@ -1432,10 +1432,15 @@ SELECT * FROM multi_extension.print_extension_changes();
| function citus_internal.adjust_local_clock_to_remote(cluster_clock) void
| function citus_internal.commit_management_command_2pc() void
| function citus_internal.database_command(text) void
| function citus_internal.delete_colocation_metadata(integer) void
| function citus_internal.delete_partition_metadata(regclass) void
| function citus_internal.delete_placement_metadata(bigint) void
| function citus_internal.delete_shard_metadata(bigint) void
| function citus_internal.delete_tenant_schema(oid) void
| function citus_internal.execute_command_on_remote_nodes_as_user(text,text) void
| function citus_internal.mark_object_distributed(oid,text,oid,text) void
| function citus_internal.start_management_transaction(xid8) void
(13 rows)
(18 rows)

DROP TABLE multi_extension.prev_objects, multi_extension.extension_diff;
-- show running version
Expand Down
2 changes: 1 addition & 1 deletion src/test/regress/expected/schema_based_sharding.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SELECT citus_internal.add_tenant_schema(NULL, 1);
ERROR: schema_id cannot be NULL
SELECT citus_internal.add_tenant_schema(1, NULL);
ERROR: colocation_id cannot be NULL
SELECT citus_internal_delete_tenant_schema(NULL);
SELECT citus_internal.delete_tenant_schema(NULL);
ERROR: schema_id cannot be NULL
SELECT citus_internal_unregister_tenant_schema_globally(1, NULL);
ERROR: schema_name cannot be NULL
Expand Down
7 changes: 6 additions & 1 deletion src/test/regress/expected/upgrade_list_citus_objects.out
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ ORDER BY 1;
function citus_internal.adjust_local_clock_to_remote(cluster_clock)
function citus_internal.commit_management_command_2pc()
function citus_internal.database_command(text)
function citus_internal.delete_colocation_metadata(integer)
function citus_internal.delete_partition_metadata(regclass)
function citus_internal.delete_placement_metadata(bigint)
function citus_internal.delete_shard_metadata(bigint)
function citus_internal.delete_tenant_schema(oid)
function citus_internal.execute_command_on_remote_nodes_as_user(text,text)
function citus_internal.find_groupid_for_node(text,integer)
function citus_internal.mark_object_distributed(oid,text,oid,text)
Expand Down Expand Up @@ -356,5 +361,5 @@ ORDER BY 1;
view citus_stat_tenants_local
view pg_dist_shard_placement
view time_partitions
(346 rows)
(351 rows)

6 changes: 3 additions & 3 deletions src/test/regress/sql/create_ref_dist_from_citus_local.sql
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ ROLLBACK;
-- reference tables.

SELECT pg_catalog.citus_internal_update_none_dist_table_metadata(1, 't', 1, true);
SELECT pg_catalog.citus_internal_delete_placement_metadata(1);
SELECT citus_internal.delete_placement_metadata(1);

CREATE ROLE test_user_create_ref_dist WITH LOGIN;
GRANT ALL ON SCHEMA create_ref_dist_from_citus_local TO test_user_create_ref_dist;
Expand All @@ -239,7 +239,7 @@ SELECT pg_catalog.citus_internal_update_none_dist_table_metadata(1, null, 1, tru
SELECT pg_catalog.citus_internal_update_none_dist_table_metadata(1, 't', null, true);
SELECT pg_catalog.citus_internal_update_none_dist_table_metadata(1, 't', 1, null);

SELECT pg_catalog.citus_internal_delete_placement_metadata(null);
SELECT citus_internal.delete_placement_metadata(null);

CREATE TABLE udf_test (col_1 int);
SELECT citus_add_local_table_to_metadata('udf_test');
Expand All @@ -253,7 +253,7 @@ BEGIN;
SELECT placementid AS udf_test_placementid FROM pg_dist_shard_placement
WHERE shardid = get_shard_id_for_distribution_column('create_ref_dist_from_citus_local.udf_test') \gset

SELECT pg_catalog.citus_internal_delete_placement_metadata(:udf_test_placementid);
SELECT citus_internal.delete_placement_metadata(:udf_test_placementid);

SELECT COUNT(*)=0 FROM pg_dist_placement WHERE placementid = :udf_test_placementid;
ROLLBACK;
Expand Down
Loading

0 comments on commit 594cb6f

Please sign in to comment.