Skip to content

Commit 0eafc54

Browse files
gayyappansvenklemm
authored andcommitted
Modify isolation test to use non-batched mode for manual refresh
Use the same mechanism as #9683 to stabilize cancel/terminate pids.
1 parent c7d565f commit 0eafc54

4 files changed

Lines changed: 53 additions & 67 deletions

File tree

tsl/test/isolation/expected/cagg_concurrent_register.out

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ step s3_lock_before_register:
1313
BEGIN; LOCK TABLE _timescaledb_catalog.continuous_aggs_jobs_refresh_ranges;
1414

1515
step s1_run_cagg1_refresh:
16-
CALL refresh_continuous_aggregate('cagg_1', '2020-01-01 00:00:00+00', '2020-01-03 00:00:00+00');
16+
CALL refresh_continuous_aggregate('cagg_1', '2020-01-01 00:00:00+00', '2020-01-03 00:00:00+00', options => jsonb_build_object('buckets_per_batch', 0));
1717
<waiting ...>
1818
step s2_run_cagg2_overlap_refresh:
19-
CALL refresh_continuous_aggregate('cagg_2', '2020-01-03 00:00:00+00', '2020-01-05 00:00:00+00');
19+
CALL refresh_continuous_aggregate('cagg_2', '2020-01-03 00:00:00+00', '2020-01-05 00:00:00+00', options => jsonb_build_object('buckets_per_batch', 0));
2020
<waiting ...>
2121
step s4_enable_before_process_cagg_invalidations:
2222
SELECT debug_waitpoint_enable('before_process_cagg_invalidations_for_refresh_lock');
@@ -39,8 +39,8 @@ step s5_show_running_jobs:
3939

4040
cagg_name| start_range| end_range|start_ts_utc |end_ts_utc
4141
---------+----------------+----------------+------------------------+------------------------
42-
cagg_1 |1577980800000000|1578009600000000|Thu Jan 02 16:00:00 2020|Fri Jan 03 00:00:00 2020
43-
cagg_2 |1578153600000000|1578182400000000|Sat Jan 04 16:00:00 2020|Sun Jan 05 00:00:00 2020
42+
cagg_1 |1577836800000000|1578009600000000|Wed Jan 01 00:00:00 2020|Fri Jan 03 00:00:00 2020
43+
cagg_2 |1578009600000000|1578182400000000|Fri Jan 03 00:00:00 2020|Sun Jan 05 00:00:00 2020
4444

4545
step s4_release_before_process_cagg_invalidations:
4646
SELECT debug_waitpoint_release('before_process_cagg_invalidations_for_refresh_lock');
@@ -66,10 +66,10 @@ step s3_lock_before_register:
6666
BEGIN; LOCK TABLE _timescaledb_catalog.continuous_aggs_jobs_refresh_ranges;
6767

6868
step s1_run_cagg2_overlap_refresh:
69-
CALL refresh_continuous_aggregate('cagg_2', '2020-01-01 00:00:00+00', '2020-01-07 00:00:00+00');
69+
CALL refresh_continuous_aggregate('cagg_2', '2020-01-01 00:00:00+00', '2020-01-07 00:00:00+00', options => jsonb_build_object('buckets_per_batch', 0));
7070
<waiting ...>
7171
step s2_run_cagg2_overlap_refresh:
72-
CALL refresh_continuous_aggregate('cagg_2', '2020-01-03 00:00:00+00', '2020-01-05 00:00:00+00');
72+
CALL refresh_continuous_aggregate('cagg_2', '2020-01-03 00:00:00+00', '2020-01-05 00:00:00+00', options => jsonb_build_object('buckets_per_batch', 0));
7373
<waiting ...>
7474
step s4_enable_before_process_cagg_invalidations:
7575
SELECT debug_waitpoint_enable('before_process_cagg_invalidations_for_refresh_lock');
@@ -92,15 +92,14 @@ step s5_show_running_jobs:
9292

