Skip to content

Commit a98eb32

Browse files
committed
Wait for target LSN, not only for WAL segment
1 parent aa9764d commit a98eb32

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

backup.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,22 @@ wait_wal_lsn(XLogRecPtr lsn)
837837
timeout = archive_timeout;
838838
}
839839

840-
/* Wait until switched WAL is archived */
841-
while (!fileExists(wal_segment_full_path))
840+
/* Wait until target LSN is archived */
841+
while (true)
842842
{
843+
bool file_exists = fileExists(wal_segment_full_path);
844+
845+
if (file_exists)
846+
{
847+
/*
848+
* WAL segment was archived. Check LSN on it.
849+
*/
850+
if ((stream_wal && wal_contains_lsn(wal_dir, lsn, tli)) ||
851+
(!stream_wal && wal_contains_lsn(arclog_path, lsn, tli)))
852+
/* Target LSN was found */
853+
return;
854+
}
855+
843856
sleep(1);
844857
if (interrupted)
845858
elog(ERROR, "interrupted during waiting for WAL archiving");
@@ -851,18 +864,17 @@ wait_wal_lsn(XLogRecPtr lsn)
851864
(uint32) (lsn >> 32), (uint32) lsn, wal_segment_full_path);
852865

853866
if (timeout > 0 && try_count > timeout)
854-
elog(ERROR,
855-
"switched WAL segment %s could not be archived in %d seconds",
856-
wal_segment, timeout);
867+
{
868+
if (file_exists)
869+
elog(ERROR, "WAL segment %s was archived, "
870+
"but target LSN %X/%X could not be archived in %d seconds",
871+
wal_segment, (uint32) (lsn >> 32), (uint32) lsn, timeout);
872+
else
873+
elog(ERROR,
874+
"switched WAL segment %s could not be archived in %d seconds",
875+
wal_segment, timeout);
876+
}
857877
}
858-
859-
/*
860-
* WAL segment was archived. Check LSN on it.
861-
*/
862-
if ((stream_wal && !wal_contains_lsn(wal_dir, lsn, tli)) ||
863-
(!stream_wal && !wal_contains_lsn(arclog_path, lsn, tli)))
864-
elog(ERROR, "WAL segment %s doesn't contain target LSN %X/%X",
865-
wal_segment, (uint32) (lsn >> 32), (uint32) lsn);
866878
}
867879

868880
/*
@@ -984,8 +996,11 @@ pg_stop_backup(pgBackup *backup)
984996
PQclear(res);
985997

986998
if (stream_wal)
999+
{
9871000
/* Wait for the completion of stream */
1001+
elog(LOG, "Wait end of WAL streaming");
9881002
pthread_join(stream_thread, NULL);
1003+
}
9891004
wait_wal_lsn(stop_backup_lsn);
9901005

9911006
/* Fill in fields if that is the correct end of backup. */

parsexlog.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -508,15 +508,7 @@ wal_contains_lsn(const char *archivedir, XLogRecPtr target_lsn,
508508
elog(ERROR, "out of memory");
509509

510510
res = XLogReadRecord(xlogreader, target_lsn, &errormsg) != NULL;
511-
if (!res)
512-
{
513-
if (errormsg)
514-
elog(ERROR, "could not read WAL record at %X/%X: %s",
515-
(uint32) (target_lsn >> 32), (uint32) (target_lsn),
516-
errormsg);
517-
518-
/* Didn't find 'target_lsn' and there is no error, return false */
519-
}
511+
/* Didn't find 'target_lsn' and there is no error, return false */
520512

521513
XLogReaderFree(xlogreader);
522514
if (xlogreadfd != -1)

0 commit comments

Comments
 (0)