@@ -1506,6 +1506,8 @@ wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn, TimeLineID tli,
15061506
15071507 if (file_exists )
15081508 {
1509+ //TODO is this comment also relates to current segment_only case
1510+ // and should be updated?
15091511 /* Do not check LSN for previous WAL segment */
15101512 if (segment_only )
15111513 return InvalidXLogRecPtr ;
@@ -1805,6 +1807,11 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18051807 XLogSegNo segno = 0 ;
18061808 XLogRecPtr lsn_tmp = InvalidXLogRecPtr ;
18071809
1810+ /*
1811+ * TODO Let's rephrase that to be less scary for a user.
1812+ * Even though the value is invalid, it's expected postgres behaviour
1813+ * and we're trying to fix it below.
1814+ */
18081815 elog (WARNING , "Invalid stop_backup_lsn value %X/%X" ,
18091816 (uint32 ) (stop_backup_lsn_tmp >> 32 ), (uint32 ) (stop_backup_lsn_tmp ));
18101817
@@ -1829,27 +1836,36 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18291836 GetXLogSegNo (stop_backup_lsn_tmp , segno , instance_config .xlog_seg_size );
18301837
18311838 /*
1832- * Note, that there is no guarantee that corresponding WAL file is even exists.
1833- * Basically replica may return LSN from future and keep staying in present.
1834- * Yeah, it sucks.
1839+ * Note, that there is no guarantee that corresponding WAL file even exists.
1840+ * Replica may return LSN from future and keep staying in present.
1841+ * Or it can return LSN with invalid XRecOff.
1842+ *
1843+ * That's bad, since we want to get real LSN to save it in backup label file
1844+ * and to use it in WAL validation.
18351845 *
1836- * So we should try to do the following:
1837- * 1. Wait for current segment and look in it for the LSN >= STOP_LSN. It should
1838- * solve the problem of occasional 0 offset on write-busy system.
1846+ * So we try to do the following:
1847+ * 1. Wait for current segment and look in it for the LSN >= STOP_LSN.
1848+ * //TODO what is 'current' segment?
1849+ * //TODO how long do we wait? is there a timeout?
1850+ * It solves the problem of occasional invalid XRecOff
1851+ * on write-busy system.
18391852 * 2. Failing that, look for record in previous segment with endpoint
18401853 * equal or greater than 0 offset LSN. It may(!) solve the problem of 0 offset
18411854 * on write-idle system.
1855+ * //TODO what if if didn't?
1856+ * //TODO what kind of record that refers to?
18421857 */
18431858
18441859 /* Wait for segment with current stop_lsn, it is ok for it to never arrive */
18451860 wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
18461861 false, true, WARNING , stream_wal );
18471862
1848- /* Optimistically try to get the first record in segment with current stop_lsn */
1863+ /* Get the first record in segment with current stop_lsn */
18491864 lsn_tmp = get_first_wal_lsn (xlog_path , segno , backup -> tli ,
18501865 instance_config .xlog_seg_size );
18511866
18521867 /* Check if returned LSN is satisfying our requirements */
1868+ //TODO what requirements?
18531869 if (XLogRecPtrIsInvalid (lsn_tmp ) ||
18541870 !XRecOffIsValid (lsn_tmp ) ||
18551871 lsn_tmp < stop_backup_lsn_tmp )
@@ -1877,6 +1893,9 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18771893 stop_backup_lsn = lsn_tmp ;
18781894 stop_lsn_exists = true;
18791895 }
1896+ //TODO is it good to throw an error here? Shouldn't we rather
1897+ // save it as is and mark backup as DONE instead of OK
1898+ // and check it in validation and restore?
18801899 else
18811900 elog (ERROR , "Invalid stop_backup_lsn value %X/%X" ,
18821901 (uint32 ) (stop_backup_lsn_tmp >> 32 ), (uint32 ) (stop_backup_lsn_tmp ));
@@ -1981,6 +2000,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
19812000
19822001 /*
19832002 * Wait for stop_lsn to be archived or streamed.
2003+ * //TODO is the sentence below outdated?
19842004 * If replica returned non-existent LSN, look for previous record,
19852005 * which endpoint >= stop_lsn
19862006 */
0 commit comments