9393
cagg_name| start_range| end_range|start_ts_utc |end_ts_utc
9494
---------+----------------+----------------+------------------------+------------------------
95-
cagg_2 |1578153600000000|1578182400000000|Sat Jan 04 16:00:00 2020|Sun Jan 05 00:00:00 2020
96-
cagg_2 |1578268800000000|1578355200000000|Mon Jan 06 00:00:00 2020|Tue Jan 07 00:00:00 2020
95+
cagg_2 |1577836800000000|1578355200000000|Wed Jan 01 00:00:00 2020|Tue Jan 07 00:00:00 2020
9796

9897
step s4_release_before_process_cagg_invalidations:
9998
SELECT debug_waitpoint_release('before_process_cagg_invalidations_for_refresh_lock');
10099
<waiting ...>
101100
step s1_run_cagg2_overlap_refresh: <... completed>
102-
ERROR: could not refresh continuous aggregate "cagg_2" due to a concurrent refresh
103101
step s2_run_cagg2_overlap_refresh: <... completed>
102+
ERROR: could not refresh continuous aggregate "cagg_2" due to a concurrent refresh
104103
step s4_release_before_process_cagg_invalidations: <... completed>
105104
debug_waitpoint_release
106105
-----------------------
@@ -123,7 +122,7 @@ step s1_run_cagg2_nonoverlap_refresh:
123122
CALL refresh_continuous_aggregate('cagg_2', '2020-01-01 00:00:00+00', '2020-01-02 00:00:00+00');
124123
<waiting ...>
125124
step s2_run_cagg2_overlap_refresh:
126-
CALL refresh_continuous_aggregate('cagg_2', '2020-01-03 00:00:00+00', '2020-01-05 00:00:00+00');
125+
CALL refresh_continuous_aggregate('cagg_2', '2020-01-03 00:00:00+00', '2020-01-05 00:00:00+00', options => jsonb_build_object('buckets_per_batch', 0));
127126
<waiting ...>
128127
step s4_enable_before_process_cagg_invalidations:
129128
SELECT debug_waitpoint_enable('before_process_cagg_invalidations_for_refresh_lock');
@@ -147,7 +146,7 @@ step s5_show_running_jobs:
147146
cagg_name| start_range| end_range|start_ts_utc |end_ts_utc
148147
---------+----------------+----------------+------------------------+------------------------
149148
cagg_2 |1577836800000000|1577923200000000|Wed Jan 01 00:00:00 2020|Thu Jan 02 00:00:00 2020
150-
cagg_2 |1578153600000000|1578182400000000|Sat Jan 04 16:00:00 2020|Sun Jan 05 00:00:00 2020
149+
cagg_2 |1578009600000000|1578182400000000|Fri Jan 03 00:00:00 2020|Sun Jan 05 00:00:00 2020
151150

152151
step s4_release_before_process_cagg_invalidations:
153152
SELECT debug_waitpoint_release('before_process_cagg_invalidations_for_refresh_lock');

tsl/test/isolation/expected/cagg_refresh_cleanup_register.out

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ debug_waitpoint_enable
77

88

99
step R2_refresh:
10-
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-02-15');
10+
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-02-15', options => jsonb_build_object('buckets_per_batch', 0));
1111
<waiting ...>
1212
step L1_lock:
1313
BEGIN;
@@ -20,10 +20,10 @@ debug_waitpoint_release
2020

2121

2222
step R3_refresh:
23-
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15');
23+
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15', options => jsonb_build_object('buckets_per_batch', 0));
2424
<waiting ...>
2525
step R4_refresh:
26-
CALL refresh_continuous_aggregate('cond_daily', '2026-03-15', '2026-03-30');
26+
CALL refresh_continuous_aggregate('cond_daily', '2026-03-15', '2026-03-30', options => jsonb_build_object('buckets_per_batch', 0));
2727
<waiting ...>
2828
step check_locks:
2929
SELECT l.mode, l.granted
@@ -50,7 +50,7 @@ step check_jobs:
5050

5151
user_view_name|start_time |end_time
5252
--------------+----------------------------+----------------------------
53-
cond_daily |Sun Feb 08 16:00:00 2026 PST|Sat Feb 14 16:00:00 2026 PST
53+
cond_daily |Mon Jan 05 16:00:00 2026 PST|Sat Feb 14 16:00:00 2026 PST
5454

5555
step L1_unlock:
5656
COMMIT;
@@ -89,7 +89,7 @@ debug_waitpoint_enable
8989

