From: Kyotaro Horiguchi Date: Thu, 18 Apr 2019 16:00:57 +0900 Subject: [PATCH 09/10] Make pg_rewind not use callback but call the function directly This patch replaces the call to the callback in pg_rewind with direct call to the original function. Then invalidate the parameters callback and private for XLogReaderAllocate. --- src/bin/pg_rewind/parsexlog.c | 78 ++++++++++++------------------------------- 1 file changed, 22 insertions(+), 56 deletions(-) diff --git a/src/bin/pg_rewind/parsexlog.c b/src/bin/pg_rewind/parsexlog.c index e26127206c..26446027ab 100644 --- a/src/bin/pg_rewind/parsexlog.c +++ b/src/bin/pg_rewind/parsexlog.c @@ -41,16 +41,8 @@ static int xlogreadfd = -1; static XLogSegNo xlogreadsegno = -1; static char xlogfpath[MAXPGPATH]; -typedef struct XLogPageReadPrivate -{ - const char *datadir; - int tliIndex; -} XLogPageReadPrivate; - -static void SimpleXLogPageRead(XLogReaderState *xlogreader, - XLogRecPtr targetPagePtr, - int reqLen, XLogRecPtr targetRecPtr, char *readBuf, - TimeLineID *pageTLI); +static void SimpleXLogPageRead(XLogReaderState *xlogreader, + const char *datadir, int *tliIndex); /* * Read WAL from the datadir/pg_wal, starting from 'startpoint' on timeline @@ -64,12 +56,8 @@ extractPageMap(const char *datadir, XLogRecPtr startpoint, int tliIndex, XLogRecord *record; XLogReaderState *xlogreader; char *errormsg; - XLogPageReadPrivate private; - private.datadir = datadir; - private.tliIndex = tliIndex; - xlogreader = XLogReaderAllocate(WalSegSz, &SimpleXLogPageRead, - &private); + xlogreader = XLogReaderAllocate(WalSegSz, NULL, NULL); if (xlogreader == NULL) pg_fatal("out of memory"); @@ -77,12 +65,7 @@ extractPageMap(const char *datadir, XLogRecPtr startpoint, int tliIndex, { while (XLogReadRecord(xlogreader, startpoint, &record, &errormsg) == XLREAD_NEED_DATA) - xlogreader->read_page(xlogreader, - xlogreader->loadPagePtr, - xlogreader->loadLen, - xlogreader->currRecPtr, - xlogreader->readBuf, - &xlogreader->readPageTLI); + SimpleXLogPageRead(xlogreader, datadir, &tliIndex); if (record == NULL) { @@ -124,24 +107,15 @@ readOneRecord(const char *datadir, XLogRecPtr ptr, int tliIndex) XLogRecord *record; XLogReaderState *xlogreader; char *errormsg; - XLogPageReadPrivate private; XLogRecPtr endptr; - private.datadir = datadir; - private.tliIndex = tliIndex; - xlogreader = XLogReaderAllocate(WalSegSz, &SimpleXLogPageRead, - &private); + xlogreader = XLogReaderAllocate(WalSegSz, NULL, NULL); if (xlogreader == NULL) pg_fatal("out of memory"); while (XLogReadRecord(xlogreader, ptr, &record, &errormsg) == XLREAD_NEED_DATA) - xlogreader->read_page(xlogreader, - xlogreader->loadPagePtr, - xlogreader->loadLen, - xlogreader->currRecPtr, - xlogreader->readBuf, - &xlogreader->readPageTLI); + SimpleXLogPageRead(xlogreader, datadir, &tliIndex); if (record == NULL) { @@ -177,7 +151,6 @@ findLastCheckpoint(const char *datadir, XLogRecPtr forkptr, int tliIndex, XLogRecPtr searchptr; XLogReaderState *xlogreader; char *errormsg; - XLogPageReadPrivate private; /* * The given fork pointer points to the end of the last common record, @@ -193,10 +166,7 @@ findLastCheckpoint(const char *datadir, XLogRecPtr forkptr, int tliIndex, forkptr += SizeOfXLogShortPHD; } - private.datadir = datadir; - private.tliIndex = tliIndex; - xlogreader = XLogReaderAllocate(WalSegSz, &SimpleXLogPageRead, - &private); + xlogreader = XLogReaderAllocate(WalSegSz, NULL, NULL); if (xlogreader == NULL) pg_fatal("out of memory"); @@ -207,12 +177,7 @@ findLastCheckpoint(const char *datadir, XLogRecPtr forkptr, int tliIndex, while (XLogReadRecord(xlogreader, searchptr, &record, &errormsg) == XLREAD_NEED_DATA) - xlogreader->read_page(xlogreader, - xlogreader->loadPagePtr, - xlogreader->loadLen, - xlogreader->currRecPtr, - xlogreader->readBuf, - &xlogreader->readPageTLI); + SimpleXLogPageRead(xlogreader, datadir, &tliIndex); if (record == NULL) { @@ -259,11 +224,12 @@ findLastCheckpoint(const char *datadir, XLogRecPtr forkptr, int tliIndex, /* XLogreader callback function, to read a WAL page */ static void -SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, - int reqLen, XLogRecPtr targetRecPtr, char *readBuf, - TimeLineID *pageTLI) +SimpleXLogPageRead(XLogReaderState *xlogreader, + const char*datadir, int *tliIndex) { - XLogPageReadPrivate *private = (XLogPageReadPrivate *) xlogreader->private_data; + XLogRecPtr targetPagePtr = xlogreader->loadPagePtr; + char *readBuf = xlogreader->readBuf; + TimeLineID *pageTLI = &xlogreader->readPageTLI; uint32 targetPageOff; XLogRecPtr targetSegEnd; XLogSegNo targetSegNo; @@ -296,17 +262,17 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, * be done both forward and backward, consider also switching timeline * accordingly. */ - while (private->tliIndex < targetNentries - 1 && - targetHistory[private->tliIndex].end < targetSegEnd) - private->tliIndex++; - while (private->tliIndex > 0 && - targetHistory[private->tliIndex].begin >= targetSegEnd) - private->tliIndex--; + while (*tliIndex < targetNentries - 1 && + targetHistory[*tliIndex].end < targetSegEnd) + (*tliIndex)++; + while (*tliIndex > 0 && + targetHistory[*tliIndex].begin >= targetSegEnd) + (*tliIndex)--; - XLogFileName(xlogfname, targetHistory[private->tliIndex].tli, + XLogFileName(xlogfname, targetHistory[*tliIndex].tli, xlogreadsegno, WalSegSz); - snprintf(xlogfpath, MAXPGPATH, "%s/" XLOGDIR "/%s", private->datadir, xlogfname); + snprintf(xlogfpath, MAXPGPATH, "%s/" XLOGDIR "/%s", datadir, xlogfname); xlogreadfd = open(xlogfpath, O_RDONLY | PG_BINARY, 0); @@ -347,7 +313,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, Assert(targetSegNo == xlogreadsegno); - *pageTLI = targetHistory[private->tliIndex].tli; + *pageTLI = targetHistory[*tliIndex].tli; xlogreader->readLen = XLOG_BLCKSZ; return; -- 2.16.3 ----Next_Part(Fri_May_24_11_56_24_2019_374)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="v3-0010-Remove-callback-entry-from-XLogReaderState.patch"