Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 21a1036

Browse files
committed
Add some isolation tests for CLUSTER
This commit adds two isolation tests for CLUSTER, using: - A normal table, making sure that CLUSTER blocks and completes if the table is locked by a concurrent session. - A partitioned table with a partition owned by a different user. If the partitioned table is locked by a concurrent session, CLUSTER on the partitioned table should block. If the partition owned by a different user is locked, CLUSTER on its partitioned table should complete and skip the partition. 3f19e17 has added an early check to ignore such a partition with a SQL regression test, but this was not checking that CLUSTER should not block. Discussion: https://postgr.es/m/YlqveniXn9AI6RFZ@paquier.xyz
1 parent b787c55 commit 21a1036

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Parsed test spec with 2 sessions
2+
3+
starting permutation: s1_begin s1_lock_parent s2_auth s2_cluster s1_commit s2_reset
4+
step s1_begin: BEGIN;
5+
step s1_lock_parent: LOCK cluster_part_tab IN SHARE UPDATE EXCLUSIVE MODE;
6+
step s2_auth: SET ROLE regress_cluster_part;
7+
step s2_cluster: CLUSTER cluster_part_tab USING cluster_part_ind; <waiting ...>
8+
step s1_commit: COMMIT;
9+
step s2_cluster: <... completed>
10+
step s2_reset: RESET ROLE;
11+
12+
starting permutation: s1_begin s2_auth s1_lock_parent s2_cluster s1_commit s2_reset
13+
step s1_begin: BEGIN;
14+
step s2_auth: SET ROLE regress_cluster_part;
15+
step s1_lock_parent: LOCK cluster_part_tab IN SHARE UPDATE EXCLUSIVE MODE;
16+
step s2_cluster: CLUSTER cluster_part_tab USING cluster_part_ind; <waiting ...>
17+
step s1_commit: COMMIT;
18+
step s2_cluster: <... completed>
19+
step s2_reset: RESET ROLE;
20+
21+
starting permutation: s1_begin s1_lock_child s2_auth s2_cluster s1_commit s2_reset
22+
step s1_begin: BEGIN;
23+
step s1_lock_child: LOCK cluster_part_tab1 IN SHARE UPDATE EXCLUSIVE MODE;
24+
step s2_auth: SET ROLE regress_cluster_part;
25+
step s2_cluster: CLUSTER cluster_part_tab USING cluster_part_ind;
26+
step s1_commit: COMMIT;
27+
step s2_reset: RESET ROLE;
28+
29+
starting permutation: s1_begin s2_auth s1_lock_child s2_cluster s1_commit s2_reset
30+
step s1_begin: BEGIN;
31+
step s2_auth: SET ROLE regress_cluster_part;
32+
step s1_lock_child: LOCK cluster_part_tab1 IN SHARE UPDATE EXCLUSIVE MODE;
33+
step s2_cluster: CLUSTER cluster_part_tab USING cluster_part_ind;
34+
step s1_commit: COMMIT;
35+
step s2_reset: RESET ROLE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Parsed test spec with 2 sessions
2+
3+
starting permutation: s1_begin s1_lock s2_auth s2_cluster s1_commit s2_reset
4+
step s1_begin: BEGIN;
5+
step s1_lock: LOCK cluster_tab IN SHARE UPDATE EXCLUSIVE MODE;
6+
step s2_auth: SET ROLE regress_cluster_conflict;
7+
step s2_cluster: CLUSTER cluster_tab USING cluster_ind; <waiting ...>
8+
step s1_commit: COMMIT;
9+
step s2_cluster: <... completed>
10+
step s2_reset: RESET ROLE;
11+
12+
starting permutation: s1_begin s2_auth s1_lock s2_cluster s1_commit s2_reset
13+
step s1_begin: BEGIN;
14+
step s2_auth: SET ROLE regress_cluster_conflict;
15+
step s1_lock: LOCK cluster_tab IN SHARE UPDATE EXCLUSIVE MODE;
16+
step s2_cluster: CLUSTER cluster_tab USING cluster_ind; <waiting ...>
17+
step s1_commit: COMMIT;
18+
step s2_cluster: <... completed>
19+
step s2_reset: RESET ROLE;

