MySQL  8.0.19
Source Code Documentation
mtr0log.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2019, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 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
41 struct dict_index_t;
42 
43 /** Writes 1, 2 or 4 bytes to a file page. Writes the corresponding log
44  record to the mini-transaction log if mtr is not NULL. */
45 void mlog_write_ulint(
46  byte *ptr, /*!< in: pointer where to write */
47  ulint val, /*!< in: value to write */
48  mlog_id_t type, /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
49  mtr_t *mtr); /*!< in: mini-transaction handle */
50 
51 /** Writes 8 bytes to a file page. Writes the corresponding log
52  record to the mini-transaction log, only if mtr is not NULL */
53 void mlog_write_ull(byte *ptr, /*!< in: pointer where to write */
54  ib_uint64_t val, /*!< in: value to write */
55  mtr_t *mtr); /*!< in: mini-transaction handle */
56 /** Writes a string to a file page buffered in the buffer pool. Writes the
57  corresponding log record to the mini-transaction log. */
58 void mlog_write_string(byte *ptr, /*!< in: pointer where to write */
59  const byte *str, /*!< in: string to write */
60  ulint len, /*!< in: string length */
61  mtr_t *mtr); /*!< in: mini-transaction handle */
62 /** Logs a write of a string to a file page buffered in the buffer pool.
63  Writes the corresponding log record to the mini-transaction log. */
64 void mlog_log_string(byte *ptr, /*!< in: pointer written to */
65  ulint len, /*!< in: string length */
66  mtr_t *mtr); /*!< in: mini-transaction handle */
67 /** Writes initial part of a log record consisting of one-byte item
68  type and four-byte space and page numbers. */
70  const byte *ptr, /*!< in: pointer to (inside) a buffer
71  frame holding the file page where
72  modification is made */
73  mlog_id_t type, /*!< in: log item type: MLOG_1BYTE, ... */
74  mtr_t *mtr); /*!< in: mini-transaction handle */
75 
76 /** Catenates 1 - 4 bytes to the mtr log. The value is not compressed.
77 @param[in,out] dyn_buf buffer to write
78 @param[in] val value to write
79 @param[in] type type of value to write */
80 UNIV_INLINE
81 void mlog_catenate_ulint(mtr_buf_t *dyn_buf, ulint val, mlog_id_t type);
82 
83 /** Catenates 1 - 4 bytes to the mtr log.
84 @param[in] mtr mtr
85 @param[in] val value to write
86 @param[in] type MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
87 UNIV_INLINE
88 void mlog_catenate_ulint(mtr_t *mtr, ulint val, mlog_id_t type);
89 
90 /** Catenates n bytes to the mtr log. */
91 void mlog_catenate_string(mtr_t *mtr, /*!< in: mtr */
92  const byte *str, /*!< in: string to write */
93  ulint len); /*!< in: string length */
94 
95 /** Catenates a compressed ulint to mlog.
96 @param[in] mtr mtr
97 @param[in] val value to write */
98 UNIV_INLINE
99 void mlog_catenate_ulint_compressed(mtr_t *mtr, ulint val);
100 
101 /** Catenates a compressed 64-bit integer to mlog.
102 @param[in] mtr mtr
103 @param[in] val value to write */
104 UNIV_INLINE
105 void mlog_catenate_ull_compressed(mtr_t *mtr, ib_uint64_t val);
106 
107 /** Opens a buffer to mlog. It must be closed with mlog_close.
108 @param[in,out] mtr mtr
109 @param[in] size buffer size in bytes; MUST be smaller than
110  DYN_ARRAY_DATA_SIZE!
111 @return buffer, NULL if log mode MTR_LOG_NONE */
112 UNIV_INLINE
113 byte *mlog_open(mtr_t *mtr, ulint size);
114 
115 /** Opens a buffer to mlog. It must be closed with mlog_close.
116 This is used for writing log for metadata changes
117 @param[in,out] mtr mtr
118 @param[in] size buffer size in bytes; MUST be smaller than
119  DYN_ARRAY_DATA_SIZE!
120 @return buffer */
121 UNIV_INLINE
122 byte *mlog_open_metadata(mtr_t *mtr, ulint size);
123 
124 /** Closes a buffer opened to mlog.
125 @param[in] mtr mtr
126 @param[in] ptr buffer space from ptr up was not used */
127 UNIV_INLINE
128 void mlog_close(mtr_t *mtr, byte *ptr);
129 
130 /** Writes a log record about a dictionary operation, which would cost
131 at most 23 bytes.
132 @param[in] type redo log record type
133 @param[in] id table id
134 @param[in] version table dynamic metadata version
135 @param[in,out] log_ptr current end of mini-transaction log
136 @param[in,out] mtr mini-transaction
137 @return end of mini-transaction log */
138 UNIV_INLINE
140  uint64_t version, byte *log_ptr,
141  mtr_t *mtr);
142 
143 /** Writes a log record about an operation.
144 @param[in] type redo log record type
145 @param[in] space_id tablespace identifier
146 @param[in] page_no page number
147 @param[in,out] log_ptr current end of mini-transaction log
148 @param[in,out] mtr mini-transaction
149 @return end of mini-transaction log */
150 UNIV_INLINE
152  page_no_t page_no, byte *log_ptr,
153  mtr_t *mtr);
154 
155 #ifndef UNIV_HOTBACKUP
156 /** Writes the initial part of a log record (3..11 bytes).
157 If the implementation of this function is changed, all size parameters to
158 mlog_open() should be adjusted accordingly!
159 @param[in] ptr pointer to (inside) a buffer frame holding the file
160  page where modification is made
161 @param[in] type log item type: MLOG_1BYTE, ...
162 @param[in] log_ptr pointer to mtr log which has been opened
163 @param[in] mtr mtr
164 @return new value of log_ptr */
165 UNIV_INLINE
166 byte *mlog_write_initial_log_record_fast(const byte *ptr, mlog_id_t type,
167  byte *log_ptr, mtr_t *mtr);
168 #else /* !UNIV_HOTBACKUP */
169 #define mlog_write_initial_log_record(ptr, type, mtr) ((void)0)
170 #define mlog_write_initial_log_record_fast(ptr, type, log_ptr, mtr) ((byte *)0)
171 #endif /* !UNIV_HOTBACKUP */
172 
173 /** Parses an initial log record written by mlog_write_initial_dict_log_record.
174 @param[in] ptr buffer
175 @param[in] end_ptr buffer end
176 @param[out] type log record type, should be
177  MLOG_TABLE_DYNAMIC_META
178 @param[out] id table id
179 @param[out] version table dynamic metadata version
180 @return parsed record end, NULL if not a complete record */
181 byte *mlog_parse_initial_dict_log_record(const byte *ptr, const byte *end_ptr,
182  mlog_id_t *type, table_id_t *id,
183  uint64 *version);
184 
185 /** Parses an initial log record written by mlog_write_initial_log_record.
186  @return parsed record end, NULL if not a complete record */
188  const byte *ptr, /*!< in: buffer */
189  const byte *end_ptr, /*!< in: buffer end */
190  mlog_id_t *type, /*!< out: log record type: MLOG_1BYTE, ... */
191  space_id_t *space, /*!< out: space id */
192  page_no_t *page_no); /*!< out: page number */
193 /** Parses a log record written by mlog_write_ulint or mlog_write_ull.
194  @return parsed record end, NULL if not a complete record */
195 byte *mlog_parse_nbytes(
196  mlog_id_t type, /*!< in: log record type: MLOG_1BYTE, ... */
197  const byte *ptr, /*!< in: buffer */
198  const byte *end_ptr, /*!< in: buffer end */
199  byte *page, /*!< in: page where to apply the log record,
200  or NULL */
201  void *page_zip); /*!< in/out: compressed page, or NULL */
202 /** Parses a log record written by mlog_write_string.
203  @return parsed record end, NULL if not a complete record */
204 byte *mlog_parse_string(
205  byte *ptr, /*!< in: buffer */
206  byte *end_ptr, /*!< in: buffer end */
207  byte *page, /*!< in: page where to apply the log record, or NULL */
208  void *page_zip); /*!< in/out: compressed page, or NULL */
209 
210 /** Opens a buffer for mlog, writes the initial log record and,
211  if needed, the field lengths of an index. Reserves space
212  for further log entries. The log entry must be closed with
213  mtr_close().
214  @return buffer, NULL if log mode MTR_LOG_NONE */
216  mtr_t *mtr, /*!< in: mtr */
217  const byte *rec, /*!< in: index record or page */
218  const dict_index_t *index, /*!< in: record descriptor */
219  mlog_id_t type, /*!< in: log item type */
220  ulint size); /*!< in: requested buffer size in bytes
221  (if 0, calls mlog_close() and
222  returns NULL) */
223 
224 /** Parses a log record written by mlog_open_and_write_index.
225  @return parsed record end, NULL if not a complete record */
226 byte *mlog_parse_index(byte *ptr, /*!< in: buffer */
227  const byte *end_ptr, /*!< in: buffer end */
228  ibool comp, /*!< in: TRUE=compact record format */
229  dict_index_t **index); /*!< out, own: dummy index */
230 
231 /** Insert, update, and maybe other functions may use this value to define an
232 extra mlog buffer size for variable size data */
233 #define MLOG_BUF_MARGIN 256
234 
235 #include "mtr0log.ic"
236 
237 #endif /* mtr0log_h */
page_no_t
uint32 page_no_t
Page number.
Definition: api0api.h:57
mlog_parse_initial_dict_log_record
byte * mlog_parse_initial_dict_log_record(const byte *ptr, const byte *end_ptr, mlog_id_t *type, table_id_t *id, uint64 *version)
Parses an initial log record written by mlog_write_initial_dict_log_record.
Definition: mtr0log.cc:96
mlog_write_initial_log_record
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:63
mlog_write_ull
void mlog_write_ull(byte *ptr, ib_uint64_t val, mtr_t *mtr)
Writes 8 bytes to a file page.
Definition: mtr0log.cc:289
version
const string version("\"Version\"")
dict_index_t
Data structure for an index.
Definition: dict0mem.h:869
mtr_t
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:169
uint64
uint64_t uint64
Definition: my_inttypes.h:68
mlog_write_string
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:316
mlog_open_metadata
UNIV_INLINE byte * mlog_open_metadata(mtr_t *mtr, ulint size)
Opens a buffer to mlog.
mlog_log_string
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:331
mlog_close
UNIV_INLINE void mlog_close(mtr_t *mtr, byte *ptr)
Closes a buffer opened to mlog.
dyn0buf.h
mlog_write_ulint
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:249
mlog_catenate_ulint
UNIV_INLINE void mlog_catenate_ulint(mtr_buf_t *dyn_buf, ulint val, mlog_id_t type)
Catenates 1 - 4 bytes to the mtr log.
table_id_t
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:215
page
int page
Definition: ctype-mb.cc:1232
mlog_open
UNIV_INLINE byte * mlog_open(mtr_t *mtr, ulint size)
Opens a buffer to mlog.
dict_index_t::space
unsigned space
space where the index tree is placed
Definition: dict0mem.h:875
mlog_write_initial_log_record_fast
UNIV_INLINE 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).
dyn_buf_t
Class that manages dynamic buffers.
Definition: dyn0buf.h:49
mlog_parse_string
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:363
mlog_write_initial_log_record_low
UNIV_INLINE 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.
dict_index_t::space_id
space_id_t space_id() const
Get the space id of the tablespace to which this index belongs.
Definition: dict0mem.h:1245
HttpMethod::type
int type
Definition: http_common.h:411
mlog_id_t
mlog_id_t
Definition: mtr0types.h:59
mtr0mtr.h
mlog_catenate_string
void mlog_catenate_string(mtr_t *mtr, const byte *str, ulint len)
Catenates n bytes to the mtr log.
Definition: mtr0log.cc:48
space_id_t
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
mlog_parse_nbytes
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:156
mlog_parse_initial_log_record
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:125
mlog_parse_index
byte * mlog_parse_index(byte *ptr, const byte *end_ptr, ibool comp, dict_index_t **index)
Parses a log record written by mlog_open_and_write_index.
Definition: mtr0log.cc:530
mlog_write_initial_dict_log_record
UNIV_INLINE 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.
mlog_open_and_write_index
byte * mlog_open_and_write_index(mtr_t *mtr, const byte *rec, const dict_index_t *index, mlog_id_t type, ulint size)
Opens a buffer for mlog, writes the initial log record and, if needed, the field lengths of an index.
Definition: mtr0log.cc:408
mlog_catenate_ulint_compressed
UNIV_INLINE void mlog_catenate_ulint_compressed(mtr_t *mtr, ulint val)
Catenates a compressed ulint to mlog.
mlog_catenate_ull_compressed
UNIV_INLINE void mlog_catenate_ull_compressed(mtr_t *mtr, ib_uint64_t val)
Catenates a compressed 64-bit integer to mlog.
index
char * index(const char *, int c)
Definition: mysql.cc:2875