Skip to content

Commit eeeead5

Browse files
author
Antonin Houska
committed
Add one more injection point and check the task progress.
1 parent f6c091f commit eeeead5

3 files changed

Lines changed: 81 additions & 40 deletions

File tree

expected/pg_rewrite_concurrent.out

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
Parsed test spec with 2 sessions
22

3-
starting permutation: wait_before_lock wait_for_s1_sleep do_changes wakeup_before_lock wait_for_backend_exit check
3+
starting permutation: do_rewrite wait_for_before_lock_ip do_changes wakeup_before_lock_ip wait_for_after_commit_ip check wakeup_after_commit_ip
44
injection_points_attach
55
-----------------------
66

77
(1 row)
88

9-
step wait_before_lock:
9+
step do_rewrite:
1010
SELECT rewrite_table_nowait('tbl_src', 'tbl_dst', 'tbl_src_old');
1111

1212
rewrite_table_nowait
1313
--------------------
1414

1515
(1 row)
1616

17-
step wait_for_s1_sleep:
17+
step wait_for_before_lock_ip:
1818
DO $$
1919
BEGIN
2020
LOOP
@@ -52,39 +52,43 @@ step do_changes:
5252
-- Delete.
5353
DELETE FROM tbl_src WHERE i=4;
5454

55-
step wakeup_before_lock:
55+
step wakeup_before_lock_ip:
5656
SELECT injection_points_wakeup('pg_rewrite-before-lock');
57-
SELECT injection_points_detach('pg_rewrite-before-lock');
5857

5958
injection_points_wakeup
6059
-----------------------
6160

6261
(1 row)
6362

64-
injection_points_detach
65-
-----------------------
66-
67-
(1 row)
68-
69-
step wait_for_backend_exit:
63+
step wait_for_after_commit_ip:
7064
DO $$
7165
BEGIN
7266
LOOP
73-
PERFORM FROM pg_rewrite_progress;
67+
PERFORM pg_stat_clear_snapshot();
7468

75-
IF NOT FOUND THEN
69+
PERFORM
70+
FROM pg_stat_activity
71+
WHERE (wait_event_type, wait_event)=('InjectionPoint', 'pg_rewrite-after-commit');
72+
73+
IF FOUND THEN
7674
EXIT;
7775
END IF;
7876

7977
PERFORM pg_sleep(.1);
8078
END LOOP;
8179
END;
82-
$$;
83-
80+
$$
8481

8582
step check:
83+
TABLE pg_rewrite_progress;
84+
8685
SELECT i, j FROM tbl_src ORDER BY i, j;
8786

87+
src_table|dst_table|src_table_new|ins_initial|ins|upd|del
88+
---------+---------+-------------+-----------+---+---+---
89+
tbl_src |tbl_dst |tbl_src_old | 2| 4| 3| 2
90+
(1 row)
91+
8892
i|j
8993
-+-
9094
1|0
@@ -93,3 +97,16 @@ i|j
9397
7|4
9498
(4 rows)
9599

100+
step wakeup_after_commit_ip:
101+
SELECT injection_points_wakeup('pg_rewrite-after-commit');
102+
103+
injection_points_wakeup
104+
-----------------------
105+
106+
(1 row)
107+
108+
injection_points_detach
109+
-----------------------
110+
111+
(1 row)
112+

pg_rewrite.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,13 @@ rewrite_worker_main(Datum main_arg)
743743
rewrite_table_impl(relschema, relname, relname_new, relschema_dst,
744744
relname_dst);
745745
CommitTransactionCommand();
746+
747+
/*
748+
* In regression tests, use this injection point to check that
749+
* the changes are visible by other transactions.
750+
*/
751+
INJECTION_POINT("pg_rewrite-after-commit");
752+
746753
}
747754
PG_CATCH();
748755
{

specs/pg_rewrite_concurrent.spec

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ session s1
2222
setup
2323
{
2424
SELECT injection_points_attach('pg_rewrite-before-lock', 'wait');
25+
SELECT injection_points_attach('pg_rewrite-after-commit', 'wait');
2526
}
2627
# Perform the initial load and wait for s2 to do some data changes.
2728
#
@@ -30,31 +31,15 @@ setup
3031
# is who waits). Therefore use rewrite_table_nowait(), which only launches the
3132
# worker and goes on. The 'wait_for_s1_sleep' step below then checks until the
3233
# waiting started.
33-
step wait_before_lock
34+
step do_rewrite
3435
{
3536
SELECT rewrite_table_nowait('tbl_src', 'tbl_dst', 'tbl_src_old');
36-
}
37-
# Wait until the changes have been surely applied.
38-
step wait_for_backend_exit
39-
{
40-
DO $$
41-
BEGIN
42-
LOOP
43-
PERFORM FROM pg_rewrite_progress;
44-
45-
IF NOT FOUND THEN
46-
EXIT;
47-
END IF;
48-
49-
PERFORM pg_sleep(.1);
50-
END LOOP;
51-
END;
52-
$$;
53-
5437
}
5538
# Check the data.
5639
step check
5740
{
41+
TABLE pg_rewrite_progress;
42+
5843
SELECT i, j FROM tbl_src ORDER BY i, j;
5944
}
6045

@@ -63,7 +48,7 @@ session s2
6348
# does not appear to be waiting on the injection point. Instead we need to
6449
# check explicitly if the waiting on the injection point is in progress, and
6550
# wait if it's not.
66-
step wait_for_s1_sleep
51+
step wait_for_before_lock_ip
6752
{
6853
DO $$
6954
BEGIN
@@ -103,16 +88,48 @@ step do_changes
10388
-- Delete.
10489
DELETE FROM tbl_src WHERE i=4;
10590
}
106-
step wakeup_before_lock
91+
step wakeup_before_lock_ip
10792
{
10893
SELECT injection_points_wakeup('pg_rewrite-before-lock');
94+
}
95+
# Wait until the concurrent changes have been committed by the pg_rewrite
96+
# worker.
97+
step wait_for_after_commit_ip
98+
{
99+
DO $$
100+
BEGIN
101+
LOOP
102+
PERFORM pg_stat_clear_snapshot();
103+
104+
PERFORM
105+
FROM pg_stat_activity
106+
WHERE (wait_event_type, wait_event)=('InjectionPoint', 'pg_rewrite-after-commit');
107+
108+
IF FOUND THEN
109+
EXIT;
110+
END IF;
111+
112+
PERFORM pg_sleep(.1);
113+
END LOOP;
114+
END;
115+
$$
116+
}
117+
# Like wakeup_before_lock_ip above.
118+
step wakeup_after_commit_ip
119+
{
120+
SELECT injection_points_wakeup('pg_rewrite-after-commit');
121+
}
122+
teardown
123+
{
109124
SELECT injection_points_detach('pg_rewrite-before-lock');
125+
SELECT injection_points_detach('pg_rewrite-after-commit');
110126
}
111127

112128
permutation
113-
wait_before_lock
114-
wait_for_s1_sleep
129+
do_rewrite
130+
wait_for_before_lock_ip
115131
do_changes
116-
wakeup_before_lock
117-
wait_for_backend_exit
132+
wakeup_before_lock_ip
133+
wait_for_after_commit_ip
118134
check
135+
wakeup_after_commit_ip

0 commit comments

Comments
 (0)