@@ -148,10 +148,12 @@ typedef struct
148
148
int ret ;
149
149
} xlog_thread_arg ;
150
150
151
+ static XLogRecord * WalReadRecord (XLogReaderState * xlogreader , XLogRecPtr startpoint , char * * errormsg );
152
+ static XLogReaderState * WalReaderAllocate (uint32 wal_seg_size , XLogReaderData * reader_data );
153
+
151
154
static int SimpleXLogPageRead (XLogReaderState * xlogreader ,
152
155
XLogRecPtr targetPagePtr ,
153
- int reqLen , XLogRecPtr targetRecPtr , char * readBuf ,
154
- TimeLineID * pageTLI );
156
+ int reqLen , XLogRecPtr targetRecPtr , char * readBuf );
155
157
static XLogReaderState * InitXLogPageRead (XLogReaderData * reader_data ,
156
158
const char * archivedir ,
157
159
TimeLineID tli , uint32 segment_size ,
@@ -551,7 +553,13 @@ read_recovery_info(const char *archivedir, TimeLineID tli, uint32 wal_seg_size,
551
553
TimestampTz last_time = 0 ;
552
554
char * errormsg ;
553
555
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 );
555
563
if (record == NULL )
556
564
{
557
565
XLogRecPtr errptr ;
@@ -615,7 +623,13 @@ wal_contains_lsn(const char *archivedir, XLogRecPtr target_lsn,
615
623
616
624
xlogreader -> system_identifier = instance_config .system_identifier ;
617
625
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 ;
619
633
/* Didn't find 'target_lsn' and there is no error, return false */
620
634
621
635
if (errormsg )
@@ -656,6 +670,12 @@ get_first_record_lsn(const char *archivedir, XLogSegNo segno,
656
670
/* Set startpoint to 0 in segno */
657
671
GetXLogRecPtr (segno , 0 , wal_seg_size , startpoint );
658
672
673
+ #if PG_VERSION_NUM >= 130000
674
+ if (XLogRecPtrIsInvalid (startpoint ))
675
+ startpoint = SizeOfXLogShortPHD ;
676
+ XLogBeginRead (xlogreader , startpoint );
677
+ #endif
678
+
659
679
while (attempts <= timeout )
660
680
{
661
681
record = XLogFindNextRecord (xlogreader , startpoint );
@@ -710,6 +730,12 @@ get_next_record_lsn(const char *archivedir, XLogSegNo segno,
710
730
/* Set startpoint to 0 in segno */
711
731
GetXLogRecPtr (segno , 0 , wal_seg_size , startpoint );
712
732
733
+ #if PG_VERSION_NUM >= 130000
734
+ if (XLogRecPtrIsInvalid (startpoint ))
735
+ startpoint = SizeOfXLogShortPHD ;
736
+ XLogBeginRead (xlogreader , startpoint );
737
+ #endif
738
+
713
739
found = XLogFindNextRecord (xlogreader , startpoint );
714
740
715
741
if (XLogRecPtrIsInvalid (found ))
@@ -733,7 +759,7 @@ get_next_record_lsn(const char *archivedir, XLogSegNo segno,
733
759
if (interrupted )
734
760
elog (ERROR , "Interrupted during WAL reading" );
735
761
736
- record = XLogReadRecord (xlogreader , startpoint , & errormsg );
762
+ record = WalReadRecord (xlogreader , startpoint , & errormsg );
737
763
738
764
if (record == NULL )
739
765
{
@@ -822,6 +848,13 @@ get_prior_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
822
848
XLogRecPtr found ;
823
849
824
850
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
+
825
858
found = XLogFindNextRecord (xlogreader , startpoint );
826
859
827
860
if (XLogRecPtrIsInvalid (found ))
@@ -846,7 +879,7 @@ get_prior_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
846
879
if (interrupted )
847
880
elog (ERROR , "Interrupted during WAL reading" );
848
881
849
- record = XLogReadRecord (xlogreader , startpoint , & errormsg );
882
+ record = WalReadRecord (xlogreader , startpoint , & errormsg );
850
883
if (record == NULL )
851
884
{
852
885
XLogRecPtr errptr ;
@@ -905,8 +938,7 @@ get_gz_error(gzFile gzf)
905
938
/* XLogreader callback function, to read a WAL page */
906
939
static int
907
940
SimpleXLogPageRead (XLogReaderState * xlogreader , XLogRecPtr targetPagePtr ,
908
- int reqLen , XLogRecPtr targetRecPtr , char * readBuf ,
909
- TimeLineID * pageTLI )
941
+ int reqLen , XLogRecPtr targetRecPtr , char * readBuf )
910
942
{
911
943
XLogReaderData * reader_data ;
912
944
uint32 targetPageOff ;
@@ -1040,7 +1072,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
1040
1072
reader_data -> prev_page_off == targetPageOff )
1041
1073
{
1042
1074
memcpy (readBuf , reader_data -> page_buf , XLOG_BLCKSZ );
1043
- * pageTLI = reader_data -> tli ;
1075
+ // *pageTLI = reader_data->tli;
1044
1076
return XLOG_BLCKSZ ;
1045
1077
}
1046
1078
@@ -1084,7 +1116,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
1084
1116
1085
1117
memcpy (reader_data -> page_buf , readBuf , XLOG_BLCKSZ );
1086
1118
reader_data -> prev_page_off = targetPageOff ;
1087
- * pageTLI = reader_data -> tli ;
1119
+ // *pageTLI = reader_data->tli;
1088
1120
return XLOG_BLCKSZ ;
1089
1121
}
1090
1122
@@ -1109,12 +1141,7 @@ InitXLogPageRead(XLogReaderData *reader_data, const char *archivedir,
1109
1141
1110
1142
if (allocate_reader )
1111
1143
{
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 );
1118
1145
if (xlogreader == NULL )
1119
1146
elog (ERROR , "Out of memory" );
1120
1147
xlogreader -> system_identifier = instance_config .system_identifier ;
@@ -1314,16 +1341,18 @@ XLogThreadWorker(void *arg)
1314
1341
uint32 prev_page_off = 0 ;
1315
1342
bool need_read = true;
1316
1343
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
+
1323
1346
if (xlogreader == NULL )
1324
1347
elog (ERROR , "Thread [%d]: out of memory" , reader_data -> thread_num );
1325
1348
xlogreader -> system_identifier = instance_config .system_identifier ;
1326
1349
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
+
1327
1356
found = XLogFindNextRecord (xlogreader , thread_arg -> startpoint );
1328
1357
1329
1358
/*
@@ -1376,7 +1405,7 @@ XLogThreadWorker(void *arg)
1376
1405
!SwitchThreadToNextWal (xlogreader , thread_arg ))
1377
1406
break ;
1378
1407
1379
- record = XLogReadRecord (xlogreader , thread_arg -> startpoint , & errormsg );
1408
+ record = WalReadRecord (xlogreader , thread_arg -> startpoint , & errormsg );
1380
1409
1381
1410
if (record == NULL )
1382
1411
{
@@ -1857,3 +1886,28 @@ bool validate_wal_segment(TimeLineID tli, XLogSegNo segno, const char *prefetch_
1857
1886
return rc ;
1858
1887
}
1859
1888
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