MySQL 8.0.31
Source Code Documentation
mtr0log.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2022, 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 also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/mtr0log.h
28 Mini-transaction logging routines
29
30 Created 12/7/1995 Heikki Tuuri
31 *******************************************************/
32
33#ifndef mtr0log_h
34#define mtr0log_h
35
36#include "dyn0buf.h"
37#include "mtr0mtr.h"
38#include "univ.i"
39
40// Forward declaration
41struct dict_index_t;
42
43#define INDEX_LOG_VERSION 0x01
44
45#define COMPACT_FLAG 0x01
46#define VERSION_FLAG 0x02
47#define INSTANT_FLAG 0x04
48
49#define IS_INSTANT(flags) (flags & INSTANT_FLAG)
50#define IS_VERSIONED(flags) (flags & VERSION_FLAG)
51#define IS_COMPACT(flags) (flags & COMPACT_FLAG)
52
53#define SET_INSTANT(flags) (flag |= INSTANT_FLAG)
54#define SET_VERSIONED(flags) (flag |= VERSION_FLAG)
55#define SET_COMPACT(flags) (flag |= COMPACT_FLAG)
56
57/* Size of initial info on REDO log
58 1 byte for LOG TYPE
59 3-5 bytes for SPACE ID
60 3-5 bytes for PAGE OFFSET */
61constexpr size_t REDO_LOG_INITIAL_INFO_SIZE = 11;
62
63/** Writes 1, 2 or 4 bytes to a file page. Writes the corresponding log
64 record to the mini-transaction log if mtr is not NULL. */
66 byte *ptr, /*!< in: pointer where to write */
67 ulint val, /*!< in: value to write */
68 mlog_id_t type, /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
69 mtr_t *mtr); /*!< in: mini-transaction handle */
70
71/** Writes 8 bytes to a file page. Writes the corresponding log
72 record to the mini-transaction log, only if mtr is not NULL */
73void mlog_write_ull(byte *ptr, /*!< in: pointer where to write */
74 uint64_t val, /*!< in: value to write */
75 mtr_t *mtr); /*!< in: mini-transaction handle */
76/** Writes a string to a file page buffered in the buffer pool. Writes the
77 corresponding log record to the mini-transaction log. */
78void mlog_write_string(byte *ptr, /*!< in: pointer where to write */
79 const byte *str, /*!< in: string to write */
80 ulint len, /*!< in: string length */
81 mtr_t *mtr); /*!< in: mini-transaction handle */
82/** Logs a write of a string to a file page buffered in the buffer pool.
83 Writes the corresponding log record to the mini-transaction log. */
84void mlog_log_string(byte *ptr, /*!< in: pointer written to */
85 ulint len, /*!< in: string length */
86 mtr_t *mtr); /*!< in: mini-transaction handle */
87/** Writes initial part of a log record consisting of one-byte item
88 type and four-byte space and page numbers. */
90 const byte *ptr, /*!< in: pointer to (inside) a buffer
91 frame holding the file page where
92 modification is made */
93 mlog_id_t type, /*!< in: log item type: MLOG_1BYTE, ... */
94 mtr_t *mtr); /*!< in: mini-transaction handle */
95
96/** Catenates 1 - 4 bytes to the mtr log. The value is not compressed.
97@param[in,out] dyn_buf buffer to write
98@param[in] val value to write
99@param[in] type type of value to write */
100static inline void mlog_catenate_ulint(mtr_buf_t *dyn_buf, ulint val,
102
103/** Catenates 1 - 4 bytes to the mtr log.
104@param[in] mtr mtr
105@param[in] val value to write
106@param[in] type MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
107static inline void mlog_catenate_ulint(mtr_t *mtr, ulint val, mlog_id_t type);
108
109/** Catenates n bytes to the mtr log.
110@param[in] mtr Mini-transaction
111@param[in] str String to write
112@param[in] len String length */
113void mlog_catenate_string(mtr_t *mtr, const byte *str, ulint len);
114
115/** Catenates a compressed ulint to mlog.
116@param[in] mtr mtr
117@param[in] val value to write */
118static inline void mlog_catenate_ulint_compressed(mtr_t *mtr, ulint val);
119
120/** Catenates a compressed 64-bit integer to mlog.
121@param[in] mtr mtr
122@param[in] val value to write */
123static inline void mlog_catenate_ull_compressed(mtr_t *mtr, uint64_t val);
124
125/** Opens a buffer to mlog. It must be closed with mlog_close.
126@param[in,out] mtr mtr
127@param[in] size buffer size in bytes; MUST be smaller than
128 DYN_ARRAY_DATA_SIZE!
129@param[out] buffer mlog buffer pointer if opened successfully
130@retval true if opened successfully.
131@retval false if not opened. One case is when redo is disabled for mtr. */
132[[nodiscard]] static inline bool mlog_open(mtr_t *mtr, ulint size,
133 byte *&buffer);
134
135/** Opens a buffer to mlog. It must be closed with mlog_close.
136This is used for writing log for metadata changes
137@param[in,out] mtr mtr
138@param[in] size buffer size in bytes; MUST be smaller than
139 DYN_ARRAY_DATA_SIZE!
140@param[out] buffer mlog buffer pointer if opened successfully
141@retval true if opened successfully.
142@retval false if not opened. One case is when redo is disabled for mtr. */
143[[nodiscard]] static inline bool mlog_open_metadata(mtr_t *mtr, ulint size,
144 byte *&buffer);
145
146/** Closes a buffer opened to mlog.
147@param[in] mtr mtr
148@param[in] ptr buffer space from ptr up was not used */
149static inline void mlog_close(mtr_t *mtr, byte *ptr);
150
151/** Writes a log record about a dictionary operation, which would cost
152at most 23 bytes.
153@param[in] type Redo log record type
154@param[in] id Table id
155@param[in] version Table dynamic metadata version
156@param[in,out] log_ptr Current end of mini-transaction log
157@param[in,out] mtr Mini-transaction
158@return end of mini-transaction log */
160 mlog_id_t type, table_id_t id, uint64_t version, byte *log_ptr, mtr_t *mtr);
161
162/** Writes a log record about an operation.
163@param[in] type Redo log record type
164@param[in] space_id Tablespace identifier
165@param[in] page_no Page number
166@param[in,out] log_ptr Current end of mini-transaction log
167@param[in,out] mtr Mini-transaction
168@return end of mini-transaction log */
171 page_no_t page_no,
172 byte *log_ptr,
173 mtr_t *mtr);
174
175#ifndef UNIV_HOTBACKUP
176/** Writes the initial part of a log record (3..11 bytes).
177If the implementation of this function is changed, all size parameters to
178mlog_open() should be adjusted accordingly!
179@param[in] ptr pointer to (inside) a buffer frame holding the file
180 page where modification is made
181@param[in] type log item type: MLOG_1BYTE, ...
182@param[in] log_ptr pointer to mtr log which has been opened
183@param[in] mtr mtr
184@return new value of log_ptr */
185static inline byte *mlog_write_initial_log_record_fast(const byte *ptr,
187 byte *log_ptr,
188 mtr_t *mtr);
189#else /* !UNIV_HOTBACKUP */
190#define mlog_write_initial_log_record(ptr, type, mtr) ((void)0)
191#define mlog_write_initial_log_record_fast(ptr, type, log_ptr, mtr) ((byte *)0)
192#endif /* !UNIV_HOTBACKUP */
193
194/** Parses an initial log record written by mlog_write_initial_dict_log_record.
195@param[in] ptr buffer
196@param[in] end_ptr buffer end
197@param[out] type log record type, should be
198 MLOG_TABLE_DYNAMIC_META
199@param[out] id table id
200@param[out] version table dynamic metadata version
201@return parsed record end, NULL if not a complete record */
202byte *mlog_parse_initial_dict_log_record(const byte *ptr, const byte *end_ptr,
204 uint64_t *version);
205
206/** Parses an initial log record written by mlog_write_initial_log_record.
207 @return parsed record end, NULL if not a complete record */
209 const byte *ptr, /*!< in: buffer */
210 const byte *end_ptr, /*!< in: buffer end */
211 mlog_id_t *type, /*!< out: log record type: MLOG_1BYTE, ... */
212 space_id_t *space, /*!< out: space id */
213 page_no_t *page_no); /*!< out: page number */
214/** Parses a log record written by mlog_write_ulint or mlog_write_ull.
215 @return parsed record end, NULL if not a complete record */
217 mlog_id_t type, /*!< in: log record type: MLOG_1BYTE, ... */
218 const byte *ptr, /*!< in: buffer */
219 const byte *end_ptr, /*!< in: buffer end */
220 byte *page, /*!< in: page where to apply the log record,
221 or NULL */
222 void *page_zip); /*!< in/out: compressed page, or NULL */
223/** Parses a log record written by mlog_write_string.
224 @return parsed record end, NULL if not a complete record */
226 byte *ptr, /*!< in: buffer */
227 byte *end_ptr, /*!< in: buffer end */
228 byte *page, /*!< in: page where to apply the log record, or NULL */
229 void *page_zip); /*!< in/out: compressed page, or NULL */
230
231/** Opens a buffer for mlog, writes the initial log record and, if needed, the
232field lengths of an index. Reserves space for further log entries. The log
233entry must be closed with mtr_close().
234@param[in,out] mtr Mini-transaction
235@param[in] rec Index record or page
236@param[in] index Record descriptor
237@param[in] type Log item type
238@param[in] size Requested buffer size in bytes. if 0, calls
239 mlog_close() and returns false.
240@param[out] log_ptr Log buffer pointer
241@retval true if opened successfully.
242@retval false if not opened. One case is when redo is disabled for mtr. */
243bool mlog_open_and_write_index(mtr_t *mtr, const byte *rec,
244 const dict_index_t *index, mlog_id_t type,
245 size_t size, byte *&log_ptr);
246
247/** Parses a log record written by mlog_open_and_write_index.
248@param[in] ptr buffer
249@param[in] end_ptr buffer end
250@param[out] index own: dummy index
251@return parsed record end, NULL if not a complete record */
252byte *mlog_parse_index(byte *ptr, const byte *end_ptr, dict_index_t **index);
253
254/** Parses a log record written by mlog_open_and_write_index in version <= 8027.
255This function should never be changed and should be removed once recovery from
256mysql-8.0.27 is not needed anymore.
257@param[in] ptr buffer
258@param[in] end_ptr buffer end
259@param[in] comp true=compact row format
260@param[out] index own: dummy index
261@return parsed record end, NULL if not a complete record */
262byte *mlog_parse_index_8027(byte *ptr, const byte *end_ptr, bool comp,
263 dict_index_t **index);
264
265/** Insert, update, and maybe other functions may use this value to define an
266extra mlog buffer size for variable size data */
267constexpr auto MLOG_BUF_MARGIN = 256;
268
269#include "mtr0log.ic"
270
271#endif /* mtr0log_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:50
uint32_t page_no_t
Page number.
Definition: api0api.h:48
int page
Definition: ctype-mb.cc:1235
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:217
The dynamically allocated buffer implementation.
static bool mlog_open_metadata(mtr_t *mtr, ulint size, byte *&buffer)
Opens a buffer to mlog.
static void mlog_catenate_ulint(mtr_buf_t *dyn_buf, ulint val, mlog_id_t type)
Catenates 1 - 4 bytes to the mtr log.
constexpr size_t REDO_LOG_INITIAL_INFO_SIZE
Definition: mtr0log.h:61
void mlog_log_string(byte *ptr, ulint len, mtr_t *mtr)
Logs a write of a string to a file page buffered in the buffer pool.
Definition: mtr0log.cc:341
byte * mlog_parse_nbytes(mlog_id_t type, const byte *ptr, const byte *end_ptr, byte *page, void *page_zip)
Parses a log record written by mlog_write_ulint or mlog_write_ull.
Definition: mtr0log.cc:162
void mlog_catenate_string(mtr_t *mtr, const byte *str, ulint len)
Catenates n bytes to the mtr log.
Definition: mtr0log.cc:59
static byte * mlog_write_initial_log_record_fast(const byte *ptr, mlog_id_t type, byte *log_ptr, mtr_t *mtr)
Writes the initial part of a log record (3..11 bytes).
byte * mlog_parse_initial_dict_log_record(const byte *ptr, const byte *end_ptr, mlog_id_t *type, table_id_t *id, uint64_t *version)
Parses an initial log record written by mlog_write_initial_dict_log_record.
Definition: mtr0log.cc:102
constexpr auto MLOG_BUF_MARGIN
Insert, update, and maybe other functions may use this value to define an extra mlog buffer size for ...
Definition: mtr0log.h:267
static bool mlog_open(mtr_t *mtr, ulint size, byte *&buffer)
Opens a buffer to mlog.
static void mlog_catenate_ull_compressed(mtr_t *mtr, uint64_t val)
Catenates a compressed 64-bit integer to mlog.
static void mlog_catenate_ulint_compressed(mtr_t *mtr, ulint val)
Catenates a compressed ulint to mlog.
byte * mlog_parse_string(byte *ptr, byte *end_ptr, byte *page, void *page_zip)
Parses a log record written by mlog_write_string.
Definition: mtr0log.cc:371
byte * mlog_parse_initial_log_record(const byte *ptr, const byte *end_ptr, mlog_id_t *type, space_id_t *space, page_no_t *page_no)
Parses an initial log record written by mlog_write_initial_log_record.
Definition: mtr0log.cc:131
void mlog_write_ulint(byte *ptr, ulint val, mlog_id_t type, mtr_t *mtr)
Writes 1, 2 or 4 bytes to a file page.
Definition: mtr0log.cc:255
bool mlog_open_and_write_index(mtr_t *mtr, const byte *rec, const dict_index_t *index, mlog_id_t type, size_t size, byte *&log_ptr)
Opens a buffer for mlog, writes the initial log record and, if needed, the field lengths of an index.
Definition: mtr0log.cc:779
byte * mlog_parse_index_8027(byte *ptr, const byte *end_ptr, bool comp, dict_index_t **index)
Parses a log record written by mlog_open_and_write_index in version <= 8027.
Definition: mtr0log.cc:413
void mlog_write_string(byte *ptr, const byte *str, ulint len, mtr_t *mtr)
Writes a string to a file page buffered in the buffer pool.
Definition: mtr0log.cc:326
void mlog_write_initial_log_record(const byte *ptr, mlog_id_t type, mtr_t *mtr)
Writes initial part of a log record consisting of one-byte item type and four-byte space and page num...
Definition: mtr0log.cc:71
void mlog_write_ull(byte *ptr, uint64_t val, mtr_t *mtr)
Writes 8 bytes to a file page.
Definition: mtr0log.cc:297
static byte * mlog_write_initial_dict_log_record(mlog_id_t type, table_id_t id, uint64_t version, byte *log_ptr, mtr_t *mtr)
Writes a log record about a dictionary operation, which would cost at most 23 bytes.
static void mlog_close(mtr_t *mtr, byte *ptr)
Closes a buffer opened to mlog.
static byte * mlog_write_initial_log_record_low(mlog_id_t type, space_id_t space_id, page_no_t page_no, byte *log_ptr, mtr_t *mtr)
Writes a log record about an operation.
byte * mlog_parse_index(byte *ptr, const byte *end_ptr, dict_index_t **index)
Parses a log record written by mlog_open_and_write_index.
Definition: mtr0log.cc:1155
Mini-transaction logging routines.
Mini-transaction buffer.
mlog_id_t
Definition: mtr0types.h:62
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1063
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
required uint64 version
Definition: replication_group_member_actions.proto:40
required string type
Definition: replication_group_member_actions.proto:33
Data structure for an index.
Definition: dict0mem.h:1021
space_id_t space_id() const
Get the space id of the tablespace to which this index belongs.
Definition: dict0mem.h:1609
unsigned space
space where the index tree is placed
Definition: dict0mem.h:1038
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:181
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:407