@@ -536,6 +536,8 @@ wait_until_primary_is_ready(Keeper *keeper,
536536
537537 /* wait until the primary is ready for us to pg_basebackup */
538538 do {
539+ bool groupStateHasChanged = false;
540+
539541 if (firstLoop )
540542 {
541543 firstLoop = false;
@@ -546,8 +548,6 @@ wait_until_primary_is_ready(Keeper *keeper,
546548 KeeperStateData * keeperState = & (keeper -> state );
547549 int timeoutMs = PG_AUTOCTL_KEEPER_SLEEP_TIME * 1000 ;
548550
549- bool groupStateHasChanged = false;
550-
551551 (void ) monitor_wait_for_state_change (monitor ,
552552 keeper -> config .formation ,
553553 keeperState -> current_group ,
@@ -579,7 +579,12 @@ wait_until_primary_is_ready(Keeper *keeper,
579579 return false;
580580 }
581581 }
582- ++ tries ;
582+
583+ /* if state has changed, we didn't wait for a full timeout */
584+ if (!groupStateHasChanged )
585+ {
586+ ++ tries ;
587+ }
583588
584589 if (tries == 3 )
585590 {
@@ -630,18 +635,18 @@ wait_until_primary_has_created_our_replication_slot(Keeper *keeper,
630635 KeeperConfig * config = & (keeper -> config );
631636 LocalPostgresServer * postgres = & (keeper -> postgres );
632637 ReplicationSource * upstream = & (postgres -> replicationSource );
633- NodeAddress * primaryNode = & ( postgres -> replicationSource . primaryNode ) ;
638+ NodeAddress primaryNode = { 0 } ;
634639
635640 bool hasReplicationSlot = false;
636641
637- if (!keeper_get_primary (keeper , & ( postgres -> replicationSource . primaryNode ) ))
642+ if (!keeper_get_primary (keeper , & primaryNode ))
638643 {
639644 /* errors have already been logged */
640645 return false;
641646 }
642647
643648 if (!standby_init_replication_source (postgres ,
644- primaryNode ,
649+ & primaryNode ,
645650 PG_AUTOCTL_REPLICA_USERNAME ,
646651 config -> replication_password ,
647652 config -> replication_slot_name ,
@@ -672,10 +677,10 @@ wait_until_primary_has_created_our_replication_slot(Keeper *keeper,
672677 ++ errors ;
673678
674679 log_warn ("Failed to contact the primary node %d \"%s\" (%s:%d)" ,
675- primaryNode -> nodeId ,
676- primaryNode -> name ,
677- primaryNode -> host ,
678- primaryNode -> port );
680+ primaryNode . nodeId ,
681+ primaryNode . name ,
682+ primaryNode . host ,
683+ primaryNode . port );
679684
680685 if (errors > 5 )
681686 {
0 commit comments