MySQL 9.1.0
Source Code Documentation
fut0lst.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/fut0lst.h
29 File-based list utilities
30
31 Created 11/28/1995 Heikki Tuuri
32 ***********************************************************************/
33
34#ifndef fut0lst_h
35#define fut0lst_h
36
37#include "univ.i"
38
39#include "fil0fil.h"
40#include "mtr0mtr.h"
41
42/* The C 'types' of base node and list node: these should be used to
43write self-documenting code. Of course, the sizeof macro cannot be
44applied to these types! */
45
46typedef byte flst_base_node_t;
47typedef byte flst_node_t;
48
49/* The physical size of a list base node in bytes */
51
52/* The physical size of a list node in bytes */
54
55/** Initializes a list base node.
56@param[in] base Pointer to base node
57@param[in] mtr Mini-transaction handle */
58static inline void flst_init(flst_base_node_t *base, mtr_t *mtr);
59
60/** Adds a node as the last node in a list.
61@param[in] base Pointer to base node of list
62@param[in] node Node to add
63@param[in] mtr Mini-transaction handle */
64void flst_add_last(flst_base_node_t *base, flst_node_t *node, mtr_t *mtr);
65
66/** Adds a node as the first node in a list.
67@param[in] base Pointer to base node of list
68@param[in] node Node to add
69@param[in] mtr Mini-transaction handle */
70void flst_add_first(flst_base_node_t *base, flst_node_t *node, mtr_t *mtr);
71
72/** Removes a node.
73@param[in] base Pointer to base node of list
74@param[in] node2 Node to remove
75@param[in] mtr Mini-transaction handle */
76void flst_remove(flst_base_node_t *base, flst_node_t *node2, mtr_t *mtr);
77
78/** Get the length of a list.
79@param[in] base base node
80@return length */
81static inline ulint flst_get_len(const flst_base_node_t *base);
82
83/** Gets list first node address.
84@param[in] base Pointer to base node
85@param[in] mtr Mini-transaction handle
86@return file address */
87static inline fil_addr_t flst_get_first(const flst_base_node_t *base,
88 mtr_t *mtr);
89
90/** Gets list last node address.
91@param[in] base Pointer to base node
92@param[in] mtr Mini-transaction handle
93@return file address */
94static inline fil_addr_t flst_get_last(const flst_base_node_t *base,
95 mtr_t *mtr);
96
97/** Gets list next node address.
98@param[in] node Pointer to node
99@param[in] mtr Mini-transaction handle
100@return file address */
101static inline fil_addr_t flst_get_next_addr(const flst_node_t *node,
102 mtr_t *mtr);
103
104/** Gets list prev node address.
105@param[in] node Pointer to node
106@param[in] mtr Mini-transaction handle
107@return file address */
108static inline fil_addr_t flst_get_prev_addr(const flst_node_t *node,
109 mtr_t *mtr);
110
111/** Writes a file address.
112@param[in] faddr Pointer to file faddress
113@param[in] addr File address
114@param[in] mtr Mini-transaction handle */
115static inline void flst_write_addr(fil_faddr_t *faddr, fil_addr_t addr,
116 mtr_t *mtr);
117
118/** Reads a file address.
119@param[in] faddr Pointer to file faddress
120@param[in] mtr Mini-transaction handle
121@return file address */
122static inline fil_addr_t flst_read_addr(const fil_faddr_t *faddr, mtr_t *mtr);
123
124/** Validates a file-based list.
125 @param[in] base pointer to base node of list
126 @param[in] mtr1 mtr */
127void flst_validate(const flst_base_node_t *base, mtr_t *mtr1);
128
129/** Inserts a node after another in a list.
130@param[in] base Pointer to base node of list
131@param[in] node1 Node to insert after
132@param[in] node2 Node to add
133@param[in] mtr Mini-transaction handle. */
135 flst_node_t *node2, mtr_t *mtr);
136
137/** Inserts a node before another in a list.
138@param[in] base Pointer to base node of list
139@param[in] node2 Node to insert
140@param[in] node3 Node to insert before
141@param[in] mtr Mini-transaction handle. */
143 flst_node_t *node3, mtr_t *mtr);
144
145#include "fut0lst.ic"
146
147/** In-memory representation of flst_base_node_t */
152
154
156 : len(flst_get_len(base)),
157 first(flst_get_first(base, mtr)),
158 last(flst_get_last(base, mtr)) {}
159
160 void set(const flst_base_node_t *base, mtr_t *mtr) {
161 len = flst_get_len(base);
162 first = flst_get_first(base, mtr);
163 last = flst_get_last(base, mtr);
164 }
165
166 void reset() {
167 len = 0;
170 }
171
172 std::ostream &print(std::ostream &out) const {
173 out << "[flst_base_node_t: len=" << len << ", first=" << first
174 << ", last=" << last << "]";
175 return (out);
176 }
177};
178
179inline std::ostream &operator<<(std::ostream &out, const flst_bnode_t &obj) {
180 return (obj.print(out));
181}
182
183/** @namespace bulk
184
185Used for bulk load of data. To avoid mistakes, an explicit namespace
186is used to encapsulate functions and objects that operate without generating
187redo log records and without using mini transactions. */
188namespace bulk {
189
190/** Initializes a list base node.
191@param[in] base Pointer to base node */
192void flst_init(flst_base_node_t *base);
193
194/** Inserts a node after another in a list. This is the bulk version.
195@param[in] base Pointer to base node of list
196@param[in] node1 Node to insert after
197@param[in] node2 Node to add
198@param[in] blocks vector of blocks containing the file list. */
200 flst_node_t *node2, std::vector<buf_block_t *> &blocks);
201
202/** Writes a file address.
203@param[in] faddr Pointer to file faddress
204@param[in] addr File address */
205void flst_write_addr(fil_faddr_t *faddr, fil_addr_t addr);
206
207/** Adds a node as the last node in a list.
208@param[in] base Pointer to base node of list
209@param[in] node Node to add
210@param[in] blocks vector of blocks containing the file list. */
212 std::vector<buf_block_t *> &blocks);
213
214/** Gets list first node address.
215 @return file address */
217
218/** Gets list prev node address. Bulk version.
219@param[in] node Pointer to node
220@return file address */
222
223/** Gets list next node address.
224@param[in] node Pointer to node
225@return file address */
227
228/** Reads a file address.
229 @return file address */
231
232/** Bulk load version. Remove the node from the given list.
233@param[in] base the base node of the list.
234@param[in] node2 the first node of the list that is to be removed.
235@param[in] blocks all blocks containing the list nodes, necessary to carry
236 out this operation. */
237void flst_remove(flst_base_node_t *base, flst_node_t *node2,
238 std::vector<buf_block_t *> &blocks);
239
240/** Gets a pointer to a file address.
241@param[in] addr File address
242@param[in] blocks vector of blocks containing the file list.
243@return pointer to a location specified by addr. */
244byte *fut_get_ptr(fil_addr_t addr, std::vector<buf_block_t *> &blocks);
245
246/** Gets list last node address.
247@param[in] base Pointer to base node
248@return file address */
250
251inline void flst_init(flst_base_node_t *base) {
252 mach_write_to_4(base + FLST_LEN, 0);
255}
256
257inline void flst_write_addr(fil_faddr_t *faddr, fil_addr_t addr) {
258 ut_ad(faddr != nullptr);
259 ut_ad(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA);
263}
264
266 return flst_read_addr(base + FLST_FIRST);
267}
268
270 ut_ad(faddr != nullptr);
271
272 fil_addr_t addr;
273
276 ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA);
278 return addr;
279}
280
282 return flst_read_addr(node + FLST_PREV);
283}
284
286 return flst_read_addr(node + FLST_NEXT);
287}
288
290 return flst_read_addr(base + FLST_LAST);
291}
292
293} // namespace bulk
294
295#endif /* fut0lst_h */
fil_addr_t fil_addr_null
The null file address.
Definition: fil0fil.cc:326
The low-level file system.
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1156
byte fil_faddr_t
'type' definition in C: an address stored in a file page is a string of bytes
Definition: fil0fil.h:1170
constexpr size_t FIL_ADDR_PAGE
First in address is the page offset.
Definition: fil0types.h:122
constexpr uint32_t FIL_PAGE_DATA
start of the data on the page
Definition: fil0types.h:111
constexpr size_t FIL_ADDR_SIZE
Address size is 6 bytes.
Definition: fil0types.h:128
constexpr size_t FIL_ADDR_BYTE
Then comes 2-byte byte offset within page.
Definition: fil0types.h:125
static fil_addr_t flst_get_next_addr(const flst_node_t *node, mtr_t *mtr)
Gets list next node address.
void flst_add_last(flst_base_node_t *base, flst_node_t *node, mtr_t *mtr)
Adds a node as the last node in a list.
Definition: fut0lst.cc:90
constexpr ulint FLST_BASE_NODE_SIZE
Definition: fut0lst.h:50
void flst_remove(flst_base_node_t *base, flst_node_t *node2, mtr_t *mtr)
Removes a node.
Definition: fut0lst.cc:287
static void flst_write_addr(fil_faddr_t *faddr, fil_addr_t addr, mtr_t *mtr)
Writes a file address.
byte flst_base_node_t
Definition: fut0lst.h:46
static fil_addr_t flst_read_addr(const fil_faddr_t *faddr, mtr_t *mtr)
Reads a file address.
static ulint flst_get_len(const flst_base_node_t *base)
Get the length of a list.
constexpr ulint FLST_NODE_SIZE
Definition: fut0lst.h:53
void flst_add_first(flst_base_node_t *base, flst_node_t *node, mtr_t *mtr)
Adds a node as the first node in a list.
Definition: fut0lst.cc:133
static fil_addr_t flst_get_last(const flst_base_node_t *base, mtr_t *mtr)
Gets list last node address.
static void flst_init(flst_base_node_t *base, mtr_t *mtr)
Initializes a list base node.
static fil_addr_t flst_get_prev_addr(const flst_node_t *node, mtr_t *mtr)
Gets list prev node address.
void flst_insert_after(flst_base_node_t *base, flst_node_t *node1, flst_node_t *node2, mtr_t *mtr)
Inserts a node after another in a list.
Definition: fut0lst.cc:172
std::ostream & operator<<(std::ostream &out, const flst_bnode_t &obj)
Definition: fut0lst.h:179
void flst_validate(const flst_base_node_t *base, mtr_t *mtr1)
Validates a file-based list.
Definition: fut0lst.cc:353
static fil_addr_t flst_get_first(const flst_base_node_t *base, mtr_t *mtr)
Gets list first node address.
void flst_insert_before(flst_base_node_t *base, flst_node_t *node2, flst_node_t *node3, mtr_t *mtr)
Inserts a node before another in a list.
Definition: fut0lst.cc:228
byte flst_node_t
Definition: fut0lst.h:47
File-based list utilities.
constexpr uint32_t FLST_PREV
6-byte address of the previous list element; the page part of address is FIL_NULL,...
Definition: fut0lst.ic:41
constexpr uint32_t FLST_LAST
6-byte address of the last element of the list; undefined if empty list
Definition: fut0lst.ic:52
constexpr uint32_t FLST_LEN
32-bit list length field
Definition: fut0lst.ic:48
constexpr uint32_t FLST_FIRST
6-byte address of the first element of the list; undefined if empty list
Definition: fut0lst.ic:50
constexpr uint32_t FLST_NEXT
Definition: fut0lst.ic:44
static uint32_t mach_read_ulint(const byte *ptr, mlog_id_t type)
Read 1 to 4 bytes from a file page buffered in the buffer pool.
static void mach_write_to_4(byte *b, ulint n)
The following function is used to store data in 4 consecutive bytes.
static void mach_write_ulint(byte *ptr, ulint val, mlog_id_t type)
Writes 1, 2 or 4 bytes to a file page.
Definition: mach0data.h:292
Mini-transaction buffer.
@ MLOG_4BYTES
4 bytes ...
Definition: mtr0types.h:76
@ MLOG_2BYTES
2 bytes ...
Definition: mtr0types.h:73
Used for bulk load of data.
Definition: fut0lst.cc:411
fil_addr_t flst_get_prev_addr(const flst_node_t *node)
Gets list prev node address.
Definition: fut0lst.h:281
byte * fut_get_ptr(fil_addr_t addr, std::vector< buf_block_t * > &blocks)
Gets a pointer to a file address.
Definition: fut0lst.cc:499
fil_addr_t flst_read_addr(const fil_faddr_t *faddr)
Reads a file address.
Definition: fut0lst.h:269
void flst_remove(flst_base_node_t *base, flst_node_t *node2, std::vector< buf_block_t * > &blocks)
Bulk load version.
Definition: fut0lst.cc:441
void flst_write_addr(fil_faddr_t *faddr, fil_addr_t addr)
Writes a file address.
Definition: fut0lst.h:257
fil_addr_t flst_get_last(const flst_base_node_t *base)
Gets list last node address.
Definition: fut0lst.h:289
void flst_init(flst_base_node_t *base)
Initializes a list base node.
Definition: fut0lst.h:251
void flst_add_last(flst_base_node_t *base, flst_node_t *node, std::vector< buf_block_t * > &blocks)
Adds a node as the last node in a list.
Definition: fut0lst.cc:511
fil_addr_t flst_get_next_addr(const flst_node_t *node)
Gets list next node address.
Definition: fut0lst.h:285
fil_addr_t flst_get_first(const flst_base_node_t *base)
Gets list first node address.
Definition: fut0lst.h:265
void flst_insert_after(flst_base_node_t *base, flst_node_t *node1, flst_node_t *node2, std::vector< buf_block_t * > &blocks)
Inserts a node after another in a list.
Definition: fut0lst.cc:543
File space address.
Definition: fil0fil.h:1173
uint32_t boffset
Byte offset within the page.
Definition: fil0fil.h:1205
page_no_t page
Page number within a space.
Definition: fil0fil.h:1202
In-memory representation of flst_base_node_t.
Definition: fut0lst.h:148
ulint len
Definition: fut0lst.h:149
std::ostream & print(std::ostream &out) const
Definition: fut0lst.h:172
flst_bnode_t()
Definition: fut0lst.h:153
fil_addr_t last
Definition: fut0lst.h:151
flst_bnode_t(const flst_base_node_t *base, mtr_t *mtr)
Definition: fut0lst.h:155
void set(const flst_base_node_t *base, mtr_t *mtr)
Definition: fut0lst.h:160
fil_addr_t first
Definition: fut0lst.h:150
void reset()
Definition: fut0lst.h:166
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:177
Version control for database, common definitions, and include files.
#define UNIV_PAGE_SIZE
The universal page size of the database.
Definition: univ.i:294
unsigned long int ulint
Definition: univ.i:406
static ulint ut_align_offset(const void *ptr, ulint align_no)
The following function computes the offset of a pointer from the nearest aligned address.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93