Deadlock with concurrent create_distributed_table and citus_create_restore_point
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
We are facing with this bug within our regression tests. We are running `multi_utilities` and `foreign_key_to_reference_table` tests in parallel and `citus_create_restore_point` is called from the first test and `create_distributed_table` is called from the second test.
Creating a distributed table (with a new colocation group) using `create_distributed_table` first locks the `pg_dist_partition` table (while inserting a new tuple to it) and then locks the `pg_dist_node` table (while creating shards with round robin policy). On the other hand, `citus_create_restore_point` locks metadata tables in the order of `pg_dist_node`, `pg_dist_partition` and `pg_dist_transaction`. Running these two concurrently may cause a deadlock.
You may reproduce it by running the following two scripts concurrently with pgbench
```
create table rt(id int);
select create_distributed_table('rt', 'id');
drop table rt;
```
and
`SELECT 1 FROM citus_create_restore_point('regression-test');
`
Contributor guide
Assessment
This issue has not been assessed yet.