1
/*-------------------------------------------------------------------------
4
* Definitions for the generic XLog reading facility
6
* Portions Copyright (c) 2013, PostgreSQL Global Development Group
9
* src/include/access/xlogreader.h
12
* See the definition of the XLogReaderState struct for instructions on
13
* how to use the XLogReader infrastructure.
15
* The basic idea is to allocate an XLogReaderState via
16
* XLogReaderAllocate(), and call XLogReadRecord() until it returns NULL.
17
*-------------------------------------------------------------------------
22
#include "access/xlog_internal.h"
24
typedef struct XLogReaderState XLogReaderState;
26
/* Function type definition for the read_page callback */
27
typedef int (*XLogPageReadCB) (XLogReaderState *xlogreader,
28
XLogRecPtr targetPagePtr,
30
XLogRecPtr targetRecPtr,
34
struct XLogReaderState
36
/* ----------------------------------------
38
* ----------------------------------------
42
* Data input callback (mandatory).
44
* This callback shall read at least reqLen valid bytes of the xlog page
45
* starting at targetPagePtr, and store them in readBuf. The callback
46
* shall return the number of bytes read (never more than XLOG_BLCKSZ), or
47
* -1 on failure. The callback shall sleep, if necessary, to wait for the
48
* requested bytes to become available. The callback will not be invoked
49
* again for the same page unless more than the returned number of bytes
52
* targetRecPtr is the position of the WAL record we're reading. Usually
53
* it is equal to targetPagePtr + reqLen, but sometimes xlogreader needs
54
* to read and verify the page or segment header, before it reads the
55
* actual WAL record it's interested in. In that case, targetRecPtr can
56
* be used to determine which timeline to read the page from.
58
* The callback shall set *pageTLI to the TLI of the file the page was
59
* read from. It is currently used only for error reporting purposes, to
60
* reconstruct the name of the WAL file where an error occurred.
62
XLogPageReadCB read_page;
65
* System identifier of the xlog files we're about to read. Set to zero
66
* (the default value) if unknown or unimportant.
68
uint64 system_identifier;
71
* Opaque data for callbacks to use. Not used by XLogReader.
76
* Start and end point of last record read. EndRecPtr is also used as the
77
* position to read next, if XLogReadRecord receives an invalid recptr.
79
XLogRecPtr ReadRecPtr; /* start of last record read */
80
XLogRecPtr EndRecPtr; /* end+1 of last record read */
82
/* ----------------------------------------
83
* private/internal state
84
* ----------------------------------------
87
/* Buffer for currently read page (XLOG_BLCKSZ bytes) */
90
/* last read segment, segment offset, read length, TLI */
94
TimeLineID readPageTLI;
96
/* beginning of last page read, and its TLI */
97
XLogRecPtr latestPagePtr;
98
TimeLineID latestPageTLI;
100
/* beginning of the WAL record being read. */
101
XLogRecPtr currRecPtr;
103
/* Buffer for current ReadRecord result (expandable) */
105
uint32 readRecordBufSize;
107
/* Buffer to hold error message */
111
/* Get a new XLogReader */
112
extern XLogReaderState *XLogReaderAllocate(XLogPageReadCB pagereadfunc,
115
/* Free an XLogReader */
116
extern void XLogReaderFree(XLogReaderState *state);
118
/* Read the next XLog record. Returns NULL on end-of-WAL or failure */
119
extern struct XLogRecord *XLogReadRecord(XLogReaderState *state,
120
XLogRecPtr recptr, char **errormsg);
123
extern XLogRecPtr XLogFindNextRecord(XLogReaderState *state, XLogRecPtr RecPtr);
124
#endif /* FRONTEND */
126
#endif /* XLOGREADER_H */