Skip to content

Commit 0876dd6

Browse files
committed
[Issue #346] set "interrupted" in elog, wait for streamed segments
1 parent f4ab4b9 commit 0876dd6

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/backup.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn, PGNode
5656

5757
static XLogRecPtr wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn, TimeLineID tli,
5858
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);
6060

6161
static void check_external_for_tablespaces(parray *external_list,
6262
PGconn *backup_conn);
@@ -268,7 +268,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
268268
* Because WAL streaming will start after pg_start_backup() in stream
269269
* mode.
270270
*/
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);
272272
}
273273

274274
/* start stream replication */
@@ -279,6 +279,12 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
279279

280280
start_WAL_streaming(backup_conn, dst_backup_path, &instance_config.conn_opt,
281281
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);
282288
}
283289

284290
/* initialize backup's file list */
@@ -1262,7 +1268,7 @@ pg_is_superuser(PGconn *conn)
12621268
static XLogRecPtr
12631269
wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
12641270
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)
12661272
{
12671273
XLogSegNo targetSegNo;
12681274
char pg_wal_dir[MAXPGPATH];
@@ -1294,15 +1300,14 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
12941300
*/
12951301
if (in_stream_dir)
12961302
{
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);
12991304
join_path_components(wal_segment_path, pg_wal_dir, wal_segment);
13001305
wal_segment_dir = pg_wal_dir;
13011306
}
13021307
else
13031308
{
13041309
join_path_components(wal_segment_path, arclog_path, wal_segment);
1305-
wal_segment_dir = arclog_path;
1310+
wal_segment_dir = arclog_path; /* global var */
13061311
}
13071312

13081313
/* 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,
13941399

13951400
sleep(1);
13961401
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");
13981403
try_count++;
13991404

14001405
/* 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,
14181423
{
14191424
if (file_exists)
14201425
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",
14221427
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);
14241430
/* If WAL segment doesn't exist or we wait for previous segment */
14251431
else
14261432
elog(timeout_elevel,
@@ -1705,7 +1711,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17051711
{
17061712
/* Wait for segment with current stop_lsn, it is ok for it to never arrive */
17071713
wait_wal_lsn(stop_backup_lsn_tmp, false, backup->tli,
1708-
false, true, WARNING, stream_wal);
1714+
false, true, WARNING, stream_wal, backup);
17091715

17101716
/* Get the first record in segment with current stop_lsn */
17111717
lsn_tmp = get_first_record_lsn(xlog_path, segno, backup->tli,
@@ -1733,7 +1739,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17331739
* because previous record can be the contrecord.
17341740
*/
17351741
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);
17371743

17381744
/* sanity */
17391745
if (!XRecOffIsValid(lsn_tmp) || XLogRecPtrIsInvalid(lsn_tmp))
@@ -1747,7 +1753,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17471753
{
17481754
/* Wait for segment with current stop_lsn */
17491755
wait_wal_lsn(stop_backup_lsn_tmp, false, backup->tli,
1750-
false, true, ERROR, stream_wal);
1756+
false, true, ERROR, stream_wal, backup);
17511757

17521758
/* Get the next closest record in segment with current stop_lsn */
17531759
lsn_tmp = get_next_record_lsn(xlog_path, segno, backup->tli,
@@ -1876,7 +1882,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18761882
*/
18771883
if (!stop_lsn_exists)
18781884
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);
18801886

18811887
if (stream_wal)
18821888
{

src/utils/logger.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ exit_if_necessary(int elevel)
169169
{
170170
/* Interrupt other possible routines */
171171
thread_interrupted = true;
172+
interrupted = true;
172173
#ifdef WIN32
173174
ExitThread(elevel);
174175
#else

0 commit comments

Comments
 (0)