Skip to content

Commit 51ef917

Browse files
author
Amit Kapila
committed
Another try to fix the test case added by commit f5fc2f5.
As per analysis, it appears that the 'drop slot' message from the previous test and 'create slot' message of the new test are either missed or not yet delivered to the stats collector due to which we will still see the stats from the old slot. This can happen rarely which could be the reason that we are seeing some failures in the buildfarm randomly. To avoid that we are using a different slot name for the tests in test_decoding/sql/stats.sql. Reported-by: Tom Lane based on buildfarm reports Author: Sawada Masahiko Reviewed-by: Amit Kapila, Vignesh C Discussion: https://postgr.es/m/20210319185247.ldebgpdaxsowiflw@alap3.anarazel.de
1 parent c9c37ae commit 51ef917

File tree

2 files changed

+43
-39
lines changed

2 files changed

+43
-39
lines changed

contrib/test_decoding/expected/stats.out

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- predictability
22
SET synchronous_commit = on;
3-
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
3+
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_stats', 'test_decoding');
44
?column?
55
----------
66
init
@@ -23,7 +23,7 @@ BEGIN
2323
ELSE (spill_txns > 0)
2424
END
2525
INTO updated
26-
FROM pg_stat_replication_slots WHERE slot_name='regression_slot';
26+
FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats';
2727

2828
ELSE
2929

@@ -32,7 +32,7 @@ BEGIN
3232
ELSE (total_txns > 0)
3333
END
3434
INTO updated
35-
FROM pg_stat_replication_slots WHERE slot_name='regression_slot';
35+
FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats';
3636

3737
END IF;
3838

@@ -52,8 +52,9 @@ BEGIN
5252
END
5353
$$ LANGUAGE plpgsql;
5454
-- non-spilled xact
55+
SET logical_decoding_work_mem to '64MB';
5556
INSERT INTO stats_test values(1);
56-
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
57+
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
5758
count
5859
-------
5960
3
@@ -66,13 +67,14 @@ SELECT wait_for_decode_stats(false, false);
6667
(1 row)
6768

6869
SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots;
69-
slot_name | spill_txns | spill_count | total_txns | total_bytes
70-
-----------------+------------+-------------+------------+-------------
71-
regression_slot | t | t | t | t
70+
slot_name | spill_txns | spill_count | total_txns | total_bytes
71+
-----------------------+------------+-------------+------------+-------------
72+
regression_slot_stats | t | t | t | t
7273
(1 row)
7374

75+
RESET logical_decoding_work_mem;
7476
-- reset the slot stats, and wait for stats collector's total txn to reset
75-
SELECT pg_stat_reset_replication_slot('regression_slot');
77+
SELECT pg_stat_reset_replication_slot('regression_slot_stats');
7678
pg_stat_reset_replication_slot
7779
--------------------------------
7880

@@ -85,16 +87,16 @@ SELECT wait_for_decode_stats(true, false);
8587
(1 row)
8688

8789
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
88-
slot_name | spill_txns | spill_count | total_txns | total_bytes
89-
-----------------+------------+-------------+------------+-------------
90-
regression_slot | 0 | 0 | 0 | 0
90+
slot_name | spill_txns | spill_count | total_txns | total_bytes
91+
-----------------------+------------+-------------+------------+-------------
92+
regression_slot_stats | 0 | 0 | 0 | 0
9193
(1 row)
9294

9395
-- spilling the xact
9496
BEGIN;
9597
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
9698
COMMIT;
97-
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
99+
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
98100
count
99101
-------
100102
5002
@@ -110,13 +112,13 @@ SELECT wait_for_decode_stats(false, true);
110112
(1 row)
111113

112114
SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots;
113-
slot_name | spill_txns | spill_count | total_txns | total_bytes
114-
-----------------+------------+-------------+------------+-------------
115-
regression_slot | t | t | t | t
115+
slot_name | spill_txns | spill_count | total_txns | total_bytes
116+
-----------------------+------------+-------------+------------+-------------
117+
regression_slot_stats | t | t | t | t
116118
(1 row)
117119

118120
-- reset the slot stats, and wait for stats collector to reset
119-
SELECT pg_stat_reset_replication_slot('regression_slot');
121+
SELECT pg_stat_reset_replication_slot('regression_slot_stats');
120122
pg_stat_reset_replication_slot
121123
--------------------------------
122124

@@ -129,13 +131,13 @@ SELECT wait_for_decode_stats(true, true);
129131
(1 row)
130132

