| 1 |
# Try various things to happen to a partition with an incomplete detach |
| 2 |
# |
| 3 |
# Note: When using "s1cancel", mark the target step (the one to be canceled) |
| 4 |
# as blocking "s1cancel". This ensures consistent reporting regardless of |
| 5 |
# whether "s1cancel" finishes before or after the other step reports failure. |
| 6 |
# Also, ensure the step after "s1cancel" is also an s1 step (use "s1noop" if |
| 7 |
# necessary). This ensures we won't move on to the next step until the cancel |
| 8 |
# is complete. |
| 9 |
|
| 10 |
setup |
| 11 |
{ |
| 12 |
CREATE TABLE d3_listp (a int) PARTITION BY LIST(a); |
| 13 |
CREATE TABLE d3_listp1 PARTITION OF d3_listp FOR VALUES IN (1); |
| 14 |
CREATE TABLE d3_listp2 PARTITION OF d3_listp FOR VALUES IN (2); |
| 15 |
CREATE TABLE d3_pid (pid int); |
| 16 |
INSERT INTO d3_listp VALUES (1); |
| 17 |
} |
| 18 |
|
| 19 |
teardown { |
| 20 |
DROP TABLE IF EXISTS d3_listp, d3_listp1, d3_listp2, d3_pid; |
| 21 |
} |
| 22 |
|
| 23 |
session s1 |
| 24 |
step s1b { BEGIN; } |
| 25 |
step s1brr { BEGIN ISOLATION LEVEL REPEATABLE READ; } |
| 26 |
step s1s { SELECT * FROM d3_listp; } |
| 27 |
step s1spart { SELECT * FROM d3_listp1; } |
| 28 |
step s1cancel { SELECT pg_cancel_backend(pid) FROM d3_pid; } |
| 29 |
step s1noop { } |
| 30 |
step s1c { COMMIT; } |
| 31 |
step s1alter { ALTER TABLE d3_listp1 ALTER a DROP NOT NULL; } |
| 32 |
step s1insert { INSERT INTO d3_listp VALUES (1); } |
| 33 |
step s1insertpart { INSERT INTO d3_listp1 VALUES (1); } |
| 34 |
step s1drop { DROP TABLE d3_listp; } |
| 35 |
step s1droppart { DROP TABLE d3_listp1; } |
| 36 |
step s1trunc { TRUNCATE TABLE d3_listp; } |
| 37 |
step s1list { SELECT relname FROM pg_catalog.pg_class |
| 38 |
WHERE relname LIKE 'd3_listp%' ORDER BY 1; } |
| 39 |
step s1describe { SELECT 'd3_listp' AS root, * FROM pg_partition_tree('d3_listp') |
| 40 |
UNION ALL SELECT 'd3_listp1', * FROM pg_partition_tree('d3_listp1'); } |
| 41 |
|
| 42 |
session s2 |
| 43 |
step s2begin { BEGIN; } |
| 44 |
step s2snitch { INSERT INTO d3_pid SELECT pg_backend_pid(); } |
| 45 |
step s2detach { ALTER TABLE d3_listp DETACH PARTITION d3_listp1 CONCURRENTLY; } |
| 46 |
step s2detach2 { ALTER TABLE d3_listp DETACH PARTITION d3_listp2 CONCURRENTLY; } |
| 47 |
step s2detachfinal { ALTER TABLE d3_listp DETACH PARTITION d3_listp1 FINALIZE; } |
| 48 |
step s2drop { DROP TABLE d3_listp1; } |
| 49 |
step s2commit { COMMIT; } |
| 50 |
|
| 51 |
# Try various things while the partition is in "being detached" state, with |
| 52 |
# no session waiting. |
| 53 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s1describe s1alter |
| 54 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1insert s1c |
| 55 |
permutation s2snitch s1brr s1s s2detach s1cancel(s2detach) s1insert s1c s1spart |
| 56 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s1insertpart |
| 57 |
|
| 58 |
# Test partition descriptor caching |
| 59 |
permutation s2snitch s1b s1s s2detach2 s1cancel(s2detach2) s1c s1brr s1insert s1s s1insert s1c |
| 60 |
permutation s2snitch s1b s1s s2detach2 s1cancel(s2detach2) s1c s1brr s1s s1insert s1s s1c |
| 61 |
|
| 62 |
# "drop" here does both tables |
| 63 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s1drop s1list |
| 64 |
# "truncate" only does parent, not partition |
| 65 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s1trunc s1spart |
| 66 |
|
| 67 |
# If a partition pending detach exists, we cannot drop another one |
| 68 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1noop s2detach2 s1c |
| 69 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1noop s2detachfinal s1c s2detach2 |
| 70 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s1droppart s2detach2 |
| 71 |
|
| 72 |
# When a partition with incomplete detach is dropped, we grab lock on parent too. |
| 73 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s2begin s2drop s1s s2commit |
| 74 |
|
| 75 |
# Partially detach, then select and try to complete the detach. Reading |
| 76 |
# from partition blocks (AEL is required on partition); reading from parent |
| 77 |
# does not block. |
| 78 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s1b s1spart s2detachfinal s1c |
| 79 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s1b s1s s2detachfinal s1c |
| 80 |
|
| 81 |
# DETACH FINALIZE in a transaction block. No insert/select on the partition |
| 82 |
# is allowed concurrently with that. |
| 83 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s1b s1spart s2detachfinal s1c |
| 84 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s2begin s2detachfinal s2commit |
| 85 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s2begin s2detachfinal s1spart s2commit |
| 86 |
permutation s2snitch s1b s1s s2detach s1cancel(s2detach) s1c s2begin s2detachfinal s1insertpart s2commit |