9090

9191
step R2_refresh:
92-
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-02-15');
92+
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-02-15', options => jsonb_build_object('buckets_per_batch', 0));
9393
<waiting ...>
9494
step L1_lock:
9595
BEGIN;
@@ -102,10 +102,10 @@ debug_waitpoint_release
102102

103103

104104
step R3_refresh:
105-
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15');
105+
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15', options => jsonb_build_object('buckets_per_batch', 0));
106106
<waiting ...>
107107
step R4_overlapping_refresh:
108-
CALL refresh_continuous_aggregate('cond_daily', '2026-03-01', '2026-03-15');
108+
CALL refresh_continuous_aggregate('cond_daily', '2026-03-01', '2026-03-15', options => jsonb_build_object('buckets_per_batch', 0));
109109
<waiting ...>
110110
step check_locks:
111111
SELECT l.mode, l.granted
@@ -132,7 +132,7 @@ step check_jobs:
132132

133133
user_view_name|start_time |end_time
134134
--------------+----------------------------+----------------------------
135-
cond_daily |Sun Feb 08 16:00:00 2026 PST|Sat Feb 14 16:00:00 2026 PST
135+
cond_daily |Mon Jan 05 16:00:00 2026 PST|Sat Feb 14 16:00:00 2026 PST
136136

137137
step L1_unlock:
138138
COMMIT;
@@ -172,7 +172,7 @@ debug_waitpoint_enable
172172

173173

174174
step R3_refresh:
175-
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15');
175+
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15', options => jsonb_build_object('buckets_per_batch', 0));
176176
<waiting ...>
177177
step check_jobs:
178178
SELECT ca.user_view_name,
@@ -185,7 +185,7 @@ step check_jobs:
185185

186186
user_view_name|start_time |end_time
187187
--------------+----------------------------+----------------------------
188-
cond_daily |Sat Mar 07 16:00:00 2026 PST|Sat Mar 14 17:00:00 2026 PDT
188+
cond_daily |Sun Feb 15 16:00:00 2026 PST|Sat Mar 14 17:00:00 2026 PDT
189189

190190
step A1_revoke_perm:
191191
REVOKE SELECT on conditions FROM cagg_user;
@@ -217,7 +217,7 @@ debug_waitpoint_enable
217217

218218

219219
step R3_refresh:
220-
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15');
220+
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15', options => jsonb_build_object('buckets_per_batch', 0));
221221
<waiting ...>
222222
step check_jobs:
223223
SELECT ca.user_view_name,
@@ -230,7 +230,7 @@ step check_jobs:
230230

231231
user_view_name|start_time |end_time
232232
--------------+----------------------------+----------------------------
233-
cond_daily |Sat Mar 07 16:00:00 2026 PST|Sat Mar 14 17:00:00 2026 PDT
233+
cond_daily |Sun Feb 15 16:00:00 2026 PST|Sat Mar 14 17:00:00 2026 PDT
234234

235235
step A1_revoke_mat_perm:
236236
DO $$
@@ -273,7 +273,7 @@ debug_waitpoint_enable
273273

274274

275275
step R2_refresh:
276-
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-02-15');
276+
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-02-15', options => jsonb_build_object('buckets_per_batch', 0));
277277
<waiting ...>
278278
step check_jobs_metadata_manual:
279279
SELECT ca.user_view_name,
@@ -352,7 +352,7 @@ debug_waitpoint_enable
352352

353353

354354
step R1_refresh:
355-
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-03-15');
355+
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-03-15', options => jsonb_build_object('buckets_per_batch', 0));
356356
<waiting ...>
357357
step check_jobs:
358358
SELECT ca.user_view_name,
@@ -365,24 +365,11 @@ step check_jobs:
365365

366366
user_view_name|start_time |end_time
367367
--------------+----------------------------+----------------------------
368-
cond_daily |Tue Mar 10 17:00:00 2026 PDT|Sat Mar 14 17:00:00 2026 PDT
368+
cond_daily |Mon Jan 05 16:00:00 2026 PST|Sat Mar 14 17:00:00 2026 PDT
369369