131133
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
132-
slot_name | spill_txns | spill_count | total_txns | total_bytes
133-
-----------------+------------+-------------+------------+-------------
134-
regression_slot | 0 | 0 | 0 | 0
134+
slot_name | spill_txns | spill_count | total_txns | total_bytes
135+
-----------------------+------------+-------------+------------+-------------
136+
regression_slot_stats | 0 | 0 | 0 | 0
135137
(1 row)
136138

137139
-- decode and check stats again.
138-
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
140+
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
139141
count
140142
-------
141143
5002
@@ -148,30 +150,30 @@ SELECT wait_for_decode_stats(false, true);
148150
(1 row)
149151

150152
SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots;
151-
slot_name | spill_txns | spill_count | total_txns | total_bytes
152-
-----------------+------------+-------------+------------+-------------
153-
regression_slot | t | t | t | t
153+
slot_name | spill_txns | spill_count | total_txns | total_bytes
154+
-----------------------+------------+-------------+------------+-------------
155+
regression_slot_stats | t | t | t | t
154156
(1 row)
155157

156158
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
157159
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
158160
BEGIN;
159161
SELECT slot_name FROM pg_stat_replication_slots;
160-
slot_name
161-
-----------------
162-
regression_slot
162+
slot_name
163+
-----------------------
164+
regression_slot_stats
163165
(1 row)
164166

165167
SELECT slot_name FROM pg_stat_replication_slots;
166-
slot_name
167-
-----------------
168-
regression_slot
168+
slot_name
169+
-----------------------
170+
regression_slot_stats
169171
(1 row)
170172

171173
COMMIT;
172174
DROP FUNCTION wait_for_decode_stats(bool, bool);
173175
DROP TABLE stats_test;
174-
SELECT pg_drop_replication_slot('regression_slot');
176+
SELECT pg_drop_replication_slot('regression_slot_stats');
175177
pg_drop_replication_slot
176178
--------------------------
177179

contrib/test_decoding/sql/stats.sql

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- predictability
22
SET synchronous_commit = on;
33

4-
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
4+
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_stats', 'test_decoding');
55

66
CREATE TABLE stats_test(data text);
77

@@ -21,7 +21,7 @@ BEGIN
2121
ELSE (spill_txns > 0)
2222
END
2323
INTO updated
24-
FROM pg_stat_replication_slots WHERE slot_name='regression_slot';
24+
FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats';
2525

2626
ELSE
2727

@@ -30,7 +30,7 @@ BEGIN
3030
ELSE (total_txns > 0)
3131
END
3232
INTO updated
33-
FROM pg_stat_replication_slots WHERE slot_name='regression_slot';
33+
FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats';
3434

3535
END IF;
3636

@@ -51,21 +51,23 @@ END
5151
$$ LANGUAGE plpgsql;
5252

5353
-- non-spilled xact
54+
SET logical_decoding_work_mem to '64MB';
5455
INSERT INTO stats_test values(1);
55-
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
56+
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
5657
SELECT wait_for_decode_stats(false, false);
5758
SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots;
59+
RESET logical_decoding_work_mem;
5860

5961
-- reset the slot stats, and wait for stats collector's total txn to reset
60-
SELECT pg_stat_reset_replication_slot('regression_slot');
62+
SELECT pg_stat_reset_replication_slot('regression_slot_stats');
6163
SELECT wait_for_decode_stats(true, false);
6264
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
6365

6466
-- spilling the xact
6567
BEGIN;
6668
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
6769
COMMIT;
68-
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
70+
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
6971

7072
-- Check stats, wait for the stats collector to update. We can't test the
7173
-- exact stats count as that can vary if any background transaction (say by
@@ -74,12 +76,12 @@ SELECT wait_for_decode_stats(false, true);
7476
SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots;
7577

7678
-- reset the slot stats, and wait for stats collector to reset
77-
SELECT pg_stat_reset_replication_slot('regression_slot');
79+
SELECT pg_stat_reset_replication_slot('regression_slot_stats');
7880
SELECT wait_for_decode_stats(true, true);
7981
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
8082

8183
-- decode and check stats again.
82-
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
84+
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
8385
SELECT wait_for_decode_stats(false, true);
8486
SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots;
8587

@@ -92,4 +94,4 @@ COMMIT;
9294

9395
DROP FUNCTION wait_for_decode_stats(bool, bool);
9496
DROP TABLE stats_test;
95-
SELECT pg_drop_replication_slot('regression_slot');
97+
SELECT pg_drop_replication_slot('regression_slot_stats');

0 commit comments

Comments
 (0)