diff options
| author | Alvaro Herrera | 2024-03-05 11:09:18 +0000 |
|---|---|---|
| committer | Alvaro Herrera | 2024-03-05 11:09:18 +0000 |
| commit | 1a2654b32b546d25e39a0c02410049559a3d4573 (patch) | |
| tree | 00e7e463d7113fe872912f271d04671c3eb085b6 /src/test | |
| parent | 030e10ff1a365796bd4bcbbc5b6a8552f7efc765 (diff) | |
Rework redundant code in subtrans.c
When this code was written the duplicity didn't matter, but with all the
SLRU-bank stuff we just added, it has become excessive. Turn it into a
simpler loop with no code duplication. Also add a test so that this
code becomes covered.
Discussion: https://postgr.es/m/202403041517.3a35jw53os65@alvherre.pgsql
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/recovery/t/009_twophase.pl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/recovery/t/009_twophase.pl b/src/test/recovery/t/009_twophase.pl index a3cdcf32408..701f9cc20f8 100644 --- a/src/test/recovery/t/009_twophase.pl +++ b/src/test/recovery/t/009_twophase.pl @@ -45,6 +45,10 @@ $node_london->backup('london_backup'); my $node_paris = PostgreSQL::Test::Cluster->new('paris'); $node_paris->init_from_backup($node_london, 'london_backup', has_streaming => 1); +$node_paris->append_conf( + 'postgresql.conf', qq( + subtransaction_buffers = 32 +)); $node_paris->start; # Switch to synchronous replication in both directions @@ -481,4 +485,42 @@ is( $psql_out, qq{27|issued to paris}, "Check expected t_009_tbl2 data on standby"); + +# Exercise the 2PC recovery code in StartupSUBTRANS, which is concerned with +# ensuring that enough pg_subtrans pages exist on disk to cover the range of +# prepared transactions at server start time. There's not much we can verify +# directly, but let's at least get the code to run. +$cur_standby->stop(); +configure_and_reload($cur_primary, "synchronous_standby_names = ''"); + +$cur_primary->safe_psql('postgres', "CHECKPOINT"); + +my $start_lsn = + $cur_primary->safe_psql('postgres', 'select pg_current_wal_insert_lsn()'); +$cur_primary->safe_psql('postgres', + "CREATE TABLE test(); BEGIN; CREATE TABLE test1(); PREPARE TRANSACTION 'foo';" +); +my $osubtrans = $cur_primary->safe_psql('postgres', + "select 'pg_subtrans/'||f, s.size from pg_ls_dir('pg_subtrans') f, pg_stat_file('pg_subtrans/'||f) s" +); +$cur_primary->pgbench( + '--no-vacuum --client=5 --transactions=1000', + 0, + [], + [], + 'pgbench run to cause pg_subtrans traffic', + { + '009_twophase.pgb' => 'insert into test default values' + }); +# StartupSUBTRANS is exercised with a wide range of visible XIDs in this +# stop/start sequence, because we left a prepared transaction open above. +# Also, setting subtransaction_buffers to 32 above causes to switch SLRU +# bank, for additional code coverage. +$cur_primary->stop; +$cur_primary->start; +my $nsubtrans = $cur_primary->safe_psql('postgres', + "select 'pg_subtrans/'||f, s.size from pg_ls_dir('pg_subtrans') f, pg_stat_file('pg_subtrans/'||f) s" +); +isnt($osubtrans, $nsubtrans, "contents of pg_subtrans/ have changed"); + done_testing(); |
