From 51ef9173030cc196c6633ae82b7b32f404b0f768 Mon Sep 17 00:00:00 2001 From: Amit Kapila Date: Fri, 30 Apr 2021 07:55:42 +0530 Subject: [PATCH] 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 --- contrib/test_decoding/expected/stats.out | 62 ++++++++++++------------ contrib/test_decoding/sql/stats.sql | 20 ++++---- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/contrib/test_decoding/expected/stats.out b/contrib/test_decoding/expected/stats.out index 86d594ca15e..7d174ee8d28 100644 --- a/contrib/test_decoding/expected/stats.out +++ b/contrib/test_decoding/expected/stats.out @@ -1,6 +1,6 @@ -- predictability 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? ---------- init @@ -23,7 +23,7 @@ BEGIN ELSE (spill_txns > 0) END INTO updated - FROM pg_stat_replication_slots WHERE slot_name='regression_slot'; + FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats'; ELSE @@ -32,7 +32,7 @@ BEGIN ELSE (total_txns > 0) END 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; @@ -52,8 +52,9 @@ BEGIN END $$ LANGUAGE plpgsql; -- non-spilled xact +SET logical_decoding_work_mem to '64MB'; 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 ------- 3 @@ -66,13 +67,14 @@ SELECT wait_for_decode_stats(false, false); (1 row) 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 ------------------+------------+-------------+------------+------------- - regression_slot | t | t | t | t + slot_name | spill_txns | spill_count | total_txns | total_bytes +-----------------------+------------+-------------+------------+------------- + regression_slot_stats | t | t | t | t (1 row) +RESET logical_decoding_work_mem; -- 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 -------------------------------- @@ -85,16 +87,16 @@ SELECT wait_for_decode_stats(true, false); (1 row) 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 ------------------+------------+-------------+------------+------------- - regression_slot | 0 | 0 | 0 | 0 + slot_name | spill_txns | spill_count | total_txns | total_bytes +-----------------------+------------+-------------+------------+------------- + regression_slot_stats | 0 | 0 | 0 | 0 (1 row) -- spilling the xact BEGIN; INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i); 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 ------- 5002 @@ -110,13 +112,13 @@ SELECT wait_for_decode_stats(false, true); (1 row) 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 ------------------+------------+-------------+------------+------------- - regression_slot | t | t | t | t + slot_name | spill_txns | spill_count | total_txns | total_bytes +-----------------------+------------+-------------+------------+------------- + regression_slot_stats | t | t | t | t (1 row) -- 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 -------------------------------- @@ -129,13 +131,13 @@ SELECT wait_for_decode_stats(true, true); (1 row) 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 ------------------+------------+-------------+------------+------------- - regression_slot | 0 | 0 | 0 | 0 + slot_name | spill_txns | spill_count | total_txns | total_bytes +-----------------------+------------+-------------+------------+------------- + regression_slot_stats | 0 | 0 | 0 | 0 (1 row) -- 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 ------- 5002 @@ -148,30 +150,30 @@ SELECT wait_for_decode_stats(false, true); (1 row) 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 ------------------+------------+-------------+------------+------------- - regression_slot | t | t | t | t + slot_name | spill_txns | spill_count | total_txns | total_bytes +-----------------------+------------+-------------+------------+------------- + regression_slot_stats | t | t | t | t (1 row) -- Ensure stats can be repeatedly accessed using the same stats snapshot. See -- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de BEGIN; SELECT slot_name FROM pg_stat_replication_slots; - slot_name ------------------ - regression_slot + slot_name +----------------------- + regression_slot_stats (1 row) SELECT slot_name FROM pg_stat_replication_slots; - slot_name ------------------ - regression_slot + slot_name +----------------------- + regression_slot_stats (1 row) COMMIT; DROP FUNCTION wait_for_decode_stats(bool, bool); DROP TABLE stats_test; -SELECT pg_drop_replication_slot('regression_slot'); +SELECT pg_drop_replication_slot('regression_slot_stats'); pg_drop_replication_slot -------------------------- diff --git a/contrib/test_decoding/sql/stats.sql b/contrib/test_decoding/sql/stats.sql index 03fc27e537f..263568b00ce 100644 --- a/contrib/test_decoding/sql/stats.sql +++ b/contrib/test_decoding/sql/stats.sql @@ -1,7 +1,7 @@ -- predictability 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); @@ -21,7 +21,7 @@ BEGIN ELSE (spill_txns > 0) END INTO updated - FROM pg_stat_replication_slots WHERE slot_name='regression_slot'; + FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats'; ELSE @@ -30,7 +30,7 @@ BEGIN ELSE (total_txns > 0) END 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; @@ -51,13 +51,15 @@ END $$ LANGUAGE plpgsql; -- non-spilled xact +SET logical_decoding_work_mem to '64MB'; 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 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 -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 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; INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i); 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 -- 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; -- 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 slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots; -- 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 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 TABLE stats_test; -SELECT pg_drop_replication_slot('regression_slot'); +SELECT pg_drop_replication_slot('regression_slot_stats');