add more tests

fix/distributed_deadlock1
Sait Talha Nisanci 2021-08-06 15:11:28 +03:00
parent 5d51333ebc
commit 364f902ff0
3 changed files with 140 additions and 5 deletions

View File

@ -1565,11 +1565,11 @@ LockPartitionsForDistributedPlan(DistributedPlan *distributedPlan)
Oid parentRelationId = PartitionParentOid(targetRelationId); Oid parentRelationId = PartitionParentOid(targetRelationId);
/* /*
* We lock the parent relation after locking relations to prevent * Postgres only takes the lock on parent when the session accesses the
* distributed deadlock. * partition for the first time. So it should be okay to get this lock from
* Postgres doesn't take AccessShareLock on the parent table when the * PG perspective. Even though we diverge from PG behavior for concurrent
* child quals are already cached and a drop/create partition can * modifications on partitions vs CREATE/DROP partitions, we consider this as
* result in a distributed deadlock with multi-shard update. * a reasonable trade-off to avoid distributed deadlocks.
*/ */
LockRelationOid(parentRelationId, AccessShareLock); LockRelationOid(parentRelationId, AccessShareLock);
} }

View File

@ -5,9 +5,11 @@ step s1-begin:
BEGIN; BEGIN;
step s1-update: step s1-update:
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1; update test_9_1 set destination = 1;
step s2-drop: step s2-drop:
set citus.force_max_query_parallelization to 'on';
drop table test_6_1; drop table test_6_1;
<waiting ...> <waiting ...>
step s1-commit: step s1-commit:
@ -20,9 +22,11 @@ step s2-begin:
BEGIN; BEGIN;
step s2-drop: step s2-drop:
set citus.force_max_query_parallelization to 'on';
drop table test_6_1; drop table test_6_1;
step s1-update: step s1-update:
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1; update test_9_1 set destination = 1;
<waiting ...> <waiting ...>
step s2-commit: step s2-commit:
@ -35,9 +39,11 @@ step s1-begin:
BEGIN; BEGIN;
step s1-update: step s1-update:
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1; update test_9_1 set destination = 1;
step s2-create: step s2-create:
set citus.force_max_query_parallelization to 'on';
CREATE TABLE test_10_1 PARTITION OF test FOR VALUES FROM ('10', '2021-07-16') TO ('11', '2021-07-17'); CREATE TABLE test_10_1 PARTITION OF test FOR VALUES FROM ('10', '2021-07-16') TO ('11', '2021-07-17');
<waiting ...> <waiting ...>
step s1-commit: step s1-commit:
@ -50,9 +56,115 @@ step s2-begin:
BEGIN; BEGIN;
step s2-create: step s2-create:
set citus.force_max_query_parallelization to 'on';
CREATE TABLE test_10_1 PARTITION OF test FOR VALUES FROM ('10', '2021-07-16') TO ('11', '2021-07-17'); CREATE TABLE test_10_1 PARTITION OF test FOR VALUES FROM ('10', '2021-07-16') TO ('11', '2021-07-17');
step s1-update: step s1-update:
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1;
<waiting ...>
step s2-commit:
COMMIT;
step s1-update: <... completed>
starting permutation: s1-begin s1-update s2-truncate s1-commit
step s1-begin:
BEGIN;
step s1-update:
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1;
step s2-truncate:
set citus.force_max_query_parallelization to 'on';
TRUNCATE TABLE test_6_1;
step s1-commit:
COMMIT;
starting permutation: s2-begin s2-truncate s1-update s2-commit
step s2-begin:
BEGIN;
step s2-truncate:
set citus.force_max_query_parallelization to 'on';
TRUNCATE TABLE test_6_1;
step s1-update:
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1;
step s2-commit:
COMMIT;
starting permutation: s1-begin s1-update s2-detach s1-commit
step s1-begin:
BEGIN;
step s1-update:
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1;
step s2-detach:
ALTER TABLE test DETACH PARTITION test_6_1;
<waiting ...>
step s1-commit:
COMMIT;
step s2-detach: <... completed>
starting permutation: s2-begin s2-detach s1-update s2-commit
step s2-begin:
BEGIN;
step s2-detach:
ALTER TABLE test DETACH PARTITION test_6_1;
step s1-update:
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1;
<waiting ...>
step s2-commit:
COMMIT;
step s1-update: <... completed>
starting permutation: s1-begin s1-update s2-alter-table s1-commit
step s1-begin:
BEGIN;
step s1-update:
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1;
step s2-alter-table:
set citus.force_max_query_parallelization to 'on';
SELECT alter_table_set_access_method('test_6_1','columnar');
<waiting ...>
step s1-commit:
COMMIT;
step s2-alter-table: <... completed>
alter_table_set_access_method
starting permutation: s2-begin s2-alter-table s1-update s2-commit
step s2-begin:
BEGIN;
step s2-alter-table:
set citus.force_max_query_parallelization to 'on';
SELECT alter_table_set_access_method('test_6_1','columnar');
alter_table_set_access_method
step s1-update:
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1; update test_9_1 set destination = 1;
<waiting ...> <waiting ...>
step s2-commit: step s2-commit:

