@@ -205,17 +205,14 @@ sub reactive_slots_change_hfs_and_wait_for_xmins
205
205
206
206
change_hot_standby_feedback_and_wait_for_xmins($hsf , $invalidated );
207
207
208
- $handle =
209
- make_slot_active($node_standby , $slot_prefix , 1, \$stdout , \$stderr );
210
-
211
208
# reset stat: easier to check for confl_active_logicalslot in pg_stat_database_conflicts
212
209
$node_standby -> psql(' testdb' , q[ select pg_stat_reset();] );
213
210
}
214
211
215
212
# Check invalidation in the logfile and in pg_stat_database_conflicts
216
213
sub check_for_invalidation
217
214
{
218
- my ($slot_prefix , $log_start , $test_name ) = @_ ;
215
+ my ($slot_prefix , $log_start , $test_name , $checks_active_slot ) = @_ ;
219
216
220
217
my $active_slot = $slot_prefix . ' activeslot' ;
221
218
my $inactive_slot = $slot_prefix . ' inactiveslot' ;
@@ -231,13 +228,17 @@ sub check_for_invalidation
231
228
$log_start ),
232
229
" activeslot slot invalidation is logged $test_name " );
233
230
234
- # Verify that pg_stat_database_conflicts.confl_active_logicalslot has been updated
235
- ok( $node_standby -> poll_query_until(
236
- ' postgres' ,
237
- " select (confl_active_logicalslot = 1) from pg_stat_database_conflicts where datname = 'testdb'" ,
238
- ' t' ),
239
- ' confl_active_logicalslot updated'
240
- ) or die " Timed out waiting confl_active_logicalslot to be updated" ;
231
+ if ($checks_active_slot )
232
+ {
233
+ # Verify that pg_stat_database_conflicts.confl_active_logicalslot has
234
+ # been updated
235
+ ok( $node_standby -> poll_query_until(
236
+ ' postgres' ,
237
+ " select (confl_active_logicalslot = 1) from pg_stat_database_conflicts where datname = 'testdb'" ,
238
+ ' t' ),
239
+ ' confl_active_logicalslot updated'
240
+ ) or die " Timed out waiting confl_active_logicalslot to be updated" ;
241
+ }
241
242
}
242
243
243
244
# Launch $sql query, wait for a new snapshot that has a newer horizon and
@@ -250,7 +251,11 @@ sub check_for_invalidation
250
251
# seeing a xl_running_xacts that would advance an active replication slot's
251
252
# catalog_xmin. Advancing the active replication slot's catalog_xmin
252
253
# would break some tests that expect the active slot to conflict with
253
- # the catalog xmin horizon.
254
+ # the catalog xmin horizon. Even with the above precaution, there is a risk
255
+ # of xl_running_xacts record being logged and replayed before the VACUUM
256
+ # command, leading to the test failure. So, we ensured that replication slots
257
+ # are not activated for tests that can invalidate slots due to 'rows_removed'
258
+ # conflict reason.
254
259
sub wait_until_vacuum_can_remove
255
260
{
256
261
my ($vac_option , $sql , $to_vac ) = @_ ;
@@ -532,7 +537,7 @@ sub wait_until_vacuum_can_remove
532
537
$node_subscriber -> stop;
533
538
534
539
# #################################################
535
- # Recovery conflict: Invalidate conflicting slots, including in-use slots
540
+ # Recovery conflict: Invalidate conflicting slots
536
541
# Scenario 1: hot_standby_feedback off and vacuum FULL
537
542
# #################################################
538
543
@@ -550,7 +555,7 @@ sub wait_until_vacuum_can_remove
550
555
$node_primary -> wait_for_replay_catchup($node_standby );
551
556
552
557
# Check invalidation in the logfile and in pg_stat_database_conflicts
553
- check_for_invalidation(' vacuum_full_' , 1, ' with vacuum FULL on pg_class' );
558
+ check_for_invalidation(' vacuum_full_' , 1, ' with vacuum FULL on pg_class' , 0 );
554
559
555
560
# Verify slots are reported as conflicting in pg_replication_slots
556
561
check_slots_conflicting_status(1);
@@ -620,7 +625,7 @@ sub wait_until_vacuum_can_remove
620
625
" invalidated logical slots do not lead to retaining WAL" );
621
626
622
627
# #################################################
623
- # Recovery conflict: Invalidate conflicting slots, including in-use slots
628
+ # Recovery conflict: Invalidate conflicting slots
624
629
# Scenario 2: conflict due to row removal with hot_standby_feedback off.
625
630
# #################################################
626
631
@@ -641,7 +646,7 @@ sub wait_until_vacuum_can_remove
641
646
$node_primary -> wait_for_replay_catchup($node_standby );
642
647
643
648
# Check invalidation in the logfile and in pg_stat_database_conflicts
644
- check_for_invalidation(' row_removal_' , $logstart , ' with vacuum on pg_class' );
649
+ check_for_invalidation(' row_removal_' , $logstart , ' with vacuum on pg_class' , 0 );
645
650
646
651
# Verify slots are reported as conflicting in pg_replication_slots
647
652
check_slots_conflicting_status(1);
@@ -677,7 +682,7 @@ sub wait_until_vacuum_can_remove
677
682
678
683
# Check invalidation in the logfile and in pg_stat_database_conflicts
679
684
check_for_invalidation(' shared_row_removal_' , $logstart ,
680
- ' with vacuum on pg_authid' );
685
+ ' with vacuum on pg_authid' , 0 );
681
686
682
687
# Verify slots are reported as conflicting in pg_replication_slots
683
688
check_slots_conflicting_status(1);
@@ -701,6 +706,10 @@ sub wait_until_vacuum_can_remove
701
706
reactive_slots_change_hfs_and_wait_for_xmins(' shared_row_removal_' ,
702
707
' no_conflict_' , 0, 1);
703
708
709
+ # As this scenario is not expected to produce any conflict, so activate the slot.
710
+ # See comments atop wait_until_vacuum_can_remove().
711
+ make_slot_active($node_standby , ' no_conflict_' , 1, \$stdout , \$stderr );
712
+
704
713
# This should not trigger a conflict
705
714
wait_until_vacuum_can_remove(
706
715
' ' , ' CREATE TABLE conflict_test(x integer, y text);
@@ -738,7 +747,7 @@ sub wait_until_vacuum_can_remove
738
747
$node_standby -> restart;
739
748
740
749
# #################################################
741
- # Recovery conflict: Invalidate conflicting slots, including in-use slots
750
+ # Recovery conflict: Invalidate conflicting slots
742
751
# Scenario 5: conflict due to on-access pruning.
743
752
# #################################################
744
753
@@ -763,7 +772,7 @@ sub wait_until_vacuum_can_remove
763
772
$node_primary -> wait_for_replay_catchup($node_standby );
764
773
765
774
# Check invalidation in the logfile and in pg_stat_database_conflicts
766
- check_for_invalidation(' pruning_' , $logstart , ' with on-access pruning' );
775
+ check_for_invalidation(' pruning_' , $logstart , ' with on-access pruning' , 0 );
767
776
768
777
# Verify slots are reported as conflicting in pg_replication_slots
769
778
check_slots_conflicting_status(1);
@@ -807,7 +816,7 @@ sub wait_until_vacuum_can_remove
807
816
$node_primary -> wait_for_replay_catchup($node_standby );
808
817
809
818
# Check invalidation in the logfile and in pg_stat_database_conflicts
810
- check_for_invalidation(' wal_level_' , $logstart , ' due to wal_level' );
819
+ check_for_invalidation(' wal_level_' , $logstart , ' due to wal_level' , 1 );
811
820
812
821
# Verify slots are reported as conflicting in pg_replication_slots
813
822
check_slots_conflicting_status(1);
0 commit comments