Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8952b84

Browse files
committed
[PBCKP-434] greatly simplify stop_lsn handling
It was long believed `stop_lsn` should point on start of last record.But in fact it points to end of last record (because XLogInsert(BACKUP_END)returns pointer to end of record, and that is what pg_backup_stop/pg_stop_backup returns).So we don't need to lookup `stop_lsn` record in WAL log, but rather checkexistence of record which ends on `stop_lsn` (which is what`get_prior_record_lsn` does).And there is no need to raise error on `stop_lsn` which points on block end- it is very valid when xlog record ends at block end.So:- we simplify wait_wal_lsn to just wait for `get_prior_record_lsn` returns "ok" (ie find such previous record). But now we don't overwrite stop_lsn with lsn of this record.- we use `wait_wal_lsn` only in "ARCHIVE" mode/directory. So get rid of `in_stream_dir` argument.- and `wait_wal_lsn` now waits only for previous record even for `is_start_lsn`, since there is no much gain in waiting for it. Even for PAGE mode we need only records before `start_lsn`, since `start_lsn` record is considered as part of backup.- "STREAM" mode now waits for lsn by hooking streamer. We don't need to calculate stop_backup_lsn since we may use stop_backup_result.lsn directly to stop streamer. After streamer stopped, we just check wal with `get_prior_record_lsn`. We don't need to, but just for sanity.- therefore `wait_wal_and_calculate_stop_lsn` become obsolete. Lets get rid of it. Without it, there is no need in get_first_record_lsn and get_next_record_lsn. Lets delete them too.- Instead of using XRecOffIsValid and XRecOffIsNull use added XRecPtrLooksGood and XRecEndLooksGood. XRecPtrLooksGood validates record start more rigidly than XRecOffIsValid, and XRecEndLooksGood validates record end, which could be on block end.- In fact, some of `XRecOffIsValid(x)` had to be `!XLogRecPtrIsInvalid(x)`- Since stop_lsn is not inclusive now, RunXLogThreads doesn't need `inclusive_endpoint` parameter. (And because Page mode needs just till start_lsn)- PAGE_LSN_FROM_FUTURE must be considered as error, btw.(And by the way there's no need to XLogBeginRead before XLogFindNextRecord. Cleanup such calls)
1 parent79b8755 commit8952b84

File tree

9 files changed

+259
-575
lines changed

9 files changed

+259
-575
lines changed

‎src/backup.c

Lines changed: 55 additions & 241 deletions
Large diffs are not rendered by default.

‎src/catalog.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include"utils/file.h"
1919
#include"utils/configuration.h"
2020

21-
staticpgBackup*get_closest_backup(timelineInfo*tlinfo);
22-
staticpgBackup*get_oldest_backup(timelineInfo*tlinfo);
21+
staticpgBackup*get_closest_backup(timelineInfo*tlinfo,uint32_txlog_seg_size);
22+
staticpgBackup*get_oldest_backup(timelineInfo*tlinfo,uint32_txlog_seg_size);
2323
staticconstchar*backupModes[]= {"","PAGE","PTRACK","DELTA","FULL"};
2424
staticerr_icreate_backup_dir(pgBackup*backup,constchar*backup_instance_path);
2525

@@ -1857,8 +1857,8 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
18571857
{
18581858
timelineInfo*tlinfo=parray_get(timelineinfos,i);
18591859

1860-
tlinfo->oldest_backup=get_oldest_backup(tlinfo);
1861-
tlinfo->closest_backup=get_closest_backup(tlinfo);
1860+
tlinfo->oldest_backup=get_oldest_backup(tlinfo,instance->xlog_seg_size);
1861+
tlinfo->closest_backup=get_closest_backup(tlinfo,instance->xlog_seg_size);
18621862
}
18631863

