Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c919c58

Browse files
author
Arthur Zakirov
committed
Wait previous segment for start_lsn
1 parent a5667d3 commit c919c58

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/backup.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static int checkpoint_timeout(void);
8585

8686
static void add_pgdata_files(parray *files, const char *root);
8787
static void write_backup_file_list(parray *files, const char *root);
88-
static void wait_wal_lsn(XLogRecPtr lsn);
88+
static void wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment);
8989
static void wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup);
9090
static void make_pagemap_from_ptrack(parray *files);
9191
static void StreamLog(void *arg);
@@ -645,7 +645,7 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
645645
* Because WAL streaming will start after pg_start_backup() in stream
646646
* mode.
647647
*/
648-
wait_wal_lsn(backup->start_lsn);
648+
wait_wal_lsn(backup->start_lsn, true);
649649

650650
/* Wait for start_lsn to be replayed by replica */
651651
if (from_replica)
@@ -814,9 +814,11 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_oid,
814814
* archive 'wal' directory with WAL segment file.
815815
* If current backup started in stream mode wait for 'lsn' to be streamed in
816816
* 'pg_xlog' directory.
817+
*
818+
* If 'wait_prev_segment' wait for previous segment.
817819
*/
818820
static void
819-
wait_wal_lsn(XLogRecPtr lsn)
821+
wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
820822
{
821823
TimeLineID tli;
822824
XLogSegNo targetSegNo;
@@ -830,6 +832,8 @@ wait_wal_lsn(XLogRecPtr lsn)
830832

831833
/* Compute the name of the WAL file containig requested LSN */
832834
XLByteToSeg(lsn, targetSegNo);
835+
if (wait_prev_segment)
836+
targetSegNo--;
833837
XLogFileName(wal_segment, tli, targetSegNo);
834838

835839
if (stream_wal)
@@ -1196,7 +1200,7 @@ pg_stop_backup(pgBackup *backup)
11961200
* Wait for stop_lsn to be archived or streamed.
11971201
* We wait for stop_lsn in stream mode just in case.
11981202
*/
1199-
wait_wal_lsn(stop_backup_lsn);
1203+
wait_wal_lsn(stop_backup_lsn, false);
12001204

12011205
if (stream_wal)
12021206
{

0 commit comments

Comments
 (0)