370370
step K1_terminate:
371-
DO $$
372-
DECLARE
373-
target_pid int;
374-
BEGIN
375-
SELECT pid INTO target_pid FROM cancelpid;
376-
PERFORM pg_terminate_backend(target_pid);
377-
LOOP
378-
EXIT WHEN NOT EXISTS (
379-
SELECT 1 FROM pg_stat_activity WHERE pid = target_pid
380-
);
381-
PERFORM pg_sleep(0.05);
382-
END LOOP;
383-
END;
384-
$$;
385-
371+
CALL terminate_r1();
372+
<waiting ...>
386373
step R1_refresh: <... completed>
387374
FATAL: terminating connection due to administrator command
388375
server closed the connection unexpectedly
@@ -394,16 +381,17 @@ debug_waitpoint_release
394381
-----------------------
395382

396383

384+
step K1_terminate: <... completed>
397385
step L1_lock:
398386
BEGIN;
399387
LOCK TABLE _timescaledb_catalog.continuous_aggs_jobs_refresh_ranges
400388
IN ACCESS EXCLUSIVE MODE;
401389

402390
step R2_refresh:
403-
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-02-15');
391+
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-02-15', options => jsonb_build_object('buckets_per_batch', 0));
404392
<waiting ...>
405393
step R3_refresh:
406-
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15');
394+
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15', options => jsonb_build_object('buckets_per_batch', 0));
407395
<waiting ...>
408396
step L1_unlock:
409397
COMMIT;