18641864
/* determine which WAL segments must be kept because of wal retention */
@@ -2222,7 +2222,7 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
22222222
* timeline is unreachable. Return NULL.
22232223
*/
22242224
pgBackup*
2225-
get_closest_backup(timelineInfo*tlinfo)
2225+
get_closest_backup(timelineInfo*tlinfo,uint32xlog_seg_size)
22262226
{
22272227
pgBackup*closest_backup=NULL;
22282228
inti;
@@ -2245,7 +2245,7 @@ get_closest_backup(timelineInfo *tlinfo)
22452245
* should be considered.
22462246
*/
22472247
if (!XLogRecPtrIsInvalid(backup->stop_lsn)&&
2248-
XRecOffIsValid(backup->stop_lsn)&&
2248+
XRecEndLooksGood(backup->stop_lsn,xlog_seg_size)&&
22492249
backup->stop_lsn <=tlinfo->switchpoint&&
22502250
(backup->status==BACKUP_STATUS_OK||
22512251
backup->status==BACKUP_STATUS_DONE))
@@ -2273,7 +2273,7 @@ get_closest_backup(timelineInfo *tlinfo)
22732273
* there is no backups on this timeline. Return NULL.
22742274
*/
22752275
pgBackup*
2276-
get_oldest_backup(timelineInfo*tlinfo)
2276+
get_oldest_backup(timelineInfo*tlinfo,uint32_txlog_seg_size)
22772277
{
22782278
pgBackup*oldest_backup=NULL;
22792279
inti;
@@ -2287,7 +2287,7 @@ get_oldest_backup(timelineInfo *tlinfo)
22872287

22882288
/* Backups with invalid START LSN can be safely skipped */
22892289
if (XLogRecPtrIsInvalid(backup->start_lsn)||
2290-
!XRecOffIsValid(backup->start_lsn))
2290+
!XRecPtrLooksGood(backup->start_lsn,xlog_seg_size))
22912291
continue;
22922292

22932293
/*

‎src/catchup.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,26 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
10481048
pg_free(stop_backup_query_text);
10491049
}
10501050

1051+
/* wait for end of wal streaming and calculate wal size transfered */
10511052
if (!dry_run)
1052-
wait_wal_and_calculate_stop_lsn(dest_xlog_path,stop_backup_result.lsn,&current);
1053+
{
1054+
parray*wal_files_list=NULL;
1055+
wal_files_list=parray_new();
1056+
1057+
if (wait_WAL_streaming_end(wal_files_list,dest_xlog_path,
1058+
stop_backup_result.lsn,&current))
1059+
elog(ERROR,"WAL streaming failed");
1060+
1061+
for (i=0;i<parray_num(wal_files_list);i++)
1062+
{
1063+
pgFile*file= (pgFile*)parray_get(wal_files_list,i);
1064+
transfered_walfiles_bytes+=file->size;
1065+
}
1066+
1067+
parray_walk(wal_files_list,pgFileFree);
1068+
parray_free(wal_files_list);
1069+
wal_files_list=NULL;
1070+
}
10531071

10541072
/* Write backup_label */
10551073
Assert(stop_backup_result.backup_label_content.len!=0);
@@ -1075,26 +1093,6 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
10751093
}
10761094
ft_str_free(&stop_backup_result.tablespace_map_content);
10771095

1078-
/* wait for end of wal streaming and calculate wal size transfered */
1079-
if (!dry_run)
1080-
{
1081-
parray*wal_files_list=NULL;
1082-
wal_files_list=parray_new();
1083-
1084-
if (wait_WAL_streaming_end(wal_files_list))
1085-
elog(ERROR,"WAL streaming failed");
1086-
1087-
for (i=0;i<parray_num(wal_files_list);i++)
1088-
{
1089-
pgFile*file= (pgFile*)parray_get(wal_files_list,i);
1090-
transfered_walfiles_bytes+=file->size;
1091-
}
1092-
1093-
parray_walk(wal_files_list,pgFileFree);
1094-
parray_free(wal_files_list);
1095-
wal_files_list=NULL;
1096-
}
1097-
10981096
/*
10991097
* In case of backup from replica we must fix minRecPoint
11001098
*/

‎src/compatibility/receivelog.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
496496
*/
497497
lastFlushPosition=stream->startpos;
498498
stream->currentpos=0;
499-
stream->prevpos=0;
500499

501500
while (1)
502501
{
@@ -781,12 +780,11 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
781780
}
782781
elseif (copybuf[0]=='w')
783782
{
784-
boolok=ProcessXLogDataMsg(conn,stream,copybuf,r,&blockpos);
785-
stream->prevpos=stream->currentpos;
786-
stream->currentpos=blockpos;
787-
if (!ok)
783+
if (!ProcessXLogDataMsg(conn,stream,copybuf,r,&blockpos))
788784
gotoerror;
789785

786+
stream->currentpos=blockpos;
787+
790788
/*
791789
* Check if we should continue streaming, or abort at this
792790
* point.

‎src/compatibility/receivelog.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ typedef struct StreamCtl
3030
{
3131
XLogRecPtrstartpos;/* Start position for streaming */
3232
volatileXLogRecPtrcurrentpos;/* current position */
33-
volatileXLogRecPtrprevpos;/* current position */
34-
volatileTimeLineIDtimeline;/* Timeline to stream data from */
33+
TimeLineIDtimeline;/* Timeline to stream data from */
3534
char*sysidentifier;/* Validate this system identifier and
3635
* timeline */
3736
intstandby_message_timeout;/* Send status messages this often */

‎src/data.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,7 @@ validate_file_pages(pgFile *file, const char *fullpath, XLogRecPtr stop_lsn,
15411541
checksum_version ?"correct" :"not enabled",
15421542
(uint32) (page_st.lsn >>32), (uint32)page_st.lsn,
15431543
(uint32) (stop_lsn >>32), (uint32)stop_lsn);
1544+
is_valid= false;
15441545
break;
15451546
}
15461547
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp