~ubuntu-branches/debian/sid/postgresql-9.3/sid

« back to all changes in this revision

Viewing changes to src/include/access/xlogreader.h

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-05-08 05:39:52 UTC
  • Revision ID: package-import@ubuntu.com-20130508053952-1j7uilp7mjtrvq8q
Tags: upstream-9.3~beta1
ImportĀ upstreamĀ versionĀ 9.3~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * xlogreader.h
 
4
 *              Definitions for the generic XLog reading facility
 
5
 *
 
6
 * Portions Copyright (c) 2013, PostgreSQL Global Development Group
 
7
 *
 
8
 * IDENTIFICATION
 
9
 *              src/include/access/xlogreader.h
 
10
 *
 
11
 * NOTES
 
12
 *              See the definition of the XLogReaderState struct for instructions on
 
13
 *              how to use the XLogReader infrastructure.
 
14
 *
 
15
 *              The basic idea is to allocate an XLogReaderState via
 
16
 *              XLogReaderAllocate(), and call XLogReadRecord() until it returns NULL.
 
17
 *-------------------------------------------------------------------------
 
18
 */
 
19
#ifndef XLOGREADER_H
 
20
#define XLOGREADER_H
 
21
 
 
22
#include "access/xlog_internal.h"
 
23
 
 
24
typedef struct XLogReaderState XLogReaderState;
 
25
 
 
26
/* Function type definition for the read_page callback */
 
27
typedef int (*XLogPageReadCB) (XLogReaderState *xlogreader,
 
28
                                                                                   XLogRecPtr targetPagePtr,
 
29
                                                                                   int reqLen,
 
30
                                                                                   XLogRecPtr targetRecPtr,
 
31
                                                                                   char *readBuf,
 
32
                                                                                   TimeLineID *pageTLI);
 
33
 
 
34
struct XLogReaderState
 
35
{
 
36
        /* ----------------------------------------
 
37
         * Public parameters
 
38
         * ----------------------------------------
 
39
         */
 
40
 
 
41
        /*
 
42
         * Data input callback (mandatory).
 
43
         *
 
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
 
50
         * are needed.
 
51
         *
 
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.
 
57
         *
 
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.
 
61
         */
 
62
        XLogPageReadCB read_page;
 
63
 
 
64
        /*
 
65
         * System identifier of the xlog files we're about to read.  Set to zero
 
66
         * (the default value) if unknown or unimportant.
 
67
         */
 
68
        uint64          system_identifier;
 
69
 
 
70
        /*
 
71
         * Opaque data for callbacks to use.  Not used by XLogReader.
 
72
         */
 
73
        void       *private_data;
 
74
 
 
75
        /*
 
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.
 
78
         */
 
79
        XLogRecPtr      ReadRecPtr;             /* start of last record read */
 
80
        XLogRecPtr      EndRecPtr;              /* end+1 of last record read */
 
81
 
 
82
        /* ----------------------------------------
 
83
         * private/internal state
 
84
         * ----------------------------------------
 
85
         */
 
86
 
 
87
        /* Buffer for currently read page (XLOG_BLCKSZ bytes) */
 
88
        char       *readBuf;
 
89
 
 
90
        /* last read segment, segment offset, read length, TLI */
 
91
        XLogSegNo       readSegNo;
 
92
        uint32          readOff;
 
93
        uint32          readLen;
 
94
        TimeLineID      readPageTLI;
 
95
 
 
96
        /* beginning of last page read, and its TLI  */
 
97
        XLogRecPtr      latestPagePtr;
 
98
        TimeLineID      latestPageTLI;
 
99
 
 
100
        /* beginning of the WAL record being read. */
 
101
        XLogRecPtr      currRecPtr;
 
102
 
 
103
        /* Buffer for current ReadRecord result (expandable) */
 
104
        char       *readRecordBuf;
 
105
        uint32          readRecordBufSize;
 
106
 
 
107
        /* Buffer to hold error message */
 
108
        char       *errormsg_buf;
 
109
};
 
110
 
 
111
/* Get a new XLogReader */
 
112
extern XLogReaderState *XLogReaderAllocate(XLogPageReadCB pagereadfunc,
 
113
                                   void *private_data);
 
114
 
 
115
/* Free an XLogReader */
 
116
extern void XLogReaderFree(XLogReaderState *state);
 
117
 
 
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);
 
121
 
 
122
#ifdef FRONTEND
 
123
extern XLogRecPtr XLogFindNextRecord(XLogReaderState *state, XLogRecPtr RecPtr);
 
124
#endif   /* FRONTEND */
 
125
 
 
126
#endif   /* XLOGREADER_H */