Avoid locks in relation_is_a_known_shard

pull/5828/head
Marco Slot 2022-03-18 14:37:39 +01:00
parent eeafa67bea
commit cab243218d
3 changed files with 18 additions and 3 deletions

View File

@ -202,12 +202,15 @@ RelationIsAKnownShard(Oid shardRelationId)
}
}
Relation relation = try_relation_open(shardRelationId, AccessShareLock);
if (relation == NULL)
/*
* We do not take locks here, because that might block a query on pg_class.
*/
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(shardRelationId)))
{
/* relation does not exist */
return false;
}
relation_close(relation, NoLock);
/*
* If the input relation is an index we simply replace the

View File

@ -71,6 +71,10 @@ SELECT * FROM citus_shard_indexes_on_worker WHERE "Schema" = 'mx_hide_shard_name
---------------------------------------------------------------------
(0 rows)
-- make sure that pg_class queries do not get blocked on table locks
begin;
lock table test_table in access exclusive mode;
prepare transaction 'take-aggressive-lock';
-- shards are hidden when using psql as application_name
SELECT relname FROM pg_catalog.pg_class WHERE relnamespace = 'mx_hide_shard_names'::regnamespace ORDER BY relname;
relname
@ -78,6 +82,7 @@ SELECT relname FROM pg_catalog.pg_class WHERE relnamespace = 'mx_hide_shard_name
test_table
(1 row)
commit prepared 'take-aggressive-lock';
-- now create an index
\c - - - :master_port
SET search_path TO 'mx_hide_shard_names';

View File

@ -41,9 +41,16 @@ SET search_path TO 'mx_hide_shard_names';
SELECT * FROM citus_shards_on_worker WHERE "Schema" = 'mx_hide_shard_names' ORDER BY 2;
SELECT * FROM citus_shard_indexes_on_worker WHERE "Schema" = 'mx_hide_shard_names' ORDER BY 2;
-- make sure that pg_class queries do not get blocked on table locks
begin;
lock table test_table in access exclusive mode;
prepare transaction 'take-aggressive-lock';
-- shards are hidden when using psql as application_name
SELECT relname FROM pg_catalog.pg_class WHERE relnamespace = 'mx_hide_shard_names'::regnamespace ORDER BY relname;
commit prepared 'take-aggressive-lock';
-- now create an index
\c - - - :master_port
SET search_path TO 'mx_hide_shard_names';