mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
XLogReader general code cleanup
Some minor tweaks and comment additions, for cleanliness sake and to avoid having the upcoming timeline-following patch be polluted with unrelated cleanup. Extracted from a larger patch by Craig Ringer, reviewed by Andres Freund, with some additions by myself.
This commit is contained in:
@ -19,12 +19,11 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "miscadmin.h"
|
||||
|
||||
#include "access/xlog.h"
|
||||
#include "access/xlog_internal.h"
|
||||
#include "access/xlogutils.h"
|
||||
#include "catalog/catalog.h"
|
||||
#include "miscadmin.h"
|
||||
#include "storage/smgr.h"
|
||||
#include "utils/guc.h"
|
||||
#include "utils/hsearch.h"
|
||||
@ -638,8 +637,17 @@ XLogTruncateRelation(RelFileNode rnode, ForkNumber forkNum,
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: This is duplicate code with pg_xlogdump, similar to walsender.c, but
|
||||
* we currently don't have the infrastructure (elog!) to share it.
|
||||
* Read 'count' bytes from WAL into 'buf', starting at location 'startptr'
|
||||
* in timeline 'tli'.
|
||||
*
|
||||
* Will open, and keep open, one WAL segment stored in the static file
|
||||
* descriptor 'sendFile'. This means if XLogRead is used once, there will
|
||||
* always be one descriptor left open until the process ends, but never
|
||||
* more than one.
|
||||
*
|
||||
* XXX This is very similar to pg_xlogdump's XLogDumpXLogRead and to XLogRead
|
||||
* in walsender.c but for small differences (such as lack of elog() in
|
||||
* frontend). Probably these should be merged at some point.
|
||||
*/
|
||||
static void
|
||||
XLogRead(char *buf, TimeLineID tli, XLogRecPtr startptr, Size count)
|
||||
@ -648,6 +656,7 @@ XLogRead(char *buf, TimeLineID tli, XLogRecPtr startptr, Size count)
|
||||
XLogRecPtr recptr;
|
||||
Size nbytes;
|
||||
|
||||
/* state maintained across calls */
|
||||
static int sendFile = -1;
|
||||
static XLogSegNo sendSegNo = 0;
|
||||
static uint32 sendOff = 0;
|
||||
@ -664,11 +673,11 @@ XLogRead(char *buf, TimeLineID tli, XLogRecPtr startptr, Size count)
|
||||
|
||||
startoff = recptr % XLogSegSize;
|
||||
|
||||
/* Do we need to switch to a different xlog segment? */
|
||||
if (sendFile < 0 || !XLByteInSeg(recptr, sendSegNo))
|
||||
{
|
||||
char path[MAXPGPATH];
|
||||
|
||||
/* Switch to another logfile segment */
|
||||
if (sendFile >= 0)
|
||||
close(sendFile);
|
||||
|
||||
@ -745,7 +754,7 @@ XLogRead(char *buf, TimeLineID tli, XLogRecPtr startptr, Size count)
|
||||
* Public because it would likely be very helpful for someone writing another
|
||||
* output method outside walsender, e.g. in a bgworker.
|
||||
*
|
||||
* TODO: The walsender has it's own version of this, but it relies on the
|
||||
* TODO: The walsender has its own version of this, but it relies on the
|
||||
* walsender's latch being set whenever WAL is flushed. No such infrastructure
|
||||
* exists for normal backends, so we have to do a check/sleep/repeat style of
|
||||
* loop for now.
|
||||
|
Reference in New Issue
Block a user