MySQL 8.0.39
Source Code Documentation
mtr0log.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/mtr0log.h
29 Mini-transaction logging routines
30
31 Created 12/7/1995 Heikki Tuuri
32 *******************************************************/
33
34#ifndef mtr0log_h
35#define mtr0log_h
36
37#include "dyn0buf.h"
38#include "mtr0mtr.h"
39#include "univ.i"
40
41// Forward declaration
42struct dict_index_t;
43
44/* Index logging version */
45constexpr uint8_t INDEX_LOG_VERSION_0 = 0;
46constexpr uint8_t INDEX_LOG_VERSION_CURRENT = 1;
48
49#define COMPACT_FLAG 0x01
50#define VERSION_FLAG 0x02
51#define INSTANT_FLAG 0x04
52
53#define IS_INSTANT(flags) (flags & INSTANT_FLAG)
54#define IS_VERSIONED(flags) (flags & VERSION_FLAG)
55#define IS_COMPACT(flags) (flags & COMPACT_FLAG)
56
57#define SET_INSTANT(flags) (flag |= INSTANT_FLAG)
58#define SET_VERSIONED(flags) (flag |= VERSION_FLAG)
59#define SET_COMPACT(flags) (flag |= COMPACT_FLAG)
60
61/* Size of initial info on REDO log
62 1 byte for LOG TYPE
63 3-5 bytes for SPACE ID
64 3-5 bytes for PAGE OFFSET */
65constexpr size_t REDO_LOG_INITIAL_INFO_SIZE = 11;
66
67/** Writes 1, 2 or 4 bytes to a file page. Writes the corresponding log
68 record to the mini-transaction log if mtr is not NULL. */
70 byte *ptr, /*!< in: pointer where to write */
71 ulint val, /*!< in: value to write */
72 mlog_id_t type, /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
73 mtr_t *mtr); /*!< in: mini-transaction handle */
74
75/** Writes 8 bytes to a file page. Writes the corresponding log
76 record to the mini-transaction log, only if mtr is not NULL */
77void mlog_write_ull(byte *ptr, /*!< in: pointer where to write */
78 uint64_t val, /*!< in: value to write */
79 mtr_t *mtr); /*!< in: mini-transaction handle */
80/** Writes a string to a file page buffered in the buffer pool. Writes the
81 corresponding log record to the mini-transaction log. */
82void mlog_write_string(byte *ptr, /*!< in: pointer where to write */
83 const byte *str, /*!< in: string to write */
84 ulint len, /*!< in: string length */
85 mtr_t *mtr); /*!< in: mini-transaction handle */
86/** Logs a write of a string to a file page buffered in the buffer pool.
87 Writes the corresponding log record to the mini-transaction log. */
88void mlog_log_string(byte *ptr, /*!< in: pointer written to */
89 ulint len, /*!< in: string length */
90 mtr_t *mtr); /*!< in: mini-transaction handle */
91/** Writes initial part of a log record consisting of one-byte item
92 type and four-byte space and page numbers. */
94 const byte *ptr, /*!< in: pointer to (inside) a buffer
95 frame holding the file page where
96 modification is made */
97 mlog_id_t type, /*!< in: log item type: MLOG_1BYTE, ... */
98 mtr_t *mtr); /*!< in: mini-transaction handle */
99
100/** Catenates 1 - 4 bytes to the mtr log. The value is not compressed.
101@param[in,out] dyn_buf buffer to write
102@param[in] val value to write
103@param[in] type type of value to write */
104static inline void mlog_catenate_ulint(mtr_buf_t *dyn_buf, ulint val,
106
107/** Catenates 1 - 4 bytes to the mtr log.
108@param[in] mtr mtr
109@param[in] val value to write
110@param[in] type MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
111static inline void mlog_catenate_ulint(mtr_t *mtr, ulint val, mlog_id_t type);
112
113/** Catenates n bytes to the mtr log.
114@param[in] mtr Mini-transaction
115@param[in] str String to write
116@param[in] len String length */
117void mlog_catenate_string(mtr_t *mtr, const byte *str, ulint len);
118
119/** Catenates a compressed ulint to mlog.
120@param[in] mtr mtr
121@param[in] val value to write */
122static inline void mlog_catenate_ulint_compressed(mtr_t *mtr, ulint val);
123
124/** Catenates a compressed 64-bit integer to mlog.
125@param[in] mtr mtr
126@param[in] val value to write */
127static inline void mlog_catenate_ull_compressed(mtr_t *mtr, uint64_t val);
128
129/** Opens a buffer to mlog. It must be closed with mlog_close.
130@param[in,out] mtr mtr
131@param[in] size buffer size in bytes; MUST be smaller than
132 DYN_ARRAY_DATA_SIZE!
133@param[out] buffer mlog buffer pointer if opened successfully
134@retval true if opened successfully.
135@retval false if not opened. One case is when redo is disabled for mtr. */
136[[nodiscard]] static inline bool mlog_open(mtr_t *mtr, ulint size,
137 byte *&buffer);
138
139/** Opens a buffer to mlog. It must be closed with mlog_close.
140This is used for writing log for metadata changes
141@param[in,out] mtr mtr
142@param[in] size buffer size in bytes; MUST be smaller than
143 DYN_ARRAY_DATA_SIZE!
144@param[out] buffer mlog buffer pointer if opened successfully
145@retval true if opened successfully.
146@retval false if not opened. One case is when redo is disabled for mtr. */
147[[nodiscard]] static inline bool mlog_open_metadata(mtr_t *mtr, ulint size,
148 byte *&buffer);
149
150/** Closes a buffer opened to mlog.
151@param[in] mtr mtr
152@param[in] ptr buffer space from ptr up was not used */
153static inline void mlog_close(mtr_t *mtr, byte *ptr);
154
155/** Writes a log record about a dictionary operation, which would cost
156at most 23 bytes.
157@param[in] type Redo log record type
158@param[in] id Table id
159@param[in] version Table dynamic metadata version
160@param[in,out] log_ptr Current end of mini-transaction log
161@param[in,out] mtr Mini-transaction
162@return end of mini-transaction log */
164 mlog_id_t type, table_id_t id, uint64_t version, byte *log_ptr, mtr_t *mtr);
165
166/** Writes a log record about an operation.
167@param[in] type Redo log record type
168@param[in] space_id Tablespace identifier
169@param[in] page_no Page number
170@param[in,out] log_ptr Current end of mini-transaction log
171@param[in,out] mtr Mini-transaction
172@return end of mini-transaction log */
175 page_no_t page_no,
176 byte *log_ptr,
177 mtr_t *mtr);
178
179#ifndef UNIV_HOTBACKUP
180/** Writes the initial part of a log record (3..11 bytes).
181If the implementation of this function is changed, all size parameters to
182mlog_open() should be adjusted accordingly!
183@param[in] ptr pointer to (inside) a buffer frame holding the file
184 page where modification is made
185@param[in] type log item type: MLOG_1BYTE, ...
186@param[in] log_ptr pointer to mtr log which has been opened
187@param[in] mtr mtr
188@return new value of log_ptr */
189static inline byte *mlog_write_initial_log_record_fast(const byte *ptr,
191 byte *log_ptr,
192 mtr_t *mtr);
193#else /* !UNIV_HOTBACKUP */
194#define mlog_write_initial_log_record(ptr, type, mtr) ((void)0)
195#define mlog_write_initial_log_record_fast(ptr, type, log_ptr, mtr) ((byte *)0)
196#endif /* !UNIV_HOTBACKUP */
197
198/** Parses an initial log record written by mlog_write_initial_dict_log_record.
199@param[in] ptr buffer
200@param[in] end_ptr buffer end
201@param[out] type log record type, should be
202 MLOG_TABLE_DYNAMIC_META
203@param[out] id table id
204@param[out] version table dynamic metadata version
205@return parsed record end, NULL if not a complete record */
206byte *mlog_parse_initial_dict_log_record(const byte *ptr, const byte *end_ptr,
208 uint64_t *version);
209
210/** Parses an initial log record written by mlog_write_initial_log_record.
211 @return parsed record end, NULL if not a complete record */
213 const byte *ptr, /*!< in: buffer */
214 const byte *end_ptr, /*!< in: buffer end */
215 mlog_id_t *type, /*!< out: log record type: MLOG_1BYTE, ... */
216 space_id_t *space, /*!< out: space id */
217 page_no_t *page_no); /*!< out: page number */
218/** Parses a log record written by mlog_write_ulint or mlog_write_ull.
219 @return parsed record end, NULL if not a complete record */
221 mlog_id_t type, /*!< in: log record type: MLOG_1BYTE, ... */
222 const byte *ptr, /*!< in: buffer */
223 const byte *end_ptr, /*!< in: buffer end */
224 byte *page, /*!< in: page where to apply the log record,
225 or NULL */
226 void *page_zip); /*!< in/out: compressed page, or NULL */
227/** Parses a log record written by mlog_write_string.
228 @return parsed record end, NULL if not a complete record */
230 byte *ptr, /*!< in: buffer */
231 byte *end_ptr, /*!< in: buffer end */
232 byte *page, /*!< in: page where to apply the log record, or NULL */
233 void *page_zip); /*!< in/out: compressed page, or NULL */
234
235/** Opens a buffer for mlog, writes the initial log record and, if needed, the
236field lengths of an index. Reserves space for further log entries. The log
237entry must be closed with mtr_close().
238@param[in,out] mtr Mini-transaction
239@param[in] rec Index record or page
240@param[in] index Record descriptor
241@param[in] type Log item type
242@param[in] size Requested buffer size in bytes. if 0, calls
243 mlog_close() and returns false.
244@param[out] log_ptr Log buffer pointer
245@retval true if opened successfully.
246@retval false if not opened. One case is when redo is disabled for mtr. */
247bool mlog_open_and_write_index(mtr_t *mtr, const byte *rec,
248 const dict_index_t *index, mlog_id_t type,
249 size_t size, byte *&log_ptr);
250
251/** Parses a log record written by mlog_open_and_write_index.
252@param[in] ptr buffer
253@param[in] end_ptr buffer end
254@param[out] index own: dummy index
255@return parsed record end, NULL if not a complete record */
256byte *mlog_parse_index(byte *ptr, const byte *end_ptr, dict_index_t **index);
257
258/** Parses a log record written by mlog_open_and_write_index in version <= 8027.
259This function should never be changed and should be removed once recovery from
260mysql-8.0.27 is not needed anymore.
261@param[in] ptr buffer
262@param[in] end_ptr buffer end
263@param[in] comp true=compact row format
264@param[out] index own: dummy index
265@return parsed record end, NULL if not a complete record */
266byte *mlog_parse_index_8027(byte *ptr, const byte *end_ptr, bool comp,
267 dict_index_t **index);
268
269/** Insert, update, and maybe other functions may use this value to define an
270extra mlog buffer size for variable size data */
271constexpr auto MLOG_BUF_MARGIN = 256;
272
273#include "mtr0log.ic"
274
275#endif /* mtr0log_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:51
uint32_t page_no_t
Page number.
Definition: api0api.h:49
int page
Definition: ctype-mb.cc:1236
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:232
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 uint8_t INDEX_LOG_VERSION_0
Definition: mtr0log.h:45
constexpr uint8_t INDEX_LOG_VERSION_CURRENT
Definition: mtr0log.h:46
constexpr size_t REDO_LOG_INITIAL_INFO_SIZE
Definition: mtr0log.h:65
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:342
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:163
void mlog_catenate_string(mtr_t *mtr, const byte *str, ulint len)
Catenates n bytes to the mtr log.
Definition: mtr0log.cc:60
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:103
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:271
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:372
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:132
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:256
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:795
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:414
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:327
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:72
void mlog_write_ull(byte *ptr, uint64_t val, mtr_t *mtr)
Writes 8 bytes to a file page.
Definition: mtr0log.cc:298
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.
constexpr uint8_t INDEX_LOG_VERSION_MAX
Definition: mtr0log.h:47
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:1211
Mini-transaction logging routines.
Mini-transaction buffer.
mlog_id_t
Definition: mtr0types.h:63
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:420
required uint64 version
Definition: replication_group_member_actions.proto:41
required string type
Definition: replication_group_member_actions.proto:34
Data structure for an index.
Definition: dict0mem.h:1046
space_id_t space_id() const
Get the space id of the tablespace to which this index belongs.
Definition: dict0mem.h:1634
unsigned space
space where the index tree is placed
Definition: dict0mem.h:1063
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:177
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:406