/Users/deen/code/yugabyte-db/src/postgres/src/include/access/ginxlog.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*-------------------------------------------------------------------------- |
2 | | * ginxlog.h |
3 | | * header file for postgres inverted index xlog implementation. |
4 | | * |
5 | | * Copyright (c) 2006-2018, PostgreSQL Global Development Group |
6 | | * |
7 | | * src/include/access/ginxlog.h |
8 | | *-------------------------------------------------------------------------- |
9 | | */ |
10 | | #ifndef GINXLOG_H |
11 | | #define GINXLOG_H |
12 | | |
13 | | #include "access/ginblock.h" |
14 | | #include "access/itup.h" |
15 | | #include "access/xlogreader.h" |
16 | | #include "lib/stringinfo.h" |
17 | | #include "storage/off.h" |
18 | | |
19 | 0 | #define XLOG_GIN_CREATE_INDEX 0x00 |
20 | | |
21 | 0 | #define XLOG_GIN_CREATE_PTREE 0x10 |
22 | | |
23 | | typedef struct ginxlogCreatePostingTree |
24 | | { |
25 | | uint32 size; |
26 | | /* A compressed posting list follows */ |
27 | | } ginxlogCreatePostingTree; |
28 | | |
29 | | /* |
30 | | * The format of the insertion record varies depending on the page type. |
31 | | * ginxlogInsert is the common part between all variants. |
32 | | * |
33 | | * Backup Blk 0: target page |
34 | | * Backup Blk 1: left child, if this insertion finishes an incomplete split |
35 | | */ |
36 | | |
37 | 0 | #define XLOG_GIN_INSERT 0x20 |
38 | | |
39 | | typedef struct |
40 | | { |
41 | | uint16 flags; /* GIN_INSERT_ISLEAF and/or GIN_INSERT_ISDATA */ |
42 | | |
43 | | /* |
44 | | * FOLLOWS: |
45 | | * |
46 | | * 1. if not leaf page, block numbers of the left and right child pages |
47 | | * whose split this insertion finishes, as BlockIdData[2] (beware of |
48 | | * adding fields in this struct that would make them not 16-bit aligned) |
49 | | * |
50 | | * 2. a ginxlogInsertEntry or ginxlogRecompressDataLeaf struct, depending |
51 | | * on tree type. |
52 | | * |
53 | | * NB: the below structs are only 16-bit aligned when appended to a |
54 | | * ginxlogInsert struct! Beware of adding fields to them that require |
55 | | * stricter alignment. |
56 | | */ |
57 | | } ginxlogInsert; |
58 | | |
59 | | typedef struct |
60 | | { |
61 | | OffsetNumber offset; |
62 | | bool isDelete; |
63 | | IndexTupleData tuple; /* variable length */ |
64 | | } ginxlogInsertEntry; |
65 | | |
66 | | |
67 | | typedef struct |
68 | | { |
69 | | uint16 nactions; |
70 | | |
71 | | /* Variable number of 'actions' follow */ |
72 | | } ginxlogRecompressDataLeaf; |
73 | | |
74 | | /* |
75 | | * Note: this struct is currently not used in code, and only acts as |
76 | | * documentation. The WAL record format is as specified here, but the code |
77 | | * uses straight access through a Pointer and memcpy to read/write these. |
78 | | */ |
79 | | typedef struct |
80 | | { |
81 | | uint8 segno; /* segment this action applies to */ |
82 | | char type; /* action type (see below) */ |
83 | | |
84 | | /* |
85 | | * Action-specific data follows. For INSERT and REPLACE actions that is a |
86 | | * GinPostingList struct. For ADDITEMS, a uint16 for the number of items |
87 | | * added, followed by the items themselves as ItemPointers. DELETE actions |
88 | | * have no further data. |
89 | | */ |
90 | | } ginxlogSegmentAction; |
91 | | |
92 | | /* Action types */ |
93 | 0 | #define GIN_SEGMENT_UNMODIFIED 0 /* no action (not used in WAL records) */ |
94 | 0 | #define GIN_SEGMENT_DELETE 1 /* a whole segment is removed */ |
95 | 0 | #define GIN_SEGMENT_INSERT 2 /* a whole segment is added */ |
96 | 0 | #define GIN_SEGMENT_REPLACE 3 /* a segment is replaced */ |
97 | 0 | #define GIN_SEGMENT_ADDITEMS 4 /* items are added to existing segment */ |
98 | | |
99 | | typedef struct |
100 | | { |
101 | | OffsetNumber offset; |
102 | | PostingItem newitem; |
103 | | } ginxlogInsertDataInternal; |
104 | | |
105 | | /* |
106 | | * Backup Blk 0: new left page (= original page, if not root split) |
107 | | * Backup Blk 1: new right page |
108 | | * Backup Blk 2: original page / new root page, if root split |
109 | | * Backup Blk 3: left child, if this insertion completes an earlier split |
110 | | */ |
111 | 0 | #define XLOG_GIN_SPLIT 0x30 |
112 | | |
113 | | typedef struct ginxlogSplit |
114 | | { |
115 | | RelFileNode node; |
116 | | BlockNumber rrlink; /* right link, or root's blocknumber if root |
117 | | * split */ |
118 | | BlockNumber leftChildBlkno; /* valid on a non-leaf split */ |
119 | | BlockNumber rightChildBlkno; |
120 | | uint16 flags; /* see below */ |
121 | | } ginxlogSplit; |
122 | | |
123 | | /* |
124 | | * Flags used in ginxlogInsert and ginxlogSplit records |
125 | | */ |
126 | 0 | #define GIN_INSERT_ISDATA 0x01 /* for both insert and split records */ |
127 | 0 | #define GIN_INSERT_ISLEAF 0x02 /* ditto */ |
128 | 0 | #define GIN_SPLIT_ROOT 0x04 /* only for split records */ |
129 | | |
130 | | /* |
131 | | * Vacuum simply WAL-logs the whole page, when anything is modified. This |
132 | | * is functionally identical to XLOG_FPI records, but is kept separate for |
133 | | * debugging purposes. (When inspecting the WAL stream, it's easier to see |
134 | | * what's going on when GIN vacuum records are marked as such, not as heap |
135 | | * records.) This is currently only used for entry tree leaf pages. |
136 | | */ |
137 | 0 | #define XLOG_GIN_VACUUM_PAGE 0x40 |
138 | | |
139 | | /* |
140 | | * Vacuuming posting tree leaf page is WAL-logged like recompression caused |
141 | | * by insertion. |
142 | | */ |
143 | 0 | #define XLOG_GIN_VACUUM_DATA_LEAF_PAGE 0x90 |
144 | | |
145 | | typedef struct ginxlogVacuumDataLeafPage |
146 | | { |
147 | | ginxlogRecompressDataLeaf data; |
148 | | } ginxlogVacuumDataLeafPage; |
149 | | |
150 | | /* |
151 | | * Backup Blk 0: deleted page |
152 | | * Backup Blk 1: parent |
153 | | * Backup Blk 2: left sibling |
154 | | */ |
155 | 0 | #define XLOG_GIN_DELETE_PAGE 0x50 |
156 | | |
157 | | typedef struct ginxlogDeletePage |
158 | | { |
159 | | OffsetNumber parentOffset; |
160 | | BlockNumber rightLink; |
161 | | TransactionId deleteXid; /* last Xid which could see this page in scan */ |
162 | | } ginxlogDeletePage; |
163 | | |
164 | 0 | #define XLOG_GIN_UPDATE_META_PAGE 0x60 |
165 | | |
166 | | /* |
167 | | * Backup Blk 0: metapage |
168 | | * Backup Blk 1: tail page |
169 | | */ |
170 | | typedef struct ginxlogUpdateMeta |
171 | | { |
172 | | RelFileNode node; |
173 | | GinMetaPageData metadata; |
174 | | BlockNumber prevTail; |
175 | | BlockNumber newRightlink; |
176 | | int32 ntuples; /* if ntuples > 0 then metadata.tail was |
177 | | * updated with that many tuples; else new sub |
178 | | * list was inserted */ |
179 | | /* array of inserted tuples follows */ |
180 | | } ginxlogUpdateMeta; |
181 | | |
182 | 0 | #define XLOG_GIN_INSERT_LISTPAGE 0x70 |
183 | | |
184 | | typedef struct ginxlogInsertListPage |
185 | | { |
186 | | BlockNumber rightlink; |
187 | | int32 ntuples; |
188 | | /* array of inserted tuples follows */ |
189 | | } ginxlogInsertListPage; |
190 | | |
191 | | /* |
192 | | * Backup Blk 0: metapage |
193 | | * Backup Blk 1 to (ndeleted + 1): deleted pages |
194 | | */ |
195 | | |
196 | 0 | #define XLOG_GIN_DELETE_LISTPAGE 0x80 |
197 | | |
198 | | /* |
199 | | * The WAL record for deleting list pages must contain a block reference to |
200 | | * all the deleted pages, so the number of pages that can be deleted in one |
201 | | * record is limited by XLR_MAX_BLOCK_ID. (block_id 0 is used for the |
202 | | * metapage.) |
203 | | */ |
204 | 0 | #define GIN_NDELETE_AT_ONCE Min(16, XLR_MAX_BLOCK_ID - 1) |
205 | | typedef struct ginxlogDeleteListPages |
206 | | { |
207 | | GinMetaPageData metadata; |
208 | | int32 ndeleted; |
209 | | } ginxlogDeleteListPages; |
210 | | |
211 | | extern void gin_redo(XLogReaderState *record); |
212 | | extern void gin_desc(StringInfo buf, XLogReaderState *record); |
213 | | extern const char *gin_identify(uint8 info); |
214 | | extern void gin_xlog_startup(void); |
215 | | extern void gin_xlog_cleanup(void); |
216 | | extern void gin_mask(char *pagedata, BlockNumber blkno); |
217 | | |
218 | | #endif /* GINXLOG_H */ |