1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-22 23:02:54 +03:00

Another try to fix the test case added by commit f5fc2f5b23.

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
This commit is contained in:
Amit Kapila 2021-04-30 07:55:42 +05:30
parent c9c37ae03f
commit 51ef917303
2 changed files with 43 additions and 39 deletions

View File

@ -1,6 +1,6 @@
-- predictability -- predictability
SET synchronous_commit = on; SET synchronous_commit = on;
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_stats', 'test_decoding');
?column? ?column?
---------- ----------
init init
@ -23,7 +23,7 @@ BEGIN
ELSE (spill_txns > 0) ELSE (spill_txns > 0)
END END
INTO updated INTO updated
FROM pg_stat_replication_slots WHERE slot_name='regression_slot'; FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats';
ELSE ELSE
@ -32,7 +32,7 @@ BEGIN
ELSE (total_txns > 0) ELSE (total_txns > 0)
END END
INTO updated INTO updated
FROM pg_stat_replication_slots WHERE slot_name='regression_slot'; FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats';
END IF; END IF;
@ -52,8 +52,9 @@ BEGIN
END END
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql;
-- non-spilled xact -- non-spilled xact
SET logical_decoding_work_mem to '64MB';
INSERT INTO stats_test values(1); INSERT INTO stats_test values(1);
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1'); SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
count count
------- -------
3 3
@ -67,12 +68,13 @@ SELECT wait_for_decode_stats(false, false);
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; 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;
slot_name | spill_txns | spill_count | total_txns | total_bytes slot_name | spill_txns | spill_count | total_txns | total_bytes
-----------------+------------+-------------+------------+------------- -----------------------+------------+-------------+------------+-------------
regression_slot | t | t | t | t regression_slot_stats | t | t | t | t
(1 row) (1 row)
RESET logical_decoding_work_mem;
-- reset the slot stats, and wait for stats collector's total txn to reset -- reset the slot stats, and wait for stats collector's total txn to reset
SELECT pg_stat_reset_replication_slot('regression_slot'); SELECT pg_stat_reset_replication_slot('regression_slot_stats');
pg_stat_reset_replication_slot pg_stat_reset_replication_slot
-------------------------------- --------------------------------
@ -86,15 +88,15 @@ SELECT wait_for_decode_stats(true, false);
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots; SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
slot_name | spill_txns | spill_count | total_txns | total_bytes slot_name | spill_txns | spill_count | total_txns | total_bytes
-----------------+------------+-------------+------------+------------- -----------------------+------------+-------------+------------+-------------
regression_slot | 0 | 0 | 0 | 0 regression_slot_stats | 0 | 0 | 0 | 0
(1 row) (1 row)
-- spilling the xact -- spilling the xact
BEGIN; BEGIN;
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i); INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
COMMIT; COMMIT;
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1'); SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
count count
------- -------
5002 5002
@ -111,12 +113,12 @@ SELECT wait_for_decode_stats(false, true);
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; 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;
slot_name | spill_txns | spill_count | total_txns | total_bytes slot_name | spill_txns | spill_count | total_txns | total_bytes
-----------------+------------+-------------+------------+------------- -----------------------+------------+-------------+------------+-------------
regression_slot | t | t | t | t regression_slot_stats | t | t | t | t
(1 row) (1 row)
-- reset the slot stats, and wait for stats collector to reset -- reset the slot stats, and wait for stats collector to reset
SELECT pg_stat_reset_replication_slot('regression_slot'); SELECT pg_stat_reset_replication_slot('regression_slot_stats');
pg_stat_reset_replication_slot pg_stat_reset_replication_slot
-------------------------------- --------------------------------
@ -130,12 +132,12 @@ SELECT wait_for_decode_stats(true, true);
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots; SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
slot_name | spill_txns | spill_count | total_txns | total_bytes slot_name | spill_txns | spill_count | total_txns | total_bytes
-----------------+------------+-------------+------------+------------- -----------------------+------------+-------------+------------+-------------
regression_slot | 0 | 0 | 0 | 0 regression_slot_stats | 0 | 0 | 0 | 0
(1 row) (1 row)
-- decode and check stats again. -- decode and check stats again.
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1'); SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
count count
------- -------
5002 5002
@ -149,8 +151,8 @@ SELECT wait_for_decode_stats(false, true);
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; 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;
slot_name | spill_txns | spill_count | total_txns | total_bytes slot_name | spill_txns | spill_count | total_txns | total_bytes
-----------------+------------+-------------+------------+------------- -----------------------+------------+-------------+------------+-------------
regression_slot | t | t | t | t regression_slot_stats | t | t | t | t
(1 row) (1 row)
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See -- Ensure stats can be repeatedly accessed using the same stats snapshot. See
@ -158,20 +160,20 @@ SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count,
BEGIN; BEGIN;
SELECT slot_name FROM pg_stat_replication_slots; SELECT slot_name FROM pg_stat_replication_slots;
slot_name slot_name
----------------- -----------------------
regression_slot regression_slot_stats
(1 row) (1 row)
SELECT slot_name FROM pg_stat_replication_slots; SELECT slot_name FROM pg_stat_replication_slots;
slot_name slot_name
----------------- -----------------------
regression_slot regression_slot_stats
(1 row) (1 row)
COMMIT; COMMIT;
DROP FUNCTION wait_for_decode_stats(bool, bool); DROP FUNCTION wait_for_decode_stats(bool, bool);
DROP TABLE stats_test; DROP TABLE stats_test;
SELECT pg_drop_replication_slot('regression_slot'); SELECT pg_drop_replication_slot('regression_slot_stats');
pg_drop_replication_slot pg_drop_replication_slot
-------------------------- --------------------------

