MySQL 8.2.0
Source Code Documentation
mtr0log.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2023, 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/* Index logging version */
44constexpr uint8_t INDEX_LOG_VERSION_0 = 0;
45constexpr uint8_t INDEX_LOG_VERSION_CURRENT = 1;
47
48#define COMPACT_FLAG 0x01
49#define VERSION_FLAG 0x02
50#define INSTANT_FLAG 0x04
51
52#define IS_INSTANT(flags) (flags & INSTANT_FLAG)
53#define IS_VERSIONED(flags) (flags & VERSION_FLAG)
54#define IS_COMPACT(flags) (flags & COMPACT_FLAG)
55
56#define SET_INSTANT(flags) (flag |= INSTANT_FLAG)
57#define SET_VERSIONED(flags) (flag |= VERSION_FLAG)
58#define SET_COMPACT(flags) (flag |= COMPACT_FLAG)
59
60/* Size of initial info on REDO log
61 1 byte for LOG TYPE
62 3-5 bytes for SPACE ID
63 3-5 bytes for PAGE OFFSET */
64constexpr size_t REDO_LOG_INITIAL_INFO_SIZE = 11;
65
66/** Writes 1, 2 or 4 bytes to a file page. Writes the corresponding log
67 record to the mini-transaction log if mtr is not NULL. */
69 byte *ptr, /*!< in: pointer where to write */
70 ulint val, /*!< in: value to write */
71 mlog_id_t type, /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
72 mtr_t *mtr); /*!< in: mini-transaction handle */
73
74/** Writes 8 bytes to a file page. Writes the corresponding log
75 record to the mini-transaction log, only if mtr is not NULL */
76void mlog_write_ull(byte *ptr, /*!< in: pointer where to write */
77 uint64_t val, /*!< in: value to write */
78 mtr_t *mtr); /*!< in: mini-transaction handle */
79/** Writes a string to a file page buffered in the buffer pool. Writes the
80 corresponding log record to the mini-transaction log. */
81void mlog_write_string(byte *ptr, /*!< in: pointer where to write */
82 const byte *str, /*!< in: string to write */
83 ulint len, /*!< in: string length */
84 mtr_t *mtr); /*!< in: mini-transaction handle */
85/** Logs a write of a string to a file page buffered in the buffer pool.
86 Writes the corresponding log record to the mini-transaction log. */
87void mlog_log_string(byte *ptr, /*!< in: pointer written to */
88 ulint len, /*!< in: string length */
89 mtr_t *mtr); /*!< in: mini-transaction handle */
90/** Writes initial part of a log record consisting of one-byte item
91 type and four-byte space and page numbers. */
93 const byte *ptr, /*!< in: pointer to (inside) a buffer
94 frame holding the file page where
95 modification is made */
96 mlog_id_t type, /*!< in: log item type: MLOG_1BYTE, ... */
97 mtr_t *mtr); /*!< in: mini-transaction handle */
98
99/** Catenates 1 - 4 bytes to the mtr log. The value is not compressed.
100@param[in,out] dyn_buf buffer to write
101@param[in] val value to write
102@param[in] type type of value to write */
103static inline void mlog_catenate_ulint(mtr_buf_t *dyn_buf, ulint val,
105
106/** Catenates 1 - 4 bytes to the mtr log.
107@param[in] mtr mtr
108@param[in] val value to write
109@param[in] type MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
110static inline void mlog_catenate_ulint(mtr_t *mtr, ulint val, mlog_id_t type);
111
112/** Catenates n bytes to the mtr log.
113@param[in] mtr Mini-transaction
114@param[in] str String to write
115@param[in] len String length */
116void mlog_catenate_string(mtr_t *mtr, const byte *str, ulint len);
117
118/** Catenates a compressed ulint to mlog.
119@param[in] mtr mtr
120@param[in] val value to write */
121static inline void mlog_catenate_ulint_compressed(mtr_t *mtr, ulint val);
122
123/** Catenates a compressed 64-bit integer to mlog.
124@param[in] mtr mtr
125@param[in] val value to write */
126static inline void mlog_catenate_ull_compressed(mtr_t *mtr, uint64_t val);
127
128/** Opens a buffer to mlog. It must be closed with mlog_close.
129@param[in,out] mtr mtr
130@param[in] size buffer size in bytes; MUST be smaller than
131 DYN_ARRAY_DATA_SIZE!
132@param[out] buffer mlog buffer pointer if opened successfully
133@retval true if opened successfully.
134@retval false if not opened. One case is when redo is disabled for mtr. */
135[[nodiscard]] static inline bool mlog_open(mtr_t *mtr, ulint size,
136 byte *&buffer);
137
138/** Opens a buffer to mlog. It must be closed with mlog_close.
139This is used for writing log for metadata changes
140@param[in,out] mtr mtr
141@param[in] size buffer size in bytes; MUST be smaller than
142 DYN_ARRAY_DATA_SIZE!
143@param[out] buffer mlog buffer pointer if opened successfully
144@retval true if opened successfully.
145@retval false if not opened. One case is when redo is disabled for mtr. */
146[[nodiscard]] static inline bool mlog_open_metadata(mtr_t *mtr, ulint size,
147 byte *&buffer);
148
149/** Closes a buffer opened to mlog.
150@param[in] mtr mtr
151@param[in] ptr buffer space from ptr up was not used */
152static inline void mlog_close(mtr_t *mtr, byte *ptr);
153
154/** Writes a log record about a dictionary operation, which would cost
155at most 23 bytes.
156@param[in] type Redo log record type
157@param[in] id Table id
158@param[in] version Table dynamic metadata version
159@param[in,out] log_ptr Current end of mini-transaction log
160@param[in,out] mtr Mini-transaction
161@return end of mini-transaction log */
163 mlog_id_t type, table_id_t id, uint64_t version, byte *log_ptr, mtr_t *mtr);
164
165/** Writes a log record about an operation.
166@param[in] type Redo log record type
167@param[in] space_id Tablespace identifier
168@param[in] page_no Page number
169@param[in,out] log_ptr Current end of mini-transaction log
170@param[in,out] mtr Mini-transaction
171@return end of mini-transaction log */
174 page_no_t page_no,
175 byte *log_ptr,
176 mtr_t *mtr);
177
178#ifndef UNIV_HOTBACKUP
179/** Writes the initial part of a log record (3..11 bytes).
180If the implementation of this function is changed, all size parameters to
181mlog_open() should be adjusted accordingly!
182@param[in] ptr pointer to (inside) a buffer frame holding the file
183 page where modification is made
184@param[in] type log item type: MLOG_1BYTE, ...
185@param[in] log_ptr pointer to mtr log which has been opened
186@param[in] mtr mtr
187@return new value of log_ptr */
188static inline byte *mlog_write_initial_log_record_fast(const byte *ptr,
190 byte *log_ptr,
191 mtr_t *mtr);
192#else /* !UNIV_HOTBACKUP */
193#define mlog_write_initial_log_record(ptr, type, mtr) ((void)0)
194#define mlog_write_initial_log_record_fast(ptr, type, log_ptr, mtr) \
195 ((byte *)nullptr)
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:50
uint32_t page_no_t
Page number.
Definition: api0api.h:48
int page
Definition: ctype-mb.cc:1233
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 uint8_t INDEX_LOG_VERSION_0
Definition: mtr0log.h:44
constexpr uint8_t INDEX_LOG_VERSION_CURRENT
Definition: mtr0log.h:45
constexpr size_t REDO_LOG_INITIAL_INFO_SIZE
Definition: mtr0log.h:64
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:344
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: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:374
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:782
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:416
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.
constexpr uint8_t INDEX_LOG_VERSION_MAX
Definition: mtr0log.h:46
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:1164
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:1085
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:417
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:1045
space_id_t space_id() const
Get the space id of the tablespace to which this index belongs.
Definition: dict0mem.h:1633
unsigned space
space where the index tree is placed
Definition: dict0mem.h:1062
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:176
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:405