src/test/isolation/isolation_schedule

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ test: partition-key-update-2
102102
test: partition-key-update-3
103103
test: partition-key-update-4
104104
test: plpgsql-toast
105+
test: cluster-conflict
106+
test: cluster-conflict-partition
105107
test: truncate-conflict
106108
test: serializable-parallel
107109
test: serializable-parallel-2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Tests for locking conflicts with CLUSTER command and partitions.
2+
3+
setup
4+
{
5+
CREATE ROLE regress_cluster_part;
6+
CREATE TABLE cluster_part_tab (a int) PARTITION BY LIST (a);
7+
CREATE TABLE cluster_part_tab1 PARTITION OF cluster_part_tab FOR VALUES IN (1);
8+
CREATE TABLE cluster_part_tab2 PARTITION OF cluster_part_tab FOR VALUES IN (2);
9+
CREATE INDEX cluster_part_ind ON cluster_part_tab(a);
10+
ALTER TABLE cluster_part_tab OWNER TO regress_cluster_part;
11+
}
12+
13+
teardown
14+
{
15+
DROP TABLE cluster_part_tab;
16+
DROP ROLE regress_cluster_part;
17+
}
18+
19+
session s1
20+
step s1_begin { BEGIN; }
21+
step s1_lock_parent { LOCK cluster_part_tab IN SHARE UPDATE EXCLUSIVE MODE; }
22+
step s1_lock_child { LOCK cluster_part_tab1 IN SHARE UPDATE EXCLUSIVE MODE; }
23+
step s1_commit { COMMIT; }
24+
25+
session s2
26+
step s2_auth { SET ROLE regress_cluster_part; }
27+
step s2_cluster { CLUSTER cluster_part_tab USING cluster_part_ind; }
28+
step s2_reset { RESET ROLE; }
29+
30+
# CLUSTER on the parent waits if locked, passes for all cases.
31+
permutation s1_begin s1_lock_parent s2_auth s2_cluster s1_commit s2_reset
32+
permutation s1_begin s2_auth s1_lock_parent s2_cluster s1_commit s2_reset
33+
34+
# When taking a lock on a partition leaf, CLUSTER on the parent skips
35+
# the leaf, passes for all cases.
36+
permutation s1_begin s1_lock_child s2_auth s2_cluster s1_commit s2_reset
37+
permutation s1_begin s2_auth s1_lock_child s2_cluster s1_commit s2_reset
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Tests for locking conflicts with CLUSTER command.
2+
3+
setup
4+
{
5+
CREATE ROLE regress_cluster_conflict;
6+
CREATE TABLE cluster_tab (a int);
7+
CREATE INDEX cluster_ind ON cluster_tab(a);
8+
ALTER TABLE cluster_tab OWNER TO regress_cluster_conflict;
9+
}
10+
11+
teardown
12+
{
13+
DROP TABLE cluster_tab;
14+
DROP ROLE regress_cluster_conflict;
15+
}
16+
17+
session s1
18+
step s1_begin { BEGIN; }
19+
step s1_lock { LOCK cluster_tab IN SHARE UPDATE EXCLUSIVE MODE; }
20+
step s1_commit { COMMIT; }
21+
22+
session s2
23+
step s2_auth { SET ROLE regress_cluster_conflict; }
24+
step s2_cluster { CLUSTER cluster_tab USING cluster_ind; }
25+
step s2_reset { RESET ROLE; }
26+
27+
# The role has privileges to cluster the table, CLUSTER will block if
28+
# another session holds a lock on the table and succeed in all cases.
29+
permutation s1_begin s1_lock s2_auth s2_cluster s1_commit s2_reset
30+
permutation s1_begin s2_auth s1_lock s2_cluster s1_commit s2_reset

0 commit comments

Comments
 (0)