Skip to content

Commit c54d43f

Browse files
author
Antonin Houska
committed
Add regression tests for processing of concurrent data changes.
1 parent 58d418e commit c54d43f

6 files changed

Lines changed: 360 additions & 95 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pg_rewrite--1.2--1.3.sql
99
DOCS = pg_rewrite.md
1010

1111
REGRESS = pg_rewrite
12+
ISOLATION = pg_rewrite_concurrent
1213

1314
PGXS := $(shell $(PG_CONFIG) --pgxs)
1415
include $(PGXS)

expected/pg_rewrite_concurrent.out

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
Parsed test spec with 2 sessions
2+
3+
starting permutation: wait_before_lock wait_for_s1_sleep do_changes wakeup_before_lock wait_for_backend_exit check
4+
injection_points_attach
5+
-----------------------
6+
7+
(1 row)
8+
9+
step wait_before_lock:
10+
SELECT rewrite_table_nowait('tbl_src', 'tbl_dst', 'tbl_src_old');
11+
12+
rewrite_table_nowait
13+
--------------------
14+
15+
(1 row)
16+
17+
step wait_for_s1_sleep:
18+
DO $$
19+
BEGIN
20+
LOOP
21+
PERFORM pg_stat_clear_snapshot();
22+
23+
PERFORM
24+
FROM pg_stat_activity
25+
WHERE (wait_event_type, wait_event)=('InjectionPoint', 'pg_rewrite-before-lock');
26+
27+
IF FOUND THEN
28+
EXIT;
29+
END IF;
30+
31+
PERFORM pg_sleep(.1);
32+
END LOOP;
33+
END;
34+
$$
35+
36+
step do_changes:
37+
-- Insert one row into each partition.
38+
INSERT INTO tbl_src VALUES (2, 2), (3, 3), (5, 5);
39+
40+
-- Update with no identity change.
41+
UPDATE tbl_src SET j=0 WHERE i=1;
42+
43+
-- Update with identity change but within the same partition.
44+
UPDATE tbl_src SET i=6 WHERE i=5;
45+
46+
-- Cross-partition update.
47+
UPDATE tbl_src SET i=7 WHERE i=3;
48+
49+
-- Update a row we inserted and updated, to check that it's visible.
50+
UPDATE tbl_src SET j=4 WHERE i=7;
51+
52+
-- Delete.
53+
DELETE FROM tbl_src WHERE i=4;
54+
55+
step wakeup_before_lock:
56+
SELECT injection_points_wakeup('pg_rewrite-before-lock');
57+
SELECT injection_points_detach('pg_rewrite-before-lock');
58+
59+
injection_points_wakeup
60+
-----------------------
61+
62+
(1 row)
63+
64+
injection_points_detach
65+
-----------------------
66+
67+
(1 row)
68+
69+
step wait_for_backend_exit:
70+
DO $$
71+
BEGIN
72+
LOOP
73+
PERFORM FROM pg_rewrite_progress;
74+
75+
IF NOT FOUND THEN
76+
EXIT;
77+
END IF;
78+
79+
PERFORM pg_sleep(.1);
80+
END LOOP;
81+
END;
82+
$$;
83+
84+
85+
step check:
86+
SELECT i, j FROM tbl_src ORDER BY i, j;
87+
88+
i|j
89+
-+-
90+
1|0
91+
2|2
92+
6|5
93+
7|4
94+
(4 rows)
95+

pg_rewrite--1.2--1.3.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
\echo Use "ALTER EXTENSION pg_rewrite UPDATE TO '1.3'" to load this file. \quit
55

66
DROP FUNCTION partition_table(text, text, text);
7+
78
CREATE FUNCTION rewrite_table(
89
src_table text,
910
dst_table text,
@@ -13,3 +14,12 @@ AS 'MODULE_PATHNAME', 'rewrite_table'
1314
LANGUAGE C
1415
STRICT;
1516

17+
CREATE FUNCTION rewrite_table_nowait(
18+
src_table text,
19+
dst_table text,
20+
src_table_new text)
21+
RETURNS void
22+
AS 'MODULE_PATHNAME', 'rewrite_table_nowait'
23+
LANGUAGE C
24+
STRICT;
25+

0 commit comments

Comments
 (0)