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

Commitebeebca

Browse files
committed
Get last valid WAL record correctly using sorted thread_args array
1 parentaa1812e commitebeebca

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

‎src/parsexlog.c

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,18 @@ InitXLogPageRead(XLogReaderData *reader_data, const char *archivedir,
860860
returnxlogreader;
861861
}
862862

863+
/*
864+
* Comparison function to sort xlog_thread_arg array.
865+
*/
866+
staticint
867+
xlog_thread_arg_comp(constvoid*a1,constvoid*a2)
868+
{
869+
constxlog_thread_arg*arg1=a1;
870+
constxlog_thread_arg*arg2=a2;
871+
872+
returnarg1->reader_data.xlogsegno-arg2->reader_data.xlogsegno;
873+
}
874+
863875
/*
864876
* Run WAL processing routines using threads. Start from startpoint up to
865877
* endpoint. It is possible to send zero endpoint, threads will read WAL
@@ -877,7 +889,6 @@ RunXLogThreads(const char *archivedir, time_t target_time,
877889
inti;
878890
intthreads_need=0;
879891
XLogSegNoendSegNo=0;
880-
XLogSegNoerrorSegNo=0;
881892
boolresult= true;
882893

883894
if (!XRecOffIsValid(startpoint))
@@ -956,28 +967,27 @@ RunXLogThreads(const char *archivedir, time_t target_time,
956967
result= false;
957968
}
958969

970+
/* Release threads here, use thread_args only below */
971+
pfree(threads);
972+
threads=NULL;
973+
959974
if (last_rec)
975+
{
976+
/*
977+
* We need to sort xlog_thread_arg array by xlogsegno to return latest
978+
* possible record up to which restore is possible. We need to sort to
979+
* detect failed thread between start segment and target segment.
980+
*
981+
* Loop stops on first failed thread.
982+
*/
983+
if (threads_need>1)
984+
qsort((void*)thread_args,threads_need,sizeof(xlog_thread_arg),
985+
xlog_thread_arg_comp);
986+
960987
for (i=0;i<threads_need;i++)
961988
{
962989
XLogRecTarget*cur_rec;
963990

964-
if (thread_args[i].ret!=0)
965-
{
966-
/*
967-
* Save invalid segment number after which all segments are not
968-
* valid.
969-
*/
970-
if (errorSegNo==0||
971-
errorSegNo>thread_args[i].reader_data.xlogsegno)
972-
errorSegNo=thread_args[i].reader_data.xlogsegno;
973-
continue;
974-
}
975-
976-
/* Is this segment valid */
977-
if (errorSegNo!=0&&
978-
thread_args[i].reader_data.xlogsegno>errorSegNo)
979-
continue;
980-
981991
cur_rec=&thread_args[i].reader_data.cur_rec;
982992
/*
983993
* If we got the target return minimum possible record.
@@ -997,9 +1007,16 @@ RunXLogThreads(const char *archivedir, time_t target_time,
9971007
*/
9981008
elseif (last_rec->rec_lsn<cur_rec->rec_lsn)
9991009
*last_rec=*cur_rec;
1010+
1011+
/*
1012+
* We reached failed thread, so stop here. We cannot use following
1013+
* WAL records after failed segment.
1014+
*/
1015+
if (thread_args[i].ret!=0)
1016+
break;
10001017
}
1018+
}
10011019

1002-
pfree(threads);
10031020
pfree(thread_args);
10041021

10051022
returnresult;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp