Skip to content

Commit aab0ce3

Browse files
committed
PGPRO-2180: Fix stop_streaming(), read recovery info using valid stop LSN
1 parent b4672e3 commit aab0ce3

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/backup.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ static int checkpoint_timeout(void);
108108

109109
//static void backup_list_file(parray *files, const char *root, )
110110
static void parse_backup_filelist_filenames(parray *files, const char *root);
111-
static void wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn,
112-
bool wait_prev_lsn, bool wait_prev_segment);
111+
static XLogRecPtr wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn,
112+
bool wait_prev_lsn, bool wait_prev_segment);
113113
static void wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup);
114114
static void make_pagemap_from_ptrack(parray *files);
115115
static void *StreamLog(void *arg);
@@ -1502,8 +1502,11 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_filenode,
15021502
* be archived in archive 'wal' directory regardless stream mode.
15031503
*
15041504
* If 'wait_prev_segment' wait for previous segment.
1505+
*
1506+
* Returns LSN of last valid record if wait_prev_segment is not true, otherwise
1507+
* returns InvalidXLogRecPtr.
15051508
*/
1506-
static void
1509+
static XLogRecPtr
15071510
wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn, bool wait_prev_lsn,
15081511
bool wait_prev_segment)
15091512
{
@@ -1594,7 +1597,7 @@ wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn, bool wait_prev_lsn,
15941597
{
15951598
/* Do not check LSN for previous WAL segment */
15961599
if (wait_prev_segment)
1597-
return;
1600+
return InvalidXLogRecPtr;
15981601

15991602
/*
16001603
* A WAL segment found. Check LSN on it.
@@ -1605,7 +1608,7 @@ wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn, bool wait_prev_lsn,
16051608
/* Target LSN was found */
16061609
{
16071610
elog(LOG, "Found LSN: %X/%X", (uint32) (lsn >> 32), (uint32) lsn);
1608-
return;
1611+
return lsn;
16091612
}
16101613
}
16111614
else
@@ -1618,7 +1621,7 @@ wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn, bool wait_prev_lsn,
16181621
{
16191622
/* LSN of the prior record was found */
16201623
elog(LOG, "Found LSN: %X/%X", (uint32) (res >> 32), (uint32) res);
1621-
return;
1624+
return res;
16221625
}
16231626
}
16241627
}
@@ -2053,17 +2056,20 @@ pg_stop_backup(pgBackup *backup)
20532056
{
20542057
char *xlog_path,
20552058
stream_xlog_path[MAXPGPATH];
2059+
XLogRecPtr stop_valid_lsn = InvalidXLogRecPtr;
20562060

20572061
/* Wait for stop_lsn to be received by replica */
2058-
if (current.from_replica)
2059-
wait_replica_wal_lsn(stop_backup_lsn, false);
2062+
/* XXX Do we need this? */
2063+
// if (current.from_replica)
2064+
// wait_replica_wal_lsn(stop_backup_lsn, false);
20602065
/*
20612066
* Wait for stop_lsn to be archived or streamed.
20622067
* We wait for stop_lsn in stream mode just in case.
20632068
*/
20642069
if (!stop_lsn_exists)
2065-
wait_wal_lsn(stop_backup_lsn, false,
2066-
!exclusive_backup && current.from_replica, false);
2070+
stop_valid_lsn = wait_wal_lsn(stop_backup_lsn, false,
2071+
!exclusive_backup && current.from_replica,
2072+
false);
20672073

20682074
if (stream_wal)
20692075
{
@@ -2082,7 +2088,7 @@ pg_stop_backup(pgBackup *backup)
20822088

20832089
/* iterate over WAL from stop_backup lsn to start_backup lsn */
20842090
if (!read_recovery_info(xlog_path, backup->tli, xlog_seg_size,
2085-
backup->start_lsn, backup->stop_lsn,
2091+
backup->start_lsn, stop_valid_lsn,
20862092
&backup->recovery_time, &backup->recovery_xid))
20872093
{
20882094
elog(LOG, "Failed to find Recovery Time in WAL. Forced to trust current_timestamp");
@@ -2649,7 +2655,7 @@ stop_streaming(XLogRecPtr xlogpos, uint32 timeline, bool segment_finished)
26492655

26502656
if (!XLogRecPtrIsInvalid(stop_backup_lsn))
26512657
{
2652-
if (xlogpos > stop_backup_lsn)
2658+
if (xlogpos >= stop_backup_lsn)
26532659
{
26542660
stop_stream_lsn = xlogpos;
26552661
return true;

0 commit comments

Comments
 (0)