View File

@ -9,6 +9,7 @@ setup
SELECT create_distributed_table('test', 'name'); SELECT create_distributed_table('test', 'name');
DROP TABLE IF EXISTS test_6_1;
CREATE TABLE test_6_1 PARTITION OF test FOR VALUES FROM ('6', '2021-07-12') TO ('6', '2021-07-13'); CREATE TABLE test_6_1 PARTITION OF test FOR VALUES FROM ('6', '2021-07-12') TO ('6', '2021-07-13');
CREATE TABLE test_7_1 PARTITION OF test FOR VALUES FROM ('7', '2021-07-13') TO ('8', '2021-07-14'); CREATE TABLE test_7_1 PARTITION OF test FOR VALUES FROM ('7', '2021-07-13') TO ('8', '2021-07-14');
CREATE TABLE test_8_1 PARTITION OF test FOR VALUES FROM ('8', '2021-07-14') TO ('9', '2021-07-15'); CREATE TABLE test_8_1 PARTITION OF test FOR VALUES FROM ('8', '2021-07-14') TO ('9', '2021-07-15');
@ -29,6 +30,7 @@ step "s1-begin" {
} }
step "s1-update" { step "s1-update" {
set citus.force_max_query_parallelization to 'on';
update test_9_1 set destination = 1; update test_9_1 set destination = 1;
} }
@ -43,12 +45,27 @@ step "s2-begin" {
} }
step "s2-drop" { step "s2-drop" {
set citus.force_max_query_parallelization to 'on';
drop table test_6_1; drop table test_6_1;
} }
step "s2-create" { step "s2-create" {
set citus.force_max_query_parallelization to 'on';
CREATE TABLE test_10_1 PARTITION OF test FOR VALUES FROM ('10', '2021-07-16') TO ('11', '2021-07-17'); CREATE TABLE test_10_1 PARTITION OF test FOR VALUES FROM ('10', '2021-07-16') TO ('11', '2021-07-17');
}
step "s2-detach" {
ALTER TABLE test DETACH PARTITION test_6_1;
}
step "s2-truncate" {
set citus.force_max_query_parallelization to 'on';
TRUNCATE TABLE test_6_1;
}
step "s2-alter-table" {
set citus.force_max_query_parallelization to 'on';
SELECT alter_table_set_access_method('test_6_1','columnar');
} }
step "s2-commit" { step "s2-commit" {
@ -59,3 +76,9 @@ permutation "s1-begin" "s1-update" "s2-drop" "s1-commit"
permutation "s2-begin" "s2-drop" "s1-update" "s2-commit" permutation "s2-begin" "s2-drop" "s1-update" "s2-commit"
permutation "s1-begin" "s1-update" "s2-create" "s1-commit" permutation "s1-begin" "s1-update" "s2-create" "s1-commit"
permutation "s2-begin" "s2-create" "s1-update" "s2-commit" permutation "s2-begin" "s2-create" "s1-update" "s2-commit"
permutation "s1-begin" "s1-update" "s2-truncate" "s1-commit"
permutation "s2-begin" "s2-truncate" "s1-update" "s2-commit"
permutation "s1-begin" "s1-update" "s2-detach" "s1-commit"
permutation "s2-begin" "s2-detach" "s1-update" "s2-commit"
permutation "s1-begin" "s1-update" "s2-alter-table" "s1-commit"
permutation "s2-begin" "s2-alter-table" "s1-update" "s2-commit"