@@ -148,10 +148,12 @@ typedef struct
148148 int ret ;
149149} xlog_thread_arg ;
150150
151+ static XLogRecord * WalReadRecord (XLogReaderState * xlogreader , XLogRecPtr startpoint , char * * errormsg );
152+ static XLogReaderState * WalReaderAllocate (uint32 wal_seg_size , XLogReaderData * reader_data );
153+
151154static int SimpleXLogPageRead (XLogReaderState * xlogreader ,
152155 XLogRecPtr targetPagePtr ,
153- int reqLen , XLogRecPtr targetRecPtr , char * readBuf ,
154- TimeLineID * pageTLI );
156+ int reqLen , XLogRecPtr targetRecPtr , char * readBuf );
155157static XLogReaderState * InitXLogPageRead (XLogReaderData * reader_data ,
156158 const char * archivedir ,
157159 TimeLineID tli , uint32 segment_size ,
@@ -551,7 +553,13 @@ read_recovery_info(const char *archivedir, TimeLineID tli, uint32 wal_seg_size,
551553 TimestampTz last_time = 0 ;
552554 char * errormsg ;
553555
554- record = XLogReadRecord (xlogreader , startpoint , & errormsg );
556+ #if PG_VERSION_NUM >= 130000
557+ if (XLogRecPtrIsInvalid (startpoint ))
558+ startpoint = SizeOfXLogShortPHD ;
559+ XLogBeginRead (xlogreader , startpoint );
560+ #endif
561+
562+ record = WalReadRecord (xlogreader , startpoint , & errormsg );
555563 if (record == NULL )
556564 {
557565 XLogRecPtr errptr ;
@@ -615,7 +623,13 @@ wal_contains_lsn(const char *archivedir, XLogRecPtr target_lsn,
615623
616624 xlogreader -> system_identifier = instance_config .system_identifier ;
617625
618- res = XLogReadRecord (xlogreader , target_lsn , & errormsg ) != NULL ;
626+ #if PG_VERSION_NUM >= 130000
627+ if (XLogRecPtrIsInvalid (target_lsn ))
628+ target_lsn = SizeOfXLogShortPHD ;
629+ XLogBeginRead (xlogreader , target_lsn );
630+ #endif
631+
632+ res = WalReadRecord (xlogreader , target_lsn , & errormsg ) != NULL ;
619633 /* Didn't find 'target_lsn' and there is no error, return false */
620634
621635 if (errormsg )
@@ -656,6 +670,12 @@ get_first_record_lsn(const char *archivedir, XLogSegNo segno,
656670 /* Set startpoint to 0 in segno */
657671 GetXLogRecPtr (segno , 0 , wal_seg_size , startpoint );
658672
673+ #if PG_VERSION_NUM >= 130000
674+ if (XLogRecPtrIsInvalid (startpoint ))
675+ startpoint = SizeOfXLogShortPHD ;
676+ XLogBeginRead (xlogreader , startpoint );
677+ #endif
678+
659679 while (attempts <= timeout )
660680 {
661681 record = XLogFindNextRecord (xlogreader , startpoint );
@@ -710,6 +730,12 @@ get_next_record_lsn(const char *archivedir, XLogSegNo segno,
710730 /* Set startpoint to 0 in segno */
711731 GetXLogRecPtr (segno , 0 , wal_seg_size , startpoint );
712732
733+ #if PG_VERSION_NUM >= 130000
734+ if (XLogRecPtrIsInvalid (startpoint ))
735+ startpoint = SizeOfXLogShortPHD ;
736+ XLogBeginRead (xlogreader , startpoint );
737+ #endif
738+
713739 found = XLogFindNextRecord (xlogreader , startpoint );
714740
715741 if (XLogRecPtrIsInvalid (found ))
@@ -733,7 +759,7 @@ get_next_record_lsn(const char *archivedir, XLogSegNo segno,
733759 if (interrupted )
734760 elog (ERROR , "Interrupted during WAL reading" );
735761
736- record = XLogReadRecord (xlogreader , startpoint , & errormsg );
762+ record = WalReadRecord (xlogreader , startpoint , & errormsg );
737763
738764 if (record == NULL )
739765 {
@@ -822,6 +848,13 @@ get_prior_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
822848 XLogRecPtr found ;
823849
824850 GetXLogRecPtr (segno , 0 , wal_seg_size , startpoint );
851+
852+ #if PG_VERSION_NUM >= 130000
853+ if (XLogRecPtrIsInvalid (startpoint ))
854+ startpoint = SizeOfXLogShortPHD ;
855+ XLogBeginRead (xlogreader , startpoint );
856+ #endif
857+
825858 found = XLogFindNextRecord (xlogreader , startpoint );
826859
827860 if (XLogRecPtrIsInvalid (found ))
@@ -846,7 +879,7 @@ get_prior_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
846879 if (interrupted )
847880 elog (ERROR , "Interrupted during WAL reading" );
848881
849- record = XLogReadRecord (xlogreader , startpoint , & errormsg );
882+ record = WalReadRecord (xlogreader , startpoint , & errormsg );
850883 if (record == NULL )
851884 {
852885 XLogRecPtr errptr ;
@@ -905,8 +938,7 @@ get_gz_error(gzFile gzf)
905938/* XLogreader callback function, to read a WAL page */
906939static int
907940SimpleXLogPageRead (XLogReaderState * xlogreader , XLogRecPtr targetPagePtr ,
908- int reqLen , XLogRecPtr targetRecPtr , char * readBuf ,
909- TimeLineID * pageTLI )
941+ int reqLen , XLogRecPtr targetRecPtr , char * readBuf )
910942{
911943 XLogReaderData * reader_data ;
912944 uint32 targetPageOff ;
@@ -1040,7 +1072,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
10401072 reader_data -> prev_page_off == targetPageOff )
10411073 {
10421074 memcpy (readBuf , reader_data -> page_buf , XLOG_BLCKSZ );
1043- * pageTLI = reader_data -> tli ;
1075+ // *pageTLI = reader_data->tli;
10441076 return XLOG_BLCKSZ ;
10451077 }
10461078
@@ -1084,7 +1116,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
10841116
10851117 memcpy (reader_data -> page_buf , readBuf , XLOG_BLCKSZ );
10861118 reader_data -> prev_page_off = targetPageOff ;
1087- * pageTLI = reader_data -> tli ;
1119+ // *pageTLI = reader_data->tli;
10881120 return XLOG_BLCKSZ ;
10891121}
10901122
@@ -1109,12 +1141,7 @@ InitXLogPageRead(XLogReaderData *reader_data, const char *archivedir,
11091141
11101142 if (allocate_reader )
11111143 {
1112- #if PG_VERSION_NUM >= 110000
1113- xlogreader = XLogReaderAllocate (wal_seg_size , & SimpleXLogPageRead ,
1114- reader_data );
1115- #else
1116- xlogreader = XLogReaderAllocate (& SimpleXLogPageRead , reader_data );
1117- #endif
1144+ xlogreader = WalReaderAllocate (wal_seg_size , reader_data );
11181145 if (xlogreader == NULL )
11191146 elog (ERROR , "Out of memory" );
11201147 xlogreader -> system_identifier = instance_config .system_identifier ;
@@ -1314,16 +1341,18 @@ XLogThreadWorker(void *arg)
13141341 uint32 prev_page_off = 0 ;
13151342 bool need_read = true;
13161343
1317- #if PG_VERSION_NUM >= 110000
1318- xlogreader = XLogReaderAllocate (wal_seg_size , & SimpleXLogPageRead ,
1319- reader_data );
1320- #else
1321- xlogreader = XLogReaderAllocate (& SimpleXLogPageRead , reader_data );
1322- #endif
1344+ xlogreader = WalReaderAllocate (wal_seg_size , reader_data );
1345+
13231346 if (xlogreader == NULL )
13241347 elog (ERROR , "Thread [%d]: out of memory" , reader_data -> thread_num );
13251348 xlogreader -> system_identifier = instance_config .system_identifier ;
13261349
1350+ #if PG_VERSION_NUM >= 130000
1351+ if (XLogRecPtrIsInvalid (thread_arg -> startpoint ))
1352+ thread_arg -> startpoint = SizeOfXLogShortPHD ;
1353+ XLogBeginRead (xlogreader , thread_arg -> startpoint );
1354+ #endif
1355+
13271356 found = XLogFindNextRecord (xlogreader , thread_arg -> startpoint );
13281357
13291358 /*
@@ -1376,7 +1405,7 @@ XLogThreadWorker(void *arg)
13761405 !SwitchThreadToNextWal (xlogreader , thread_arg ))
13771406 break ;
13781407
1379- record = XLogReadRecord (xlogreader , thread_arg -> startpoint , & errormsg );
1408+ record = WalReadRecord (xlogreader , thread_arg -> startpoint , & errormsg );
13801409
13811410 if (record == NULL )
13821411 {
@@ -1857,3 +1886,28 @@ bool validate_wal_segment(TimeLineID tli, XLogSegNo segno, const char *prefetch_
18571886 return rc ;
18581887}
18591888
1889+ static XLogRecord * WalReadRecord (XLogReaderState * xlogreader , XLogRecPtr startpoint , char * * errormsg )
1890+ {
1891+
1892+ #if PG_VERSION_NUM >= 130000
1893+ return XLogReadRecord (xlogreader , errormsg );
1894+ #else
1895+ return XLogReadRecord (xlogreader , startpoint , errormsg );
1896+ #endif
1897+
1898+ }
1899+
1900+ static XLogReaderState * WalReaderAllocate (uint32 wal_seg_size , XLogReaderData * reader_data )
1901+ {
1902+
1903+ #if PG_VERSION_NUM >= 130000
1904+ return XLogReaderAllocate (wal_seg_size , NULL ,
1905+ XL_ROUTINE (.page_read = & SimpleXLogPageRead ),
1906+ reader_data );
1907+ #elif PG_VERSION_NUM >= 110000
1908+ return XLogReaderAllocate (wal_seg_size , & SimpleXLogPageRead ,
1909+ reader_data );
1910+ #else
1911+ return XLogReaderAllocate (& SimpleXLogPageRead , reader_data );
1912+ #endif
1913+ }
0 commit comments