@@ -56,7 +56,7 @@ static void pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn, PGNode
56
56
57
57
static XLogRecPtr wait_wal_lsn (XLogRecPtr lsn , bool is_start_lsn , TimeLineID tli ,
58
58
bool in_prev_segment , bool segment_only ,
59
- int timeout_elevel , bool in_stream_dir );
59
+ int timeout_elevel , bool in_stream_dir , pgBackup * backup );
60
60
61
61
static void check_external_for_tablespaces (parray * external_list ,
62
62
PGconn * backup_conn );
@@ -268,7 +268,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
268
268
* Because WAL streaming will start after pg_start_backup() in stream
269
269
* mode.
270
270
*/
271
- wait_wal_lsn (current .start_lsn , true, current .tli , false, true, ERROR , false);
271
+ wait_wal_lsn (current .start_lsn , true, current .tli , false, true, ERROR , false, & current );
272
272
}
273
273
274
274
/* start stream replication */
@@ -279,6 +279,12 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
279
279
280
280
start_WAL_streaming (backup_conn , dst_backup_path , & instance_config .conn_opt ,
281
281
current .start_lsn , current .tli );
282
+
283
+ /* Make sure that WAL streaming is working
284
+ * PAGE backup in stream mode is waited twice, first for
285
+ * segment in WAL archive and then for streamed segment
286
+ */
287
+ wait_wal_lsn (current .start_lsn , true, current .tli , false, true, ERROR , true, & current );
282
288
}
283
289
284
290
/* initialize backup's file list */
@@ -1262,7 +1268,7 @@ pg_is_superuser(PGconn *conn)
1262
1268
static XLogRecPtr
1263
1269
wait_wal_lsn (XLogRecPtr target_lsn , bool is_start_lsn , TimeLineID tli ,
1264
1270
bool in_prev_segment , bool segment_only ,
1265
- int timeout_elevel , bool in_stream_dir )
1271
+ int timeout_elevel , bool in_stream_dir , pgBackup * backup )
1266
1272
{
1267
1273
XLogSegNo targetSegNo ;
1268
1274
char pg_wal_dir [MAXPGPATH ];
@@ -1294,15 +1300,14 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
1294
1300
*/
1295
1301
if (in_stream_dir )
1296
1302
{
1297
- pgBackupGetPath2 (& current , pg_wal_dir , lengthof (pg_wal_dir ),
1298
- DATABASE_DIR , PG_XLOG_DIR );
1303
+ join_path_components (pg_wal_dir , backup -> database_dir , PG_XLOG_DIR );
1299
1304
join_path_components (wal_segment_path , pg_wal_dir , wal_segment );
1300
1305
wal_segment_dir = pg_wal_dir ;
1301
1306
}
1302
1307
else
1303
1308
{
1304
1309
join_path_components (wal_segment_path , arclog_path , wal_segment );
1305
- wal_segment_dir = arclog_path ;
1310
+ wal_segment_dir = arclog_path ; /* global var */
1306
1311
}
1307
1312
1308
1313
/* TODO: remove this in 3.0 (it is a cludge against some old bug with archive_timeout) */
@@ -1394,7 +1399,7 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
1394
1399
1395
1400
sleep (1 );
1396
1401
if (interrupted )
1397
- elog (ERROR , "Interrupted during waiting for WAL archiving" );
1402
+ elog (ERROR , "Interrupted during waiting for WAL %s" , in_stream_dir ? "streaming" : " archiving" );
1398
1403
try_count ++ ;
1399
1404
1400
1405
/* Inform user if WAL segment is absent in first attempt */
@@ -1418,9 +1423,10 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
1418
1423
{
1419
1424
if (file_exists )
1420
1425
elog (timeout_elevel , "WAL segment %s was %s, "
1421
- "but target LSN %X/%X could not be archived in %d seconds" ,
1426
+ "but target LSN %X/%X could not be %s in %d seconds" ,
1422
1427
wal_segment , wal_delivery_str ,
1423
- (uint32 ) (target_lsn >> 32 ), (uint32 ) target_lsn , timeout );
1428
+ (uint32 ) (target_lsn >> 32 ), (uint32 ) target_lsn ,
1429
+ wal_delivery_str , timeout );
1424
1430
/* If WAL segment doesn't exist or we wait for previous segment */
1425
1431
else
1426
1432
elog (timeout_elevel ,
@@ -1705,7 +1711,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
1705
1711
{
1706
1712
/* Wait for segment with current stop_lsn, it is ok for it to never arrive */
1707
1713
wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1708
- false, true, WARNING , stream_wal );
1714
+ false, true, WARNING , stream_wal , backup );
1709
1715
1710
1716
/* Get the first record in segment with current stop_lsn */
1711
1717
lsn_tmp = get_first_record_lsn (xlog_path , segno , backup -> tli ,
@@ -1733,7 +1739,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
1733
1739
* because previous record can be the contrecord.
1734
1740
*/
1735
1741
lsn_tmp = wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1736
- true, false, ERROR , stream_wal );
1742
+ true, false, ERROR , stream_wal , backup );
1737
1743
1738
1744
/* sanity */
1739
1745
if (!XRecOffIsValid (lsn_tmp ) || XLogRecPtrIsInvalid (lsn_tmp ))
@@ -1747,7 +1753,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
1747
1753
{
1748
1754
/* Wait for segment with current stop_lsn */
1749
1755
wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1750
- false, true, ERROR , stream_wal );
1756
+ false, true, ERROR , stream_wal , backup );
1751
1757
1752
1758
/* Get the next closest record in segment with current stop_lsn */
1753
1759
lsn_tmp = get_next_record_lsn (xlog_path , segno , backup -> tli ,
@@ -1876,7 +1882,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
1876
1882
*/
1877
1883
if (!stop_lsn_exists )
1878
1884
stop_backup_lsn = wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1879
- false, false, ERROR , stream_wal );
1885
+ false, false, ERROR , stream_wal , backup );
1880
1886
1881
1887
if (stream_wal )
1882
1888
{
0 commit comments