Move more citus internal functions (#7473)

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
move_blocked_processes_udfs
eaydingol 2024-01-31 23:00:04 +03:00 committed by GitHub
parent d05174093b
commit 594cb6f274
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 174 additions and 28 deletions

View File

@ -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;
@ -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);
}
@ -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;
@ -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;
@ -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;
}

View File

@ -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)
{

View File

@ -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"

View File

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

View File

@ -0,0 +1,19 @@
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
LANGUAGE C
STRICT
AS 'MODULE_PATHNAME';
COMMENT ON FUNCTION pg_catalog.citus_internal_delete_colocation_metadata(int) IS
'deletes a co-location group from pg_dist_colocation';

View File

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

View File

@ -0,0 +1,14 @@
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
AS 'MODULE_PATHNAME';
COMMENT ON FUNCTION pg_catalog.citus_internal_delete_partition_metadata(regclass) IS
'Deletes a row from pg_dist_partition with table ownership checks';

View File

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

View File

@ -0,0 +1,19 @@
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
LANGUAGE C
VOLATILE
AS 'MODULE_PATHNAME',
$$citus_internal_delete_placement_metadata$$;
COMMENT ON FUNCTION pg_catalog.citus_internal_delete_placement_metadata(bigint)
IS 'Delete placement with given id from pg_dist_placement metadata table.';

View File

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

View File

@ -0,0 +1,14 @@
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
AS 'MODULE_PATHNAME';
COMMENT ON FUNCTION pg_catalog.citus_internal_delete_shard_metadata(bigint) IS
'Deletes rows from pg_dist_shard and pg_dist_shard_placement with user checks';

View File

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

View File

@ -0,0 +1,17 @@
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
VOLATILE
AS 'MODULE_PATHNAME';
COMMENT ON FUNCTION pg_catalog.citus_internal_delete_tenant_schema(Oid) IS
'delete given tenant schema from pg_dist_schema';

View File

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

View File

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

View File

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

View File

@ -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
@ -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
@ -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)

View File

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

View File

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

View File

@ -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)
@ -356,5 +361,5 @@ ORDER BY 1;
view citus_stat_tenants_local
view pg_dist_shard_placement
view time_partitions
(346 rows)
(351 rows)

View File

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

View File

@ -745,7 +745,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;
ROLLBACK;
-- the user cannot delete non-existing shards
@ -755,7 +755,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;
ROLLBACK;
@ -770,7 +770,7 @@ 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;
SELECT citus_internal.delete_shard_metadata(shardid) FROM shard_data;
SELECT count(*) FROM pg_dist_shard WHERE shardid = 1420000;
SELECT count(*) FROM pg_dist_placement WHERE shardid = 1420000;

View File

@ -14,7 +14,7 @@ SET client_min_messages TO NOTICE;
-- fail on NULL input.
SELECT citus_internal.add_tenant_schema(NULL, 1);
SELECT citus_internal.add_tenant_schema(1, NULL);
SELECT citus_internal_delete_tenant_schema(NULL);
SELECT citus_internal.delete_tenant_schema(NULL);
SELECT citus_internal_unregister_tenant_schema_globally(1, NULL);
SELECT citus_internal_unregister_tenant_schema_globally(NULL, 'text');