8000 Move callback-call from ReadPageInternal to XLogReadRecord. · Giperboloid/postgres@17647cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 17647cf

Browse files
Kyotaro Horiguchimacdice
Kyotaro Horiguchi
authored andcommitted
Move callback-call from ReadPageInternal to XLogReadRecord.
The current WAL record reader reads page data using a call back function. Although it is not so problematic alone, it would be a problem if we are going to do add tasks like encryption which is performed on page data before WAL reader reads them. To avoid that the record reader facility has to have a new code path corresponds to every new callback, this patch separates page reader from WAL record reading facility by modifying the current WAL record reader to a state machine. As the first step of that change, this patch moves the page reader function out of ReadPageInternal, then the remaining tasks of the function are taken over by the new function XLogNeedData. As the result XLogPageRead directly calls the page reader callback function according to the feedback from XLogNeedData.
1 parent 33e52ad commit 17647cf

File tree

8 files changed

+219
-150
lines changed

8 files changed

+219
-150
lines changed

src/backend/access/transam/xlog.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ static bool InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
920920
static int XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
921921
XLogSource source, bool notfoundOk);
922922
static int XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source);
923-
static int XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
923+
static bool XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
924924
int reqLen, XLogRecPtr targetRecPtr, char *readBuf);
925925
static bool WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
926926
bool fetching_ckpt, XLogRecPtr tliRecPtr);
@@ -4375,7 +4375,6 @@ ReadRecord(XLogReaderState *xlogreader, int emode,
43754375
XLogRecord *record;
43764376
XLogPageReadPrivate *private = (XLogPageReadPrivate *) xlogreader->private_data;
43774377

4378-
/* Pass through parameters to XLogPageRead */
43794378
private->fetching_ckpt = fetching_ckpt;
43804379
private->emode = emode;
43814380
private->randAccess = (xlogreader->ReadRecPtr == InvalidXLogRecPtr);
@@ -12111,7 +12110,7 @@ CancelBackup(void)
1211112110
* XLogPageRead() to try fetching the record from another source, or to
1211212111
* sleep and retry.
1211312112
*/
12114-
static int
12113+
static bool
1211512114
XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
1211612115
XLogRecPtr targetRecPtr, char *readBuf)
1211712116
{
@@ -12170,7 +12169,8 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
1217012169
readLen = 0;
1217112170
readSource = XLOG_FROM_ANY;
1217212171

12173-
return -1;
12172+
xlogreader->readLen = -1;
12173+
return false;
1217412174
}
1217512175
}
1217612176

@@ -12265,7 +12265,8 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
1226512265
goto next_record_is_invalid;
1226612266
}
1226712267

12268-
return readLen;
12268+
xlogreader->readLen = readLen;
12269+
return true;
1226912270

1227012271
next_record_is_invalid:
1227112272
lastSourceFailed = true;
@@ -12279,8 +12280,9 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
1227912280
/* In standby-mode, keep trying */
1228012281
if (StandbyMode)
1228112282
goto retry;
12282-
else
12283-
return -1;
12283+
12284+
xlogreader->readLen = -1;
12285+
return false;
1228412286
}
1228512287

1228612288
/*

0 commit comments

Comments
 (0)
0