@@ -64,7 +64,7 @@ static void pg_stop_backup(pgBackup *backup);
64
64
65
65
static void add_pgdata_files (parray * files , const char * root );
66
66
static void write_backup_file_list (parray * files , const char * root );
67
- static void wait_archive_lsn (XLogRecPtr lsn , bool prev_segno );
67
+ static void wait_wal_lsn (XLogRecPtr lsn );
68
68
static void make_pagemap_from_ptrack (parray * files );
69
69
static void StreamLog (void * arg );
70
70
@@ -598,7 +598,12 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
598
598
if (!from_replica && !stream_wal )
599
599
pg_switch_wal ();
600
600
if (!stream_wal )
601
- wait_archive_lsn (backup -> start_lsn , false);
601
+ /*
602
+ * Do not wait start_lsn for stream backup.
603
+ * Because WAL streaming will start after pg_start_backup() in stream
604
+ * mode.
605
+ */
606
+ wait_wal_lsn (backup -> start_lsn );
602
607
}
603
608
604
609
/*
@@ -784,28 +789,32 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_oid,
784
789
* WAL segment file.
785
790
*/
786
791
static void
787
- wait_archive_lsn (XLogRecPtr lsn , bool prev_segno )
792
+ wait_wal_lsn (XLogRecPtr lsn )
788
793
{
789
794
TimeLineID tli ;
790
795
XLogSegNo targetSegNo ;
791
- char wal_path [MAXPGPATH ];
792
- char wal_file [MAXFNAMELEN ];
796
+ char wal_dir [MAXPGPATH ],
797
+ wal_segment_full_path [MAXPGPATH ];
798
+ char wal_segment [MAXFNAMELEN ];
793
799
uint32 try_count = 0 ;
794
800
795
- Assert (!stream_wal );
796
-
797
801
tli = get_current_timeline (false);
798
802
799
803
/* Compute the name of the WAL file containig requested LSN */
800
804
XLByteToSeg (lsn , targetSegNo );
801
- if (prev_segno )
802
- targetSegNo -- ;
803
- XLogFileName (wal_file , tli , targetSegNo );
805
+ XLogFileName (wal_segment , tli , targetSegNo );
804
806
805
- join_path_components (wal_path , arclog_path , wal_file );
807
+ if (stream_wal )
808
+ {
809
+ pgBackupGetPath2 (& current , wal_dir , lengthof (wal_dir ),
810
+ DATABASE_DIR , PG_XLOG_DIR );
811
+ join_path_components (wal_segment_full_path , wal_dir , wal_segment );
812
+ }
813
+ else
814
+ join_path_components (wal_segment_full_path , arclog_path , wal_segment );
806
815
807
816
/* Wait until switched WAL is archived */
808
- while (!fileExists (wal_path ))
817
+ while (!fileExists (wal_segment_full_path ))
809
818
{
810
819
sleep (1 );
811
820
if (interrupted )
@@ -815,21 +824,21 @@ wait_archive_lsn(XLogRecPtr lsn, bool prev_segno)
815
824
/* Inform user if WAL segment is absent in first attempt */
816
825
if (try_count == 1 )
817
826
elog (INFO , "wait for LSN %X/%X in archived WAL segment %s" ,
818
- (uint32 ) (lsn >> 32 ), (uint32 ) lsn , wal_path );
827
+ (uint32 ) (lsn >> 32 ), (uint32 ) lsn , wal_segment_full_path );
819
828
820
829
if (archive_timeout > 0 && try_count > archive_timeout )
821
830
elog (ERROR ,
822
831
"switched WAL segment %s could not be archived in %d seconds" ,
823
- wal_file , archive_timeout );
832
+ wal_segment , archive_timeout );
824
833
}
825
834
826
835
/*
827
- * WAL segment was archived. Check LSN on it if we waited current WAL
828
- * segment, not previous.
836
+ * WAL segment was archived. Check LSN on it.
829
837
*/
830
- if (!prev_segno && !wal_contains_lsn (arclog_path , lsn , tli ))
838
+ if ((stream_wal && !wal_contains_lsn (wal_dir , lsn , tli )) ||
839
+ (!stream_wal && !wal_contains_lsn (arclog_path , lsn , tli )))
831
840
elog (ERROR , "WAL segment %s doesn't contain target LSN %X/%X" ,
832
- wal_file , (uint32 ) (lsn >> 32 ), (uint32 ) lsn );
841
+ wal_segment , (uint32 ) (lsn >> 32 ), (uint32 ) lsn );
833
842
}
834
843
835
844
/*
@@ -950,8 +959,7 @@ pg_stop_backup(pgBackup *backup)
950
959
951
960
PQclear (res );
952
961
953
- if (!stream_wal )
954
- wait_archive_lsn (stop_backup_lsn , false);
962
+ wait_wal_lsn (stop_backup_lsn );
955
963
956
964
/* Fill in fields if that is the correct end of backup. */
957
965
if (backup != NULL )
@@ -961,7 +969,9 @@ pg_stop_backup(pgBackup *backup)
961
969
962
970
if (stream_wal )
963
971
{
964
- join_path_components (stream_xlog_path , pgdata , PG_XLOG_DIR );
972
+ pgBackupGetPath2 (backup , stream_xlog_path ,
973
+ lengthof (stream_xlog_path ),
974
+ DATABASE_DIR , PG_XLOG_DIR );
965
975
xlog_path = stream_xlog_path ;
966
976
}
967
977
else
0 commit comments