Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Stabilize the test added by commit 022564f60c.
authorAmit Kapila <akapila@postgresql.org>
Tue, 8 Oct 2024 05:31:53 +0000 (11:01 +0530)
committerAmit Kapila <akapila@postgresql.org>
Tue, 8 Oct 2024 06:00:26 +0000 (11:30 +0530)
The test was unstable in branches 14 and 15 as we were relying on the
number of changes in the table having a toast column to start streaming.
On branches >= 16, we have a GUC debug_logical_replication_streaming which
can stream each change, so the test was stable in those branches.

Change the test to use PREPARE TRANSACTION as that should make the result
consistent and test the code changed in 022564f60c.

Reported-by: Daniel Gustafsson as per buildfarm
Author: Hou Zhijie, Amit Kapila
Backpatch-through: 14
Discussion: https://postgr.es/m/8C2F86AA-981E-4803-B14D-E264C0255330@yesql.se

contrib/test_decoding/expected/stream.out
contrib/test_decoding/expected/twophase.out
contrib/test_decoding/sql/stream.sql
contrib/test_decoding/sql/twophase.sql

index 2e319a89417a85cca3c1a03435e9b82ef686171a..0f21dcb8e0e442c14079ea99426b0d3a27f952b5 100644 (file)
@@ -106,26 +106,6 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'incl
  committing streamed transaction
 (17 rows)
 
--- Test that accessing a TOAST table in streaming mode is allowed.
--- Create a table with a column that uses a TOASTed default value.
--- (temporarily hide query, to avoid the long CREATE TABLE stmt)
-\set ECHO none
-BEGIN;
-INSERT INTO test_tab SELECT repeat('a', 6000) || g.i FROM generate_series(1, 350) g(i);
--- Force WAL flush, so that the above changes will be streamed.
-SELECT 'force flush' FROM pg_switch_wal();
-  ?column?   
--------------
- force flush
-(1 row)
-
-SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
- count 
--------
-   315
-(1 row)
-
-COMMIT;
 DROP TABLE stream_test;
 SELECT pg_drop_replication_slot('regression_slot');
  pg_drop_replication_slot 
index e5e0f968961710cf3a381448415f66c27360612d..12e2e3a0ffe00555b068060fa8f8de5182d5b2ab 100644 (file)
@@ -202,10 +202,33 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'inc
  COMMIT
 (3 rows)
 
+-- Test that accessing a TOAST table is permitted during the decoding of a
+-- prepared transaction.
+-- Create a table with a column that uses a TOASTed default value.
+-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
+\set ECHO none
+BEGIN;
+INSERT INTO test_tab VALUES('test');
+PREPARE TRANSACTION 'test_toast_table_access';
+SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
+ count 
+-------
+     3
+(1 row)
+
+COMMIT PREPARED 'test_toast_table_access';
+-- consume commit prepared
+SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
+                   data                    
+-------------------------------------------
+ COMMIT PREPARED 'test_toast_table_access'
+(1 row)
+
 -- Test 8:
 -- cleanup and make sure results are also empty
 DROP TABLE test_prepared1;
 DROP TABLE test_prepared2;
+DROP TABLE test_tab;
 -- show results. There should be nothing to show
 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
  data 
index 9502a6d87cf6864510fe8c970667069596a94c97..4feec62972a5e4b6ac40fddbaed3fc8836d645a7 100644 (file)
@@ -44,23 +44,5 @@ toasted-123456789012345678901234567890123456789012345678901234567890123456789012
 
 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
 
--- Test that accessing a TOAST table in streaming mode is allowed.
-
--- Create a table with a column that uses a TOASTed default value.
--- (temporarily hide query, to avoid the long CREATE TABLE stmt)
-\set ECHO none
-SELECT 'CREATE TABLE test_tab (a text DEFAULT ''' || string_agg('toast value', '') || ''');' FROM generate_series(1, 4000)
-\gexec
-\set ECHO all
-
-BEGIN;
-INSERT INTO test_tab SELECT repeat('a', 6000) || g.i FROM generate_series(1, 350) g(i);
-
--- Force WAL flush, so that the above changes will be streamed.
-SELECT 'force flush' FROM pg_switch_wal();
-
-SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
-COMMIT;
-
 DROP TABLE stream_test;
 SELECT pg_drop_replication_slot('regression_slot');
index 05f18e84948b9e548455315191d0dfe3233d886a..e3ea45539ccfc0bc9d7f5168ca1946933adcf728 100644 (file)
@@ -101,10 +101,32 @@ COMMIT PREPARED 'test_prepared_nodecode';
 -- should be decoded now
 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
 
+-- Test that accessing a TOAST table is permitted during the decoding of a
+-- prepared transaction.
+
+-- Create a table with a column that uses a TOASTed default value.
+-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
+\set ECHO none
+SELECT 'CREATE TABLE test_tab (a text DEFAULT ''' || string_agg('toast value', '') || ''');' FROM generate_series(1, 4000)
+\gexec
+\set ECHO all
+
+BEGIN;
+INSERT INTO test_tab VALUES('test');
+PREPARE TRANSACTION 'test_toast_table_access';
+
+SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
+
+COMMIT PREPARED 'test_toast_table_access';
+
+-- consume commit prepared
+SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
+
 -- Test 8:
 -- cleanup and make sure results are also empty
 DROP TABLE test_prepared1;
 DROP TABLE test_prepared2;
+DROP TABLE test_tab;
 -- show results. There should be nothing to show
 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');