Skip to content

Commit c5acdf4

Browse files
author
Antonin Houska
committed
Added a test for TOASTed values.
1 parent 5a68f62 commit c5acdf4

File tree

3 files changed

+244
-1
lines changed

3 files changed

+244
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ DATA = pg_rewrite--1.0.sql pg_rewrite--1.0--1.1.sql pg_rewrite--1.1--1.2.sql
88
DOCS = pg_rewrite.md
99

1010
REGRESS = pg_rewrite generated
11-
#ISOLATION = pg_rewrite_concurrent pg_rewrite_concurrent_partition
11+
#ISOLATION = pg_rewrite_concurrent pg_rewrite_concurrent_partition \
12+
pg_rewrite_concurrent_toast
1213

1314
PGXS := $(shell $(PG_CONFIG) --pgxs)
1415
include $(PGXS)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
Parsed test spec with 2 sessions
2+
3+
starting permutation: do_rewrite wait_for_before_lock_ip do_changes wakeup_before_lock_ip wait_for_after_commit_ip do_check wakeup_after_commit_ip
4+
injection_points_attach
5+
-----------------------
6+
7+
(1 row)
8+
9+
step do_rewrite:
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_before_lock_ip:
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 INTO tbl_src(i, t)
38+
SELECT 5, string_agg(random()::text, '')
39+
FROM generate_series(1, 200) h(y);
40+
41+
UPDATE tbl_src SET t = t || 'x' WHERE i = 1;
42+
43+
step wakeup_before_lock_ip:
44+
SELECT injection_points_wakeup('pg_rewrite-before-lock');
45+
46+
injection_points_wakeup
47+
-----------------------
48+
49+
(1 row)
50+
51+
step wait_for_after_commit_ip:
52+
DO $$
53+
BEGIN
54+
LOOP
55+
PERFORM pg_stat_clear_snapshot();
56+
57+
PERFORM
58+
FROM pg_stat_activity
59+
WHERE (wait_event_type, wait_event)=('InjectionPoint', 'pg_rewrite-after-commit');
60+
61+
IF FOUND THEN
62+
EXIT;
63+
END IF;
64+
65+
PERFORM pg_sleep(.1);
66+
END LOOP;
67+
END;
68+
$$;
69+
70+
step do_check:
71+
TABLE pg_rewrite_progress;
72+
73+
-- Each row should contain TOASTed value.
74+
SELECT count(*) FROM tbl_src WHERE pg_column_toast_chunk_id(t) ISNULL;
75+
76+
-- The contents of the new table should be identical to that of the old
77+
-- one.
78+
SELECT count(*)
79+
FROM tbl_src t1 JOIN tbl_src_old t2 ON t1.i = t2.i
80+
WHERE t1.t <> t2.t;
81+
82+
src_table|dst_table|src_table_new|ins_initial|ins|upd|del
83+
---------+---------+-------------+-----------+---+---+---
84+
tbl_src |tbl_dst |tbl_src_old | 2| 1| 1| 0
85+
(1 row)
86+
87+
count
88+
-----
89+
0
90+
(1 row)
91+
92+
count
93+
-----
94+
0
95+
(1 row)
96+
97+
step wakeup_after_commit_ip:
98+
SELECT injection_points_wakeup('pg_rewrite-after-commit');
99+
100+
injection_points_wakeup
101+
-----------------------
102+
103+
(1 row)
104+
105+
injection_points_detach
106+
-----------------------
107+
108+
(1 row)
109+
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
setup
2+
{
3+
CREATE EXTENSION injection_points;
4+
CREATE EXTENSION pg_rewrite;
5+
6+
CREATE TABLE tbl_src(i int primary key, t text);
7+
8+
INSERT INTO tbl_src(i, t)
9+
SELECT x, string_agg(random()::text, '')
10+
FROM generate_series(1, 2) g(x), generate_series(1, 200) h(y)
11+
GROUP BY x;
12+
13+
CREATE TABLE tbl_dst(i int primary key, t text);
14+
}
15+
16+
teardown
17+
{
18+
DROP EXTENSION injection_points;
19+
DROP EXTENSION pg_rewrite;
20+
DROP TABLE tbl_src;
21+
DROP TABLE tbl_src_old;
22+
}
23+
24+
session s1
25+
setup
26+
{
27+
SELECT injection_points_attach('pg_rewrite-before-lock', 'wait');
28+
SELECT injection_points_attach('pg_rewrite-after-commit', 'wait');
29+
}
30+
# Perform the initial load and wait for s2 to do some data changes.
31+
#
32+
# Since pg_rewrite uses background worker, the isolation tester does not
33+
# recognize that the session waits on an injection point (because the worker
34+
# is who waits). Therefore use rewrite_table_nowait(), which only launches the
35+
# worker and goes on. The 'wait_for_s1_sleep' step below then checks until the
36+
# waiting started.
37+
step do_rewrite
38+
{
39+
SELECT rewrite_table_nowait('tbl_src', 'tbl_dst', 'tbl_src_old');
40+
}
41+
# Check the data.
42+
step do_check
43+
{
44+
TABLE pg_rewrite_progress;
45+
46+
-- Each row should contain TOASTed value.
47+
SELECT count(*) FROM tbl_src WHERE pg_column_toast_chunk_id(t) ISNULL;
48+
49+
-- The contents of the new table should be identical to that of the old
50+
-- one.
51+
SELECT count(*)
52+
FROM tbl_src t1 JOIN tbl_src_old t2 ON t1.i = t2.i
53+
WHERE t1.t <> t2.t;
54+
}
55+
56+
session s2
57+
# Since s1 uses background worker, the backend executing 'wait_before_lock'
58+
# does not appear to be waiting on the injection point. Instead we need to
59+
# check explicitly if the waiting on the injection point is in progress, and
60+
# wait if it's not.
61+
step wait_for_before_lock_ip
62+
{
63+
DO $$
64+
BEGIN
65+
LOOP
66+
PERFORM pg_stat_clear_snapshot();
67+
68+
PERFORM
69+
FROM pg_stat_activity
70+
WHERE (wait_event_type, wait_event)=('InjectionPoint', 'pg_rewrite-before-lock');
71+
72+
IF FOUND THEN
73+
EXIT;
74+
END IF;
75+
76+
PERFORM pg_sleep(.1);
77+
END LOOP;
78+
END;
79+
$$;
80+
}
81+
step do_changes
82+
{
83+
INSERT INTO tbl_src(i, t)
84+
SELECT 5, string_agg(random()::text, '')
85+
FROM generate_series(1, 200) h(y);
86+
87+
UPDATE tbl_src SET t = t || 'x' WHERE i = 1;
88+
}
89+
step wakeup_before_lock_ip
90+
{
91+
SELECT injection_points_wakeup('pg_rewrite-before-lock');
92+
}
93+
# Wait until the concurrent changes have been committed by the pg_rewrite
94+
# worker.
95+
step wait_for_after_commit_ip
96+
{
97+
DO $$
98+
BEGIN
99+
LOOP
100+
PERFORM pg_stat_clear_snapshot();
101+
102+
PERFORM
103+
FROM pg_stat_activity
104+
WHERE (wait_event_type, wait_event)=('InjectionPoint', 'pg_rewrite-after-commit');
105+
106+
IF FOUND THEN
107+
EXIT;
108+
END IF;
109+
110+
PERFORM pg_sleep(.1);
111+
END LOOP;
112+
END;
113+
$$;
114+
}
115+
# Like wakeup_before_lock_ip above.
116+
step wakeup_after_commit_ip
117+
{
118+
SELECT injection_points_wakeup('pg_rewrite-after-commit');
119+
}
120+
teardown
121+
{
122+
SELECT injection_points_detach('pg_rewrite-before-lock');
123+
SELECT injection_points_detach('pg_rewrite-after-commit');
124+
}
125+
126+
permutation
127+
do_rewrite
128+
wait_for_before_lock_ip
129+
do_changes
130+
wakeup_before_lock_ip
131+
wait_for_after_commit_ip
132+
do_check
133+
wakeup_after_commit_ip

0 commit comments

Comments
 (0)