postgres.git / summary / log / commit / refs

commit    dccaf9d1e4fe8552134ec322ae93454efeb17b1b
Author:   Robert Haas <rhaas@postgresql.org>
Date:     Fri Oct 30 16:28:59 2026 +0000
First released in: 19.0

    pg_stash_advice: Fix race conditions in 001_persist.pl
    
    Each time we start the server, there's a brief lockout while the
    persistence worker reloads stashes from disk. Until that's complete,
    no stashes will be visible and no stash modifications can be made.
    This test case failed to take that into account, and could therefore
    fail spuriously.
    
    Reported-by: Alexander Lakhin <exclusion@gmail.com>
    Reported-by: Nik Samokhvalov <nik@postgres.ai>
    Author: Nik Samokhvalov <nik@postgres.ai>
    Co-authored-by: Robert Haas <rhaas@postgresql.org> (whitespace changes)
    Backpatch-through: 19
    Discussion: http://postgr.es/m/CAM527d8PqdbDy=PuTLYBJM8-FvvFDr2BLcyFyZhw6Oi9rXb14g@mail.gmail.com


contrib/pg_stash_advice/t/001_persist.pl | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/contrib/pg_stash_advice/t/001_persist.pl b/contrib/pg_stash_advice/t/001_persist.pl index 89347fb35bf..ae98ef0a197 100644 --- a/contrib/pg_stash_advice/t/001_persist.pl +++ b/contrib/pg_stash_advice/t/001_persist.pl @@ -20,10 +20,15 @@ $node->start; $node->safe_psql("postgres", "CREATE EXTENSION pg_stash_advice;\n"); +# The persistence worker loads the dump file after the server starts. Wait +# until it allows changes before creating the first stash. +$node->poll_query_until("postgres", + "SELECT pg_create_advice_stash('stash_a')", '') + or die "timed out waiting for pg_stash_advice to load"; + # Create two stashes: one with 3 entries, one with just 1 entry. $node->safe_psql( "postgres", qq{ - SELECT pg_create_advice_stash('stash_a'); SELECT pg_set_stashed_advice('stash_a', 1001, 'IndexScan(t)'); SELECT pg_set_stashed_advice('stash_a', 1002, E'line1\\nline2\\ttab\\\\backslash'); SELECT pg_set_stashed_advice('stash_a', 1003, ''); @@ -39,7 +44,9 @@ is($result, "stash_a|3\nstash_b|1", 'stashes present before restart'); # Restart and verify the data survived. $node->restart; -$node->wait_for_log("loaded 2 advice stashes and 4 entries"); +$node->poll_query_until("postgres", + "SELECT count(*) = 2 FROM pg_get_advice_stashes()") + or die "timed out waiting for two advice stashes to load"; $result = $node->safe_psql("postgres", "SELECT stash_name, num_entries FROM pg_get_advice_stashes() ORDER BY stash_name" @@ -63,7 +70,9 @@ $node->safe_psql( # Restart again and verify all three stashes are present. $node->restart; -$node->wait_for_log("loaded 3 advice stashes and 4 entries"); +$node->poll_query_until("postgres", + "SELECT count(*) = 3 FROM pg_get_advice_stashes()") + or die "timed out waiting for three advice stashes to load"; $result = $node->safe_psql("postgres", "SELECT stash_name, num_entries FROM pg_get_advice_stashes() ORDER BY stash_name" @@ -82,13 +91,20 @@ $node->safe_psql( $node->restart; +ok( !-f $node->data_dir . '/pg_stash_advice.tsv', + 'dump file removed after all stashes dropped'); + +# An empty result also occurs before the worker finishes loading. Check +# that stash modifications are allowed before asserting the empty state. +$node->poll_query_until("postgres", + "SELECT pg_create_advice_stash('probe')", '') + or die "timed out waiting for pg_stash_advice to load"; +$node->safe_psql("postgres", "SELECT pg_drop_advice_stash('probe')"); + $result = $node->safe_psql("postgres", "SELECT count(*) FROM pg_get_advice_stashes()"); is($result, "0", 'no stashes after dropping all and restarting'); -ok( !-f $node->data_dir . '/pg_stash_advice.tsv', - 'dump file removed after all stashes dropped'); - $node->stop; done_testing(); [parent: af3a7f7e29da]