Merge pull request #5828 from citusdata/marcocitus/fix-lock

pull/5824/head
Marco Slot 2022-03-18 14:46:38 +01:00 committed by GitHub
commit a1108d2a20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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; return false;
} }
relation_close(relation, NoLock);
/* /*
* If the input relation is an index we simply replace the * 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) (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 -- 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; SELECT relname FROM pg_catalog.pg_class WHERE relnamespace = 'mx_hide_shard_names'::regnamespace ORDER BY relname;
relname relname
@ -78,6 +82,7 @@ SELECT relname FROM pg_catalog.pg_class WHERE relnamespace = 'mx_hide_shard_name
test_table test_table
(1 row) (1 row)
commit prepared 'take-aggressive-lock';
-- now create an index -- now create an index
\c - - - :master_port \c - - - :master_port
SET search_path TO 'mx_hide_shard_names'; 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_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; 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 -- 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; 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 -- now create an index
\c - - - :master_port \c - - - :master_port
SET search_path TO 'mx_hide_shard_names'; SET search_path TO 'mx_hide_shard_names';