mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2024-11-25 09:01:48 +02:00
[Issue #115]: minor improvements
This commit is contained in:
parent
a98ff6154a
commit
64b05d9597
17
src/backup.c
17
src/backup.c
@ -1528,14 +1528,14 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
|
||||
* If we failed to get target LSN in a reasonable time, try
|
||||
* to get LSN of last valid record prior to the target LSN. But only
|
||||
* in case of a backup from a replica.
|
||||
* Note, that with NullOffset target_lsn we do not wait
|
||||
* Note, that with NullXRecOff target_lsn we do not wait
|
||||
* for 'timeout / 2' seconds before going for previous record,
|
||||
* because such LSN cannot be delivered at all.
|
||||
*
|
||||
* There are two cases for this:
|
||||
* 1. Replica returned readpoint LSN which just do not exists. We want to look
|
||||
* for previous record in the same(!) WAL segment which endpoint points to this LSN.
|
||||
* 2. Replica returened endpoint LSN with 0 offset. We want to look
|
||||
* 2. Replica returened endpoint LSN with NullXRecOff. We want to look
|
||||
* for previous record which endpoint points greater or equal LSN in previous WAL segment.
|
||||
*/
|
||||
if (current.from_replica &&
|
||||
@ -1543,7 +1543,7 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
|
||||
{
|
||||
XLogRecPtr res;
|
||||
|
||||
res = get_last_wal_lsn(wal_segment_dir, current.start_lsn, target_lsn, tli,
|
||||
res = get_prior_record_lsn(wal_segment_dir, current.start_lsn, target_lsn, tli,
|
||||
in_prev_segment, instance_config.xlog_seg_size);
|
||||
|
||||
if (!XLogRecPtrIsInvalid(res))
|
||||
@ -1803,7 +1803,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
|
||||
|
||||
if (!XRecOffIsValid(stop_backup_lsn_tmp))
|
||||
{
|
||||
/* It is ok for replica to return STOP LSN with null offset */
|
||||
/* It is ok for replica to return STOP LSN with NullXRecOff */
|
||||
if (backup->from_replica && XRecOffIsNull(stop_backup_lsn_tmp))
|
||||
{
|
||||
char *xlog_path,
|
||||
@ -1820,7 +1820,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
|
||||
|
||||
/*
|
||||
* Note: even with gdb it is very hard to produce automated tests for
|
||||
* contrecord + null_offset STOP_LSN, so emulate it for manual testing.
|
||||
* contrecord + NullXRecOff, so emulate it for manual testing.
|
||||
*/
|
||||
//stop_backup_lsn_tmp = stop_backup_lsn_tmp - XLOG_SEG_SIZE;
|
||||
//elog(WARNING, "New Invalid stop_backup_lsn value %X/%X",
|
||||
@ -1841,7 +1841,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
|
||||
/*
|
||||
* Note, that there is no guarantee that corresponding WAL file even exists.
|
||||
* Replica may return LSN from future and keep staying in present.
|
||||
* Or it can return LSN with invalid XRecOff.
|
||||
* Or it can return LSN with NullXRecOff.
|
||||
*
|
||||
* That's bad, since we want to get real LSN to save it in backup label file
|
||||
* and to use it in WAL validation.
|
||||
@ -1851,9 +1851,8 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
|
||||
* look for the first valid record in it.
|
||||
* It solves the problem of occasional invalid XRecOff on write-busy system.
|
||||
* 2. Failing that, look for record in previous segment with endpoint
|
||||
* equal or greater than stop_lsn. It may(!) solve the problem of 0 offset
|
||||
* equal or greater than stop_lsn. It may(!) solve the problem of NullXRecOff
|
||||
* on write-idle system. If that fails too, error out.
|
||||
* //TODO what kind of record that refers to?
|
||||
*/
|
||||
|
||||
/* Wait for segment with current stop_lsn, it is ok for it to never arrive */
|
||||
@ -1861,7 +1860,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
|
||||
false, true, WARNING, stream_wal);
|
||||
|
||||
/* Get the first record in segment with current stop_lsn */
|
||||
lsn_tmp = get_first_wal_lsn(xlog_path, segno, backup->tli,
|
||||
lsn_tmp = get_first_record_lsn(xlog_path, segno, backup->tli,
|
||||
instance_config.xlog_seg_size);
|
||||
|
||||
/* Check that returned LSN is valid and greater than stop_lsn */
|
||||
|
@ -529,13 +529,10 @@ wal_contains_lsn(const char *archivedir, XLogRecPtr target_lsn,
|
||||
}
|
||||
|
||||
/*
|
||||
* Get LSN of first record within the WAL segment with number 'segno'.
|
||||
*
|
||||
* Returns LSN which points to end+1 of the last WAL record if seek_prev_segment
|
||||
* is true. Otherwise returns LSN of the record prior to stop_lsn.
|
||||
* Get LSN of a first record within the WAL segment with number 'segno'.
|
||||
*/
|
||||
XLogRecPtr
|
||||
get_first_wal_lsn(const char *archivedir, XLogSegNo segno,
|
||||
get_first_record_lsn(const char *archivedir, XLogSegNo segno,
|
||||
TimeLineID tli, uint32 wal_seg_size)
|
||||
{
|
||||
XLogReaderState *xlogreader;
|
||||
@ -574,20 +571,18 @@ get_first_wal_lsn(const char *archivedir, XLogSegNo segno,
|
||||
}
|
||||
|
||||
/*
|
||||
* Get LSN of last or prior record within the WAL segment with number 'segno'.
|
||||
* If 'start_lsn'
|
||||
* is in the segment with number 'segno' then start from 'start_lsn', otherwise
|
||||
* start from offset 0 within the segment.
|
||||
* Get LSN of a record prior to target_lsn.
|
||||
* If 'start_lsn' is in the segment with number 'segno' then start from 'start_lsn',
|
||||
* otherwise start from offset 0 within the segment.
|
||||
*
|
||||
* Returns LSN which points to end+1 of the last WAL record if seek_prev_segment
|
||||
* is true. Otherwise returns LSN of the record prior to stop_lsn.
|
||||
* Returns LSN of a record which EndRecPtr is greater or equal to target_lsn.
|
||||
* If 'seek_prev_segment' is true, then look for prior record in prior WAL segment.
|
||||
*
|
||||
* TODO Let's think of better function name.
|
||||
* it's unclear that "last" in "last_wal_lsn" refers to the
|
||||
* "closest to stop_lsn backward or forward, depending on seek_prev_segment setting".
|
||||
*/
|
||||
XLogRecPtr
|
||||
get_last_wal_lsn(const char *archivedir, XLogRecPtr start_lsn,
|
||||
get_prior_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
|
||||
XLogRecPtr stop_lsn, TimeLineID tli, bool seek_prev_segment,
|
||||
uint32 wal_seg_size)
|
||||
{
|
||||
|
@ -711,11 +711,11 @@ extern bool read_recovery_info(const char *archivedir, TimeLineID tli,
|
||||
TransactionId *recovery_xid);
|
||||
extern bool wal_contains_lsn(const char *archivedir, XLogRecPtr target_lsn,
|
||||
TimeLineID target_tli, uint32 seg_size);
|
||||
extern XLogRecPtr get_last_wal_lsn(const char *archivedir, XLogRecPtr start_lsn,
|
||||
extern XLogRecPtr get_prior_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
|
||||
XLogRecPtr stop_lsn, TimeLineID tli,
|
||||
bool seek_prev_segment, uint32 seg_size);
|
||||
|
||||
extern XLogRecPtr get_first_wal_lsn(const char *archivedir, XLogRecPtr start_lsn,
|
||||
extern XLogRecPtr get_first_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
|
||||
TimeLineID tli, uint32 wal_seg_size);
|
||||
|
||||
/* in util.c */
|
||||
|
Loading…
Reference in New Issue
Block a user