Skip to content

Commit c64dcc7

Browse files
author
Amit Kapila
committed
Fix test case added by commit f5fc2f5.
In the new test after resetting the stats, we were not waiting for the stats message to be delivered. Also, we need to decode the results for the new test, otherwise, it will show the old stats. In passing, a. Change docs added by commit f5fc2f5 as per suggestion by Justin Pryzby. b. Bump the PGSTAT_FILE_FORMAT_ID as commit f5fc2f5 changes the file format of stats. Reported-by: Tom Lane based on buildfarm reports Author: Vignesh C, Justin Pryzby Reviewed-by: Amit Kapila Discussion: https://postgr.es/m/20210319185247.ldebgpdaxsowiflw@alap3.anarazel.de
1 parent 7ef8b52 commit c64dcc7

File tree

4 files changed

+55
-32
lines changed

4 files changed

+55
-32
lines changed

contrib/test_decoding/expected/stats.out

+38-19
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,34 @@ BEGIN
5151
extract(epoch from clock_timestamp() - start_time);
5252
END
5353
$$ LANGUAGE plpgsql;
54-
-- spilling the xact
55-
BEGIN;
56-
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
57-
COMMIT;
58-
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
54+
-- non-spilled xact
55+
INSERT INTO stats_test values(1);
56+
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
5957
count
6058
-------
61-
5002
59+
3
6260
(1 row)
6361

64-
-- Check stats, wait for the stats collector to update. We can't test the
65-
-- exact stats count as that can vary if any background transaction (say by
66-
-- autovacuum) happens in parallel to the main transaction.
67-
SELECT wait_for_decode_stats(false, true);
62+
SELECT wait_for_decode_stats(false, false);
6863
wait_for_decode_stats
6964
-----------------------
7065

7166
(1 row)
7267

73-
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;
68+
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;
7469
slot_name | spill_txns | spill_count | total_txns | total_bytes
7570
-----------------+------------+-------------+------------+-------------
7671
regression_slot | t | t | t | t
7772
(1 row)
7873

79-
-- reset the slot stats, and wait for stats collector to reset
74+
-- reset the slot stats, and wait for stats collector's total txn to reset
8075
SELECT pg_stat_reset_replication_slot('regression_slot');
8176
pg_stat_reset_replication_slot
8277
--------------------------------
8378

8479
(1 row)
8580

86-
SELECT wait_for_decode_stats(true, true);
81+
SELECT wait_for_decode_stats(true, false);
8782
wait_for_decode_stats
8883
-----------------------
8984

@@ -95,13 +90,19 @@ SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_
9590
regression_slot | 0 | 0 | 0 | 0
9691
(1 row)
9792

98-
-- decode and check stats again.
93+
-- spilling the xact
94+
BEGIN;
95+
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
96+
COMMIT;
9997
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
10098
count
10199
-------
102100
5002
103101
(1 row)
104102

103+
-- Check stats, wait for the stats collector to update. We can't test the
104+
-- exact stats count as that can vary if any background transaction (say by
105+
-- autovacuum) happens in parallel to the main transaction.
105106
SELECT wait_for_decode_stats(false, true);
106107
wait_for_decode_stats
107108
-----------------------
@@ -114,24 +115,42 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
114115
regression_slot | t | t | t | t
115116
(1 row)
116117

118+
-- reset the slot stats, and wait for stats collector to reset
117119
SELECT pg_stat_reset_replication_slot('regression_slot');
118120
pg_stat_reset_replication_slot
119121
--------------------------------
120122

121123
(1 row)
122124

123-
-- non-spilled xact
124-
INSERT INTO stats_test values(generate_series(1, 10));
125-
SELECT wait_for_decode_stats(false, false);
125+
SELECT wait_for_decode_stats(true, true);
126126
wait_for_decode_stats
127127
-----------------------
128128

129129
(1 row)
130130

131-
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;
131+
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
132132
slot_name | spill_txns | spill_count | total_txns | total_bytes
133133
-----------------+------------+-------------+------------+-------------
134-
regression_slot | f | f | t | t
134+
regression_slot | 0 | 0 | 0 | 0
135+
(1 row)
136+
137+
-- decode and check stats again.
138+
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
139+
count
140+
-------
141+
5002
142+
(1 row)
143+
144+
SELECT wait_for_decode_stats(false, true);
145+
wait_for_decode_stats
146+
-----------------------
147+
148+
(1 row)
149+
150+
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
135154
(1 row)
136155

137156
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See

contrib/test_decoding/sql/stats.sql

+11-7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ BEGIN
5050
END
5151
$$ LANGUAGE plpgsql;
5252

53+
-- non-spilled xact
54+
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 wait_for_decode_stats(false, false);
57+
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;
58+
59+
-- reset the slot stats, and wait for stats collector's total txn to reset
60+
SELECT pg_stat_reset_replication_slot('regression_slot');
61+
SELECT wait_for_decode_stats(true, false);
62+
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
63+
5364
-- spilling the xact
5465
BEGIN;
5566
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
@@ -72,13 +83,6 @@ SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL,
7283
SELECT wait_for_decode_stats(false, true);
7384
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;
7485

75-
SELECT pg_stat_reset_replication_slot('regression_slot');
76-
77-
-- non-spilled xact
78-
INSERT INTO stats_test values(generate_series(1, 10));
79-
SELECT wait_for_decode_stats(false, false);
80-
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;
81-
8286
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
8387
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
8488
BEGIN;

doc/src/sgml/monitoring.sgml

+5-5
Original file line numberDiff line numberDiff line change
@@ -2722,9 +2722,9 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
27222722
</para>
27232723
<para>
27242724
Number of decoded transactions sent to the decoding output plugin for
2725-
this slot. This counter is used to maintain the top level transactions,
2726-
so the counter is not incremented for subtransactions. Note that this
2727-
includes the transactions that are streamed and/or spilled.
2725+
this slot. This counts toplevel transactions only, and is not incremented
2726+
for subtransactions. Note that this includes the transactions that are
2727+
streamed and/or spilled.
27282728
</para></entry>
27292729
</row>
27302730

@@ -2733,10 +2733,10 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
27332733
<structfield>total_bytes</structfield><type>bigint</type>
27342734
</para>
27352735
<para>
2736-
Amount of decoded transactions data sent to the decoding output plugin
2736+
Amount of decoded transaction data sent to the decoding output plugin
27372737
while decoding the changes from WAL for this slot. This can be used to
27382738
gauge the total amount of data sent during logical decoding. Note that
2739-
this includes the data that is streamed and/or spilled.
2739+
this includes data that is streamed and/or spilled.
27402740
</para>
27412741
</entry>
27422742
</row>

src/include/pgstat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ typedef union PgStat_Msg
744744
* ------------------------------------------------------------
745745
*/
746746

747-
#define PGSTAT_FILE_FORMAT_ID 0x01A5BCA1
747+
#define PGSTAT_FILE_FORMAT_ID 0x01A5BCA2
748748

749749
/* ----------
750750
* PgStat_StatDBEntry The collector's data per database

0 commit comments

Comments
 (0)