Skip to content

Commit a98ff61

Browse files
committed
[Issue #115]: some improvements of sanity and comments. Also do not wait for NullOffset LSN when looking for previous record
1 parent 07f63e4 commit a98ff61

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/backup.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,14 +1528,18 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
15281528
* If we failed to get target LSN in a reasonable time, try
15291529
* to get LSN of last valid record prior to the target LSN. But only
15301530
* in case of a backup from a replica.
1531-
1531+
* Note, that with NullOffset target_lsn we do not wait
1532+
* for 'timeout / 2' seconds before going for previous record,
1533+
* because such LSN cannot be delivered at all.
1534+
*
15321535
* There are two cases for this:
15331536
* 1. Replica returned readpoint LSN which just do not exists. We want to look
15341537
* for previous record in the same(!) WAL segment which endpoint points to this LSN.
15351538
* 2. Replica returened endpoint LSN with 0 offset. We want to look
15361539
* for previous record which endpoint points greater or equal LSN in previous WAL segment.
15371540
*/
1538-
if (!exclusive_backup && current.from_replica && try_count > timeout / 2)
1541+
if (current.from_replica &&
1542+
(XRecOffIsNull(target_lsn) || try_count > timeout / 2))
15391543
{
15401544
XLogRecPtr res;
15411545

@@ -1641,7 +1645,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
16411645
* Only if backup is from master.
16421646
* For PG 9.5 create restore point only if pguser is superuser.
16431647
*/
1644-
if (backup != NULL && !current.from_replica &&
1648+
if (backup != NULL && !backup->from_replica &&
16451649
!(nodeInfo->server_version < 90600 &&
16461650
!nodeInfo->is_superuser))
16471651
{
@@ -1677,7 +1681,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
16771681
* In case of backup from replica >= 9.6 we do not trust minRecPoint
16781682
* and stop_backup LSN, so we use latest replayed LSN as STOP LSN.
16791683
*/
1680-
if (current.from_replica)
1684+
if (backup->from_replica)
16811685
stop_backup_query = "SELECT"
16821686
" pg_catalog.txid_snapshot_xmax(pg_catalog.txid_current_snapshot()),"
16831687
" current_timestamp(0)::timestamptz,"
@@ -1799,8 +1803,8 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17991803

18001804
if (!XRecOffIsValid(stop_backup_lsn_tmp))
18011805
{
1802-
/* Replica returned STOP LSN with null offset */
1803-
if (XRecOffIsNull(stop_backup_lsn_tmp))
1806+
/* It is ok for replica to return STOP LSN with null offset */
1807+
if (backup->from_replica && XRecOffIsNull(stop_backup_lsn_tmp))
18041808
{
18051809
char *xlog_path,
18061810
stream_xlog_path[MAXPGPATH];
@@ -1888,7 +1892,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18881892
stop_backup_lsn = lsn_tmp;
18891893
stop_lsn_exists = true;
18901894
}
1891-
/* Replica returned something very illegal, error out */
1895+
/* PostgreSQL returned something very illegal as STOP_LSN, error out */
18921896
else
18931897
elog(ERROR, "Invalid stop_backup_lsn value %X/%X",
18941898
(uint32) (stop_backup_lsn_tmp >> 32), (uint32) (stop_backup_lsn_tmp));
@@ -1898,7 +1902,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18981902
if (!exclusive_backup)
18991903
{
19001904
Assert(PQnfields(res) >= 4);
1901-
pgBackupGetPath(&current, path, lengthof(path), DATABASE_DIR);
1905+
pgBackupGetPath(backup, path, lengthof(path), DATABASE_DIR);
19021906

19031907
/* Write backup_label */
19041908
join_path_components(backup_label, path, PG_BACKUP_LABEL_FILE);

tests/replica.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ def test_replica_stop_lsn_null_offset(self):
586586
return_id=False)
587587

588588
self.assertIn(
589-
'WARNING: Invalid stop_backup_lsn value 0/3000000',
589+
'LOG: Null offset in stop_backup_lsn value 0/3000000',
590590
output)
591591

592592
self.assertIn(
@@ -601,10 +601,6 @@ def test_replica_stop_lsn_null_offset(self):
601601
'LOG: Looking for LSN 0/3000000 in segment: 000000010000000000000002',
602602
output)
603603

604-
self.assertIn(
605-
'INFO: Wait for LSN 0/3000000 in streamed WAL segment',
606-
output)
607-
608604
self.assertIn(
609605
'LOG: Record 0/2000160 has endpoint 0/3000000 which is '
610606
'equal or greater than requested LSN 0/3000000',
@@ -697,7 +693,7 @@ def test_replica_stop_lsn_null_offset_next_record(self):
697693
log_content = f.read()
698694

699695
self.assertIn(
700-
'WARNING: Invalid stop_backup_lsn value 0/3000000',
696+
'LOG: Null offset in stop_backup_lsn value 0/3000000',
701697
log_content)
702698

703699
self.assertIn(
@@ -766,7 +762,7 @@ def test_archive_replica_null_offset(self):
766762
return_id=False)
767763

768764
self.assertIn(
769-
'WARNING: Invalid stop_backup_lsn value 0/3000000',
765+
'LOG: Null offset in stop_backup_lsn value 0/3000000',
770766
output)
771767

772768
self.assertIn(
@@ -790,6 +786,8 @@ def test_archive_replica_null_offset(self):
790786
'LOG: Found prior LSN: 0/2000160',
791787
output)
792788

789+
print(output)
790+
793791
# Clean after yourself
794792
self.del_test_dir(module_name, fname)
795793

@@ -949,6 +947,8 @@ def test_replica_toast(self):
949947
'LOG: Found prior LSN:',
950948
output)
951949

950+
print(output)
951+
952952
replica.cleanup()
953953
self.restore_node(backup_dir, 'replica', replica)
954954

0 commit comments

Comments
 (0)