View File

@ -1,7 +1,7 @@
-- predictability -- predictability
SET synchronous_commit = on; SET synchronous_commit = on;
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_stats', 'test_decoding');
CREATE TABLE stats_test(data text); CREATE TABLE stats_test(data text);
@ -21,7 +21,7 @@ BEGIN
ELSE (spill_txns > 0) ELSE (spill_txns > 0)
END END
INTO updated INTO updated
FROM pg_stat_replication_slots WHERE slot_name='regression_slot'; FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats';
ELSE ELSE
@ -30,7 +30,7 @@ BEGIN
ELSE (total_txns > 0) ELSE (total_txns > 0)
END END
INTO updated INTO updated
FROM pg_stat_replication_slots WHERE slot_name='regression_slot'; FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats';
END IF; END IF;
@ -51,13 +51,15 @@ END
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql;
-- non-spilled xact -- non-spilled xact
SET logical_decoding_work_mem to '64MB';
INSERT INTO stats_test values(1); INSERT INTO stats_test values(1);
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1'); SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
SELECT wait_for_decode_stats(false, false); SELECT wait_for_decode_stats(false, false);
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; 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;
RESET logical_decoding_work_mem;
-- reset the slot stats, and wait for stats collector's total txn to reset -- reset the slot stats, and wait for stats collector's total txn to reset
SELECT pg_stat_reset_replication_slot('regression_slot'); SELECT pg_stat_reset_replication_slot('regression_slot_stats');
SELECT wait_for_decode_stats(true, false); SELECT wait_for_decode_stats(true, false);
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots; SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
@ -65,7 +67,7 @@ SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_
BEGIN; BEGIN;
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i); INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
COMMIT; COMMIT;
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1'); SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
-- Check stats, wait for the stats collector to update. We can't test the -- Check stats, wait for the stats collector to update. We can't test the
-- exact stats count as that can vary if any background transaction (say by -- exact stats count as that can vary if any background transaction (say by
@ -74,12 +76,12 @@ SELECT wait_for_decode_stats(false, true);
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; 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;
-- reset the slot stats, and wait for stats collector to reset -- reset the slot stats, and wait for stats collector to reset
SELECT pg_stat_reset_replication_slot('regression_slot'); SELECT pg_stat_reset_replication_slot('regression_slot_stats');
SELECT wait_for_decode_stats(true, true); SELECT wait_for_decode_stats(true, true);
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots; SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
-- decode and check stats again. -- decode and check stats again.
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1'); SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
SELECT wait_for_decode_stats(false, true); SELECT wait_for_decode_stats(false, true);
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; 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;
@ -92,4 +94,4 @@ COMMIT;
DROP FUNCTION wait_for_decode_stats(bool, bool); DROP FUNCTION wait_for_decode_stats(bool, bool);
DROP TABLE stats_test; DROP TABLE stats_test;
SELECT pg_drop_replication_slot('regression_slot'); SELECT pg_drop_replication_slot('regression_slot_stats');