Skip to content

Commit 64b05d9

Browse files
committed
[Issue #115]: minor improvements
1 parent a98ff61 commit 64b05d9

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

src/backup.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,22 +1528,22 @@ 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-
* Note, that with NullOffset target_lsn we do not wait
1531+
* Note, that with NullXRecOff target_lsn we do not wait
15321532
* for 'timeout / 2' seconds before going for previous record,
15331533
* because such LSN cannot be delivered at all.
15341534
*
15351535
* There are two cases for this:
15361536
* 1. Replica returned readpoint LSN which just do not exists. We want to look
15371537
* for previous record in the same(!) WAL segment which endpoint points to this LSN.
1538-
* 2. Replica returened endpoint LSN with 0 offset. We want to look
1538+
* 2. Replica returened endpoint LSN with NullXRecOff. We want to look
15391539
* for previous record which endpoint points greater or equal LSN in previous WAL segment.
15401540
*/
15411541
if (current.from_replica &&
15421542
(XRecOffIsNull(target_lsn) || try_count > timeout / 2))
15431543
{
15441544
XLogRecPtr res;
15451545

1546-
res = get_last_wal_lsn(wal_segment_dir, current.start_lsn, target_lsn, tli,
1546+
res = get_prior_record_lsn(wal_segment_dir, current.start_lsn, target_lsn, tli,
15471547
in_prev_segment, instance_config.xlog_seg_size);
15481548

15491549
if (!XLogRecPtrIsInvalid(res))
@@ -1803,7 +1803,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18031803

18041804
if (!XRecOffIsValid(stop_backup_lsn_tmp))
18051805
{
1806-
/* It is ok for replica to return STOP LSN with null offset */
1806+
/* It is ok for replica to return STOP LSN with NullXRecOff */
18071807
if (backup->from_replica && XRecOffIsNull(stop_backup_lsn_tmp))
18081808
{
18091809
char *xlog_path,
@@ -1820,7 +1820,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18201820

18211821
/*
18221822
* Note: even with gdb it is very hard to produce automated tests for
1823-
* contrecord + null_offset STOP_LSN, so emulate it for manual testing.
1823+
* contrecord + NullXRecOff, so emulate it for manual testing.
18241824
*/
18251825
//stop_backup_lsn_tmp = stop_backup_lsn_tmp - XLOG_SEG_SIZE;
18261826
//elog(WARNING, "New Invalid stop_backup_lsn value %X/%X",
@@ -1841,7 +1841,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18411841
/*
18421842
* Note, that there is no guarantee that corresponding WAL file even exists.
18431843
* Replica may return LSN from future and keep staying in present.
1844-
* Or it can return LSN with invalid XRecOff.
1844+
* Or it can return LSN with NullXRecOff.
18451845
*
18461846
* That's bad, since we want to get real LSN to save it in backup label file
18471847
* and to use it in WAL validation.
@@ -1851,17 +1851,16 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18511851
* look for the first valid record in it.
18521852
* It solves the problem of occasional invalid XRecOff on write-busy system.
18531853
* 2. Failing that, look for record in previous segment with endpoint
1854-
* equal or greater than stop_lsn. It may(!) solve the problem of 0 offset
1854+
* equal or greater than stop_lsn. It may(!) solve the problem of NullXRecOff
18551855
* on write-idle system. If that fails too, error out.
1856-
* //TODO what kind of record that refers to?
18571856
*/
18581857

18591858
/* Wait for segment with current stop_lsn, it is ok for it to never arrive */
18601859
wait_wal_lsn(stop_backup_lsn_tmp, false, backup->tli,
18611860
false, true, WARNING, stream_wal);
18621861

18631862
/* Get the first record in segment with current stop_lsn */
1864-
lsn_tmp = get_first_wal_lsn(xlog_path, segno, backup->tli,
1863+
lsn_tmp = get_first_record_lsn(xlog_path, segno, backup->tli,
18651864
instance_config.xlog_seg_size);
18661865

18671866
/* Check that returned LSN is valid and greater than stop_lsn */

src/parsexlog.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,10 @@ wal_contains_lsn(const char *archivedir, XLogRecPtr target_lsn,
529529
}
530530

531531
/*
532-
* Get LSN of first record within the WAL segment with number 'segno'.
533-
*
534-
* Returns LSN which points to end+1 of the last WAL record if seek_prev_segment
535-
* is true. Otherwise returns LSN of the record prior to stop_lsn.
532+
* Get LSN of a first record within the WAL segment with number 'segno'.
536533
*/
537534
XLogRecPtr
538-
get_first_wal_lsn(const char *archivedir, XLogSegNo segno,
535+
get_first_record_lsn(const char *archivedir, XLogSegNo segno,
539536
TimeLineID tli, uint32 wal_seg_size)
540537
{
541538
XLogReaderState *xlogreader;
@@ -574,20 +571,18 @@ get_first_wal_lsn(const char *archivedir, XLogSegNo segno,
574571
}
575572

576573
/*
577-
* Get LSN of last or prior record within the WAL segment with number 'segno'.
578-
* If 'start_lsn'
579-
* is in the segment with number 'segno' then start from 'start_lsn', otherwise
580-
* start from offset 0 within the segment.
574+
* Get LSN of a record prior to target_lsn.
575+
* If 'start_lsn' is in the segment with number 'segno' then start from 'start_lsn',
576+
* otherwise start from offset 0 within the segment.
581577
*
582-
* Returns LSN which points to end+1 of the last WAL record if seek_prev_segment
583-
* is true. Otherwise returns LSN of the record prior to stop_lsn.
578+
* Returns LSN of a record which EndRecPtr is greater or equal to target_lsn.
579+
* If 'seek_prev_segment' is true, then look for prior record in prior WAL segment.
584580
*
585-
* TODO Let's think of better function name.
586581
* it's unclear that "last" in "last_wal_lsn" refers to the
587582
* "closest to stop_lsn backward or forward, depending on seek_prev_segment setting".
588583
*/
589584
XLogRecPtr
590-
get_last_wal_lsn(const char *archivedir, XLogRecPtr start_lsn,
585+
get_prior_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
591586
XLogRecPtr stop_lsn, TimeLineID tli, bool seek_prev_segment,
592587
uint32 wal_seg_size)
593588
{

src/pg_probackup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,11 @@ extern bool read_recovery_info(const char *archivedir, TimeLineID tli,
711711
TransactionId *recovery_xid);
712712
extern bool wal_contains_lsn(const char *archivedir, XLogRecPtr target_lsn,
713713
TimeLineID target_tli, uint32 seg_size);
714-
extern XLogRecPtr get_last_wal_lsn(const char *archivedir, XLogRecPtr start_lsn,
714+
extern XLogRecPtr get_prior_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
715715
XLogRecPtr stop_lsn, TimeLineID tli,
716716
bool seek_prev_segment, uint32 seg_size);
717717

718-
extern XLogRecPtr get_first_wal_lsn(const char *archivedir, XLogRecPtr start_lsn,
718+
extern XLogRecPtr get_first_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
719719
TimeLineID tli, uint32 wal_seg_size);
720720

721721
/* in util.c */

0 commit comments

Comments
 (0)