@@ -164,7 +164,7 @@ allocate_recordbuf(XLogReaderState *state, uint32 reclength)
164
164
* If RecPtr is not NULL, try to read a record at that position. Otherwise
165
165
* try to read a record just after the last one previously read.
166
166
*
167
- * If the page_read callback fails to read the requested data, NULL is
167
+ * If the read_page callback fails to read the requested data, NULL is
168
168
* returned. The callback is expected to have reported the error; errormsg
169
169
* is set to NULL.
170
170
*
@@ -217,10 +217,16 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg)
217
217
}
218
218
219
219
targetPagePtr = RecPtr - (RecPtr % XLOG_BLCKSZ );
220
+ targetRecOff = RecPtr % XLOG_BLCKSZ ;
220
221
221
- /* Read the page containing the record into state->readBuf */
222
- readOff = ReadPageInternal (state , targetPagePtr , SizeOfXLogRecord );
223
-
222
+ /*
223
+ * Read the page containing the record into state->readBuf. Request
224
+ * enough byte to cover the whole record header, or at least the part of
225
+ * it that fits on the same page.
226
+ */
227
+ readOff = ReadPageInternal (state ,
228
+ targetPagePtr ,
229
+ Min (targetRecOff + SizeOfXLogRecord , XLOG_BLCKSZ ));
224
230
if (readOff < 0 )
225
231
goto err ;
226
232
@@ -229,7 +235,6 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg)
229
235
* examine it now.
230
236
*/
231
237
pageHeaderSize = XLogPageHeaderSize ((XLogPageHeader ) state -> readBuf );
232
- targetRecOff = RecPtr % XLOG_BLCKSZ ;
233
238
if (targetRecOff == 0 )
234
239
{
235
240
/*
@@ -256,16 +261,6 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg)
256
261
/* ReadPageInternal has verified the page header */
257
262
Assert (pageHeaderSize <= readOff );
258
263
259
- /*
260
- * Ensure the whole record header or at least the part on this page is
261
- * read.
262
- */
263
- readOff = ReadPageInternal (state ,
264
- targetPagePtr ,
265
- Min (targetRecOff + SizeOfXLogRecord , XLOG_BLCKSZ ));
266
- if (readOff < 0 )
267
- goto err ;
268
-
269
264
/*
270
265
* Read the record length.
271
266
*
@@ -463,7 +458,7 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg)
463
458
}
464
459
465
460
/*
466
- * Read a single xlog page including at least [pagestart, RecPtr ] of valid data
461
+ * Read a single xlog page including at least [pageptr, reqLen ] of valid data
467
462
* via the read_page() callback.
468
463
*
469
464
* Returns -1 if the required page cannot be read for some reason; errormsg_buf
@@ -502,8 +497,7 @@ ReadPageInternal(XLogReaderState *state, XLogRecPtr pageptr, int reqLen)
502
497
* record is. This is so that we can check the additional identification
503
498
* info that is present in the first page's "long" header.
504
499
*/
505
- if (targetSegNo != state -> readSegNo &&
506
- targetPageOff != 0 )
500
+ if (targetSegNo != state -> readSegNo && targetPageOff != 0 )
507
501
{
508
502
XLogPageHeader hdr ;
509
503
XLogRecPtr targetSegmentPtr = pageptr - targetPageOff ;
0 commit comments