Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e083fa3

Browse files
committed
Further stabilize results of 019_replslot_limit.pl.
Depending on specific values of restart_lsn or pg_current_wal_lsn() is obviously unsafe. The previous coding tried to dodge this issue by rounding off, but that's not good enough, as shown by multiple buildfarm members. Nuke all the uses of these values except for null-ness checks, pending some credible argument why we should think something else could be usefully stable. Kyotaro Horiguchi, further modified by me Discussion: https://postgr.es/m/E1jM1Sa-0003mS-99@gemulon.postgresql.org
1 parent 2e0e409 commit e083fa3

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/test/recovery/t/019_replslot_limit.pl

+17-17
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
$node_master->safe_psql('postgres', "SELECT pg_create_physical_replication_slot('rep1')");
2626

2727
# The slot state and remain should be null before the first connection
28-
my $result = $node_master->safe_psql('postgres', "SELECT restart_lsn is NULL, wal_status is NULL, min_safe_lsn is NULL FROM pg_replication_slots WHERE slot_name = 'rep1'");
28+
my $result = $node_master->safe_psql('postgres', "SELECT restart_lsn IS NULL, wal_status is NULL, min_safe_lsn is NULL FROM pg_replication_slots WHERE slot_name = 'rep1'");
2929
is($result, "t|t|t", 'check the state of non-reserved slot is "unknown"');
3030

3131

@@ -48,23 +48,23 @@
4848
$node_standby->stop;
4949

5050
# Preparation done, the slot is the state "normal" now
51-
$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, min_safe_lsn is NULL FROM pg_replication_slots WHERE slot_name = 'rep1'");
52-
is($result, "$start_lsn|normal|t", 'check the catching-up state');
51+
$result = $node_master->safe_psql('postgres', "SELECT wal_status, min_safe_lsn is NULL FROM pg_replication_slots WHERE slot_name = 'rep1'");
52+
is($result, "normal|t", 'check the catching-up state');
5353

5454
# Advance WAL by five segments (= 5MB) on master
5555
advance_wal($node_master, 1);
5656
$node_master->safe_psql('postgres', "CHECKPOINT;");
5757

5858
# The slot is always "safe" when fitting max_wal_size
59-
$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, min_safe_lsn is NULL FROM pg_replication_slots WHERE slot_name = 'rep1'");
60-
is($result, "$start_lsn|normal|t", 'check that restart_lsn is in max_wal_size');
59+
$result = $node_master->safe_psql('postgres', "SELECT wal_status, min_safe_lsn is NULL FROM pg_replication_slots WHERE slot_name = 'rep1'");
60+
is($result, "normal|t", 'check that it is safe if WAL fits in max_wal_size');
6161

6262
advance_wal($node_master, 4);
6363
$node_master->safe_psql('postgres', "CHECKPOINT;");
6464

6565
# The slot is always "safe" when max_slot_wal_keep_size is not set
66-
$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, min_safe_lsn is NULL FROM pg_replication_slots WHERE slot_name = 'rep1'");
67-
is($result, "$start_lsn|normal|t", 'check that slot is working');
66+
$result = $node_master->safe_psql('postgres', "SELECT wal_status, min_safe_lsn is NULL FROM pg_replication_slots WHERE slot_name = 'rep1'");
67+
is($result, "normal|t", 'check that slot is working');
6868

6969
# The standby can reconnect to master
7070
$node_standby->start;
@@ -85,16 +85,16 @@
8585
# be as almost (max_slot_wal_keep_size - 1) times large as the segment
8686
# size
8787

88-
$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, pg_size_pretty(pg_current_wal_lsn() - min_safe_lsn) FROM pg_replication_slots WHERE slot_name = 'rep1'");
89-
is($result, "$start_lsn|normal|5120 kB", 'check that max_slot_wal_keep_size is working');
88+
$result = $node_master->safe_psql('postgres', "SELECT wal_status FROM pg_replication_slots WHERE slot_name = 'rep1'");
89+
is($result, "normal", 'check that max_slot_wal_keep_size is working');
9090

9191
# Advance WAL again then checkpoint, reducing remain by 2 MB.
9292
advance_wal($node_master, 2);
9393
$node_master->safe_psql('postgres', "CHECKPOINT;");
9494

9595
# The slot is still working
96-
$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, pg_size_pretty(pg_current_wal_lsn() - min_safe_lsn) FROM pg_replication_slots WHERE slot_name = 'rep1'");
97-
is($result, "$start_lsn|normal|2048 kB", 'check that min_safe_lsn gets close to the current LSN');
96+
$result = $node_master->safe_psql('postgres', "SELECT wal_status FROM pg_replication_slots WHERE slot_name = 'rep1'");
97+
is($result, "normal", 'check that min_safe_lsn gets close to the current LSN');
9898

9999
# The standby can reconnect to master
100100
$node_standby->start;
@@ -106,8 +106,8 @@
106106
$result = $node_master->safe_psql('postgres', "ALTER SYSTEM SET wal_keep_segments to 8; SELECT pg_reload_conf();");
107107
# Advance WAL again then checkpoint, reducing remain by 6 MB.
108108
advance_wal($node_master, 6);
109-
$result = $node_master->safe_psql('postgres', "SELECT restart_lsn, wal_status, pg_size_pretty(pg_current_wal_lsn() - min_safe_lsn) as remain FROM pg_replication_slots WHERE slot_name = 'rep1'");
110-
is($result, "$start_lsn|normal|8192 kB", 'check that wal_keep_segments overrides max_slot_wal_keep_size');
109+
$result = $node_master->safe_psql('postgres', "SELECT wal_status as remain FROM pg_replication_slots WHERE slot_name = 'rep1'");
110+
is($result, "normal", 'check that wal_keep_segments overrides max_slot_wal_keep_size');
111111
# restore wal_keep_segments
112112
$result = $node_master->safe_psql('postgres', "ALTER SYSTEM SET wal_keep_segments to 0; SELECT pg_reload_conf();");
113113

@@ -131,8 +131,8 @@
131131
advance_wal($node_master, 1);
132132

133133
# Slot gets into 'lost' state
134-
$result = $node_master->safe_psql('postgres', "SELECT wal_status FROM pg_replication_slots WHERE slot_name = 'rep1'");
135-
is($result, "lost", 'check that the slot state changes to "lost"');
134+
$result = $node_master->safe_psql('postgres', "SELECT wal_status, min_safe_lsn is NULL FROM pg_replication_slots WHERE slot_name = 'rep1'");
135+
is($result, "lost|t", 'check that the slot state changes to "lost"');
136136

137137
# The standby still can connect to master before a checkpoint
138138
$node_standby->start;
@@ -158,8 +158,8 @@
158158
'check that the warning is logged');
159159

160160
# This slot should be broken
161-
$result = $node_master->safe_psql('postgres', "SELECT slot_name, active, restart_lsn, wal_status, min_safe_lsn FROM pg_replication_slots WHERE slot_name = 'rep1'");
162-
is($result, "rep1|f|||", 'check that the slot became inactive');
161+
$result = $node_master->safe_psql('postgres', "SELECT slot_name, active, restart_lsn IS NULL, wal_status, min_safe_lsn FROM pg_replication_slots WHERE slot_name = 'rep1'");
162+
is($result, "rep1|f|t||", 'check that the slot became inactive');
163163

164164
# The standby no longer can connect to the master
165165
$logstart = get_log_size($node_standby);

0 commit comments

Comments
 (0)