tsl/test/isolation/specs/cagg_concurrent_register.spec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ teardown {
6464

6565
session "S1"
6666
step "s1_run_cagg1_refresh" {
67-
CALL refresh_continuous_aggregate('cagg_1', '2020-01-01 00:00:00+00', '2020-01-03 00:00:00+00');
67+
CALL refresh_continuous_aggregate('cagg_1', '2020-01-01 00:00:00+00', '2020-01-03 00:00:00+00', options => jsonb_build_object('buckets_per_batch', 0));
6868
}
6969
step "s1_run_cagg2_overlap_refresh" {
70-
CALL refresh_continuous_aggregate('cagg_2', '2020-01-01 00:00:00+00', '2020-01-07 00:00:00+00');
70+
CALL refresh_continuous_aggregate('cagg_2', '2020-01-01 00:00:00+00', '2020-01-07 00:00:00+00', options => jsonb_build_object('buckets_per_batch', 0));
7171
}
7272
step "s1_run_cagg2_nonoverlap_refresh" {
7373
CALL refresh_continuous_aggregate('cagg_2', '2020-01-01 00:00:00+00', '2020-01-02 00:00:00+00');
@@ -76,7 +76,7 @@ step "s1_run_cagg2_nonoverlap_refresh" {
7676
session "S2"
7777

7878
step "s2_run_cagg2_overlap_refresh" {
79-
CALL refresh_continuous_aggregate('cagg_2', '2020-01-03 00:00:00+00', '2020-01-05 00:00:00+00');
79+
CALL refresh_continuous_aggregate('cagg_2', '2020-01-03 00:00:00+00', '2020-01-05 00:00:00+00', options => jsonb_build_object('buckets_per_batch', 0));
8080
}
8181

8282
step "s2_insert_new_data_2020" {

tsl/test/isolation/specs/cagg_refresh_cleanup_register.spec

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ setup
1818
-- Table used to pass R1's backend PID to the terminator session
1919
CREATE TABLE cancelpid (pid int);
2020

21+
-- Terminate R1's backend. Wrapped in a void-returning procedure (as in
22+
-- cagg_cancel_kill_refresh.spec) so isolationtester's native blocked-step
23+
-- synchronization can be used instead of polling pg_stat_activity.
24+
CREATE OR REPLACE PROCEDURE terminate_r1() AS
25+
$$
26+
BEGIN
27+
PERFORM pg_terminate_backend(pid) FROM cancelpid;
28+
END;
29+
$$ LANGUAGE plpgsql;
30+
2131
CREATE MATERIALIZED VIEW cond_daily
2232
WITH (timescaledb.continuous, timescaledb.materialized_only = true) AS
2333
SELECT time_bucket('1 day', time) AS bucket, avg(value) AS avg_val
@@ -59,7 +69,7 @@ setup {
5969
INSERT INTO cancelpid SELECT pg_backend_pid();
6070
}
6171
step "R1_refresh" {
62-
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-03-15');
72+
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-03-15', options => jsonb_build_object('buckets_per_batch', 0));
6373
}
6474

6575
# Session WP: enables / disables waitpoints
@@ -76,23 +86,12 @@ step "WP_after_register_enable" { SELECT debug_waitpoint_enable('cagg_refresh_a
7686
step "WP_after_register_disable" { SELECT debug_waitpoint_release('cagg_refresh_after_register'); }
7787

7888
# Session K1: terminate R1's backend so its PID becomes dead in the
79-
# registration table, then wait until the process is gone.
89+
# registration table. Relies on isolationtester's native blocked-step
90+
# synchronization (see the "K1_terminate"("R1_refresh") annotation below)
91+
# rather than polling pg_stat_activity for the pid to disappear.
8092
session "K1"
8193
step "K1_terminate" {
82-
DO $$
83-
DECLARE
84-
target_pid int;
85-
BEGIN
86-
SELECT pid INTO target_pid FROM cancelpid;
87-
PERFORM pg_terminate_backend(target_pid);
88-
LOOP
89-
EXIT WHEN NOT EXISTS (
90-
SELECT 1 FROM pg_stat_activity WHERE pid = target_pid
91-
);
92-
PERFORM pg_sleep(0.05);
93-
END LOOP;
94-
END;
95-
$$;
94+
CALL terminate_r1();
9695
}
9796

9897
# Refresh sessions
@@ -102,7 +101,7 @@ setup {
102101
SET SESSION lock_timeout = '2s';
103102
}
104103
step "R2_refresh" {
105-
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-02-15');
104+
CALL refresh_continuous_aggregate('cond_daily', '2026-01-05', '2026-02-15', options => jsonb_build_object('buckets_per_batch', 0));
106105
}
107106

108107
session "R3"
@@ -111,7 +110,7 @@ setup {
111110
SET SESSION lock_timeout = '2s';
112111
}
113112
step "R3_refresh" {
114-
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15');
113+
CALL refresh_continuous_aggregate('cond_daily', '2026-02-15', '2026-03-15', options => jsonb_build_object('buckets_per_batch', 0));
115114
}
116115

117116
session "R4"
@@ -120,10 +119,10 @@ setup {
120119
SET SESSION lock_timeout = '2s';
121120
}
122121
step "R4_refresh" {
123-
CALL refresh_continuous_aggregate('cond_daily', '2026-03-15', '2026-03-30');
122+
CALL refresh_continuous_aggregate('cond_daily', '2026-03-15', '2026-03-30', options => jsonb_build_object('buckets_per_batch', 0));
124123
}
125124
step "R4_overlapping_refresh" {
126-
CALL refresh_continuous_aggregate('cond_daily', '2026-03-01', '2026-03-15');
125+
CALL refresh_continuous_aggregate('cond_daily', '2026-03-01', '2026-03-15', options => jsonb_build_object('buckets_per_batch', 0));
127126
}
128127

129128
session "A1"
@@ -241,4 +240,4 @@ permutation "P1_add_policy" "WP_after_register_enable" "P1_run_policy" "check_jo
241240
# Stale registration cleanup by concurrent refreshes.
242241
# Kill a backend during refresh to end up with a pid left behind. Later two concurrent refreshes run, only one removes the stale pid.
243242
# backend R1 is killed, we can no longer use this for later permutations
244-
permutation "WP_before_txn2_commit_enable" "R1_refresh" "check_jobs" "K1_terminate"("check_jobs") "WP_before_txn2_commit_disable" "L1_lock" "R2_refresh"("L1_lock") "R3_refresh"("R2_refresh") "L1_unlock"(R2_refresh, R3_refresh) "check_jobs"
243+
permutation "WP_before_txn2_commit_enable" "R1_refresh" "check_jobs" "K1_terminate"("R1_refresh") "WP_before_txn2_commit_disable" "L1_lock" "R2_refresh"("L1_lock") "R3_refresh"("R2_refresh") "L1_unlock"(R2_refresh, R3_refresh) "check_jobs"

0 commit comments

Comments
 (0)