1 | /***************************************************************************** |
2 | |
3 | Copyright (c) 1995, 2014, 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 as published by the Free Software |
7 | Foundation; version 2 of the License. |
8 | |
9 | This program is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
11 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License along with |
14 | this program; if not, write to the Free Software Foundation, Inc., |
15 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
16 | |
17 | *****************************************************************************/ |
18 | |
19 | /**************************************************//** |
20 | @file include/mtr0log.h |
21 | Mini-transaction logging routines |
22 | |
23 | Created 12/7/1995 Heikki Tuuri |
24 | *******************************************************/ |
25 | |
26 | #ifndef mtr0log_h |
27 | #define mtr0log_h |
28 | |
29 | #include "univ.i" |
30 | #include "mtr0mtr.h" |
31 | #include "dyn0buf.h" |
32 | |
33 | // Forward declaration |
34 | struct dict_index_t; |
35 | |
36 | /********************************************************//** |
37 | Writes 1, 2 or 4 bytes to a file page. Writes the corresponding log |
38 | record to the mini-transaction log if mtr is not NULL. */ |
39 | void |
40 | mlog_write_ulint( |
41 | /*=============*/ |
42 | byte* ptr, /*!< in: pointer where to write */ |
43 | ulint val, /*!< in: value to write */ |
44 | mlog_id_t type, /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */ |
45 | mtr_t* mtr); /*!< in: mini-transaction handle */ |
46 | |
47 | /********************************************************//** |
48 | Writes 8 bytes to a file page. Writes the corresponding log |
49 | record to the mini-transaction log, only if mtr is not NULL */ |
50 | void |
51 | mlog_write_ull( |
52 | /*===========*/ |
53 | 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 | /********************************************************//** |
57 | Writes a string to a file page buffered in the buffer pool. Writes the |
58 | corresponding log record to the mini-transaction log. */ |
59 | void |
60 | mlog_write_string( |
61 | /*==============*/ |
62 | byte* ptr, /*!< in: pointer where to write */ |
63 | const byte* str, /*!< in: string to write */ |
64 | ulint len, /*!< in: string length */ |
65 | mtr_t* mtr); /*!< in: mini-transaction handle */ |
66 | /********************************************************//** |
67 | Logs a write of a string to a file page buffered in the buffer pool. |
68 | Writes the corresponding log record to the mini-transaction log. */ |
69 | void |
70 | mlog_log_string( |
71 | /*============*/ |
72 | byte* ptr, /*!< in: pointer written to */ |
73 | ulint len, /*!< in: string length */ |
74 | mtr_t* mtr); /*!< in: mini-transaction handle */ |
75 | /********************************************************//** |
76 | Writes initial part of a log record consisting of one-byte item |
77 | type and four-byte space and page numbers. */ |
78 | void |
79 | mlog_write_initial_log_record( |
80 | /*==========================*/ |
81 | const byte* ptr, /*!< in: pointer to (inside) a buffer |
82 | frame holding the file page where |
83 | modification is made */ |
84 | mlog_id_t type, /*!< in: log item type: MLOG_1BYTE, ... */ |
85 | mtr_t* mtr); /*!< in: mini-transaction handle */ |
86 | /********************************************************//** |
87 | Catenates 1 - 4 bytes to the mtr log. The value is not compressed. */ |
88 | UNIV_INLINE |
89 | void |
90 | mlog_catenate_ulint( |
91 | /*================*/ |
92 | mtr_buf_t* dyn_buf, /*!< in/out: buffer to write */ |
93 | ulint val, /*!< in: value to write */ |
94 | mlog_id_t type); /*!< in: type of value to write */ |
95 | /********************************************************//** |
96 | Catenates 1 - 4 bytes to the mtr log. */ |
97 | UNIV_INLINE |
98 | void |
99 | mlog_catenate_ulint( |
100 | /*================*/ |
101 | mtr_t* mtr, /*!< in: mtr */ |
102 | ulint val, /*!< in: value to write */ |
103 | mlog_id_t type); /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */ |
104 | /********************************************************//** |
105 | Catenates n bytes to the mtr log. */ |
106 | void |
107 | mlog_catenate_string( |
108 | /*=================*/ |
109 | mtr_t* mtr, /*!< in: mtr */ |
110 | const byte* str, /*!< in: string to write */ |
111 | ulint len); /*!< in: string length */ |
112 | /********************************************************//** |
113 | Catenates a compressed ulint to mlog. */ |
114 | UNIV_INLINE |
115 | void |
116 | mlog_catenate_ulint_compressed( |
117 | /*===========================*/ |
118 | mtr_t* mtr, /*!< in: mtr */ |
119 | ulint val); /*!< in: value to write */ |
120 | /********************************************************//** |
121 | Catenates a compressed 64-bit integer to mlog. */ |
122 | UNIV_INLINE |
123 | void |
124 | mlog_catenate_ull_compressed( |
125 | /*=========================*/ |
126 | mtr_t* mtr, /*!< in: mtr */ |
127 | ib_uint64_t val); /*!< in: value to write */ |
128 | /********************************************************//** |
129 | Opens a buffer to mlog. It must be closed with mlog_close. |
130 | @return buffer, NULL if log mode MTR_LOG_NONE */ |
131 | UNIV_INLINE |
132 | byte* |
133 | mlog_open( |
134 | /*======*/ |
135 | mtr_t* mtr, /*!< in: mtr */ |
136 | ulint size); /*!< in: buffer size in bytes; MUST be |
137 | smaller than DYN_ARRAY_DATA_SIZE! */ |
138 | /********************************************************//** |
139 | Closes a buffer opened to mlog. */ |
140 | UNIV_INLINE |
141 | void |
142 | mlog_close( |
143 | /*=======*/ |
144 | mtr_t* mtr, /*!< in: mtr */ |
145 | byte* ptr); /*!< in: buffer space from ptr up was |
146 | not used */ |
147 | |
148 | /** Writes a log record about an operation. |
149 | @param[in] type redo log record type |
150 | @param[in] space_id tablespace identifier |
151 | @param[in] page_no page number |
152 | @param[in,out] log_ptr current end of mini-transaction log |
153 | @param[in,out] mtr mini-transaction |
154 | @return end of mini-transaction log */ |
155 | UNIV_INLINE |
156 | byte* |
157 | mlog_write_initial_log_record_low( |
158 | mlog_id_t type, |
159 | ulint space_id, |
160 | ulint page_no, |
161 | byte* log_ptr, |
162 | mtr_t* mtr); |
163 | |
164 | /********************************************************//** |
165 | Writes the initial part of a log record (3..11 bytes). |
166 | If the implementation of this function is changed, all |
167 | size parameters to mlog_open() should be adjusted accordingly! |
168 | @return new value of log_ptr */ |
169 | UNIV_INLINE |
170 | byte* |
171 | mlog_write_initial_log_record_fast( |
172 | /*===============================*/ |
173 | const byte* ptr, /*!< in: pointer to (inside) a buffer |
174 | frame holding the file page where |
175 | modification is made */ |
176 | mlog_id_t type, /*!< in: log item type: MLOG_1BYTE, ... */ |
177 | byte* log_ptr,/*!< in: pointer to mtr log which has |
178 | been opened */ |
179 | mtr_t* mtr); /*!< in: mtr */ |
180 | /********************************************************//** |
181 | Parses an initial log record written by mlog_write_initial_log_record. |
182 | @return parsed record end, NULL if not a complete record */ |
183 | byte* |
184 | mlog_parse_initial_log_record( |
185 | /*==========================*/ |
186 | const byte* ptr, /*!< in: buffer */ |
187 | const byte* end_ptr,/*!< in: buffer end */ |
188 | mlog_id_t* type, /*!< out: log record type: MLOG_1BYTE, ... */ |
189 | ulint* space, /*!< out: space id */ |
190 | ulint* page_no);/*!< out: page number */ |
191 | /********************************************************//** |
192 | Parses a log record written by mlog_write_ulint or mlog_write_ull. |
193 | @return parsed record end, NULL if not a complete record */ |
194 | byte* |
195 | mlog_parse_nbytes( |
196 | /*==============*/ |
197 | mlog_id_t type, /*!< in: log record type: MLOG_1BYTE, ... */ |
198 | const byte* ptr, /*!< in: buffer */ |
199 | const byte* end_ptr,/*!< in: buffer end */ |
200 | byte* page, /*!< in: page where to apply the log record, |
201 | or NULL */ |
202 | void* page_zip);/*!< in/out: compressed page, or NULL */ |
203 | /********************************************************//** |
204 | Parses a log record written by mlog_write_string. |
205 | @return parsed record end, NULL if not a complete record */ |
206 | byte* |
207 | mlog_parse_string( |
208 | /*==============*/ |
209 | byte* ptr, /*!< in: buffer */ |
210 | byte* end_ptr,/*!< in: buffer end */ |
211 | byte* page, /*!< in: page where to apply the log record, or NULL */ |
212 | void* page_zip);/*!< in/out: compressed page, or NULL */ |
213 | |
214 | /********************************************************//** |
215 | Opens a buffer for mlog, writes the initial log record and, |
216 | if needed, the field lengths of an index. Reserves space |
217 | for further log entries. The log entry must be closed with |
218 | mtr_close(). |
219 | @return buffer, NULL if log mode MTR_LOG_NONE */ |
220 | byte* |
221 | mlog_open_and_write_index( |
222 | /*======================*/ |
223 | mtr_t* mtr, /*!< in: mtr */ |
224 | const byte* rec, /*!< in: index record or page */ |
225 | const dict_index_t* index, /*!< in: record descriptor */ |
226 | mlog_id_t type, /*!< in: log item type */ |
227 | ulint size); /*!< in: requested buffer size in bytes |
228 | (if 0, calls mlog_close() and |
229 | returns NULL) */ |
230 | |
231 | /********************************************************//** |
232 | Parses a log record written by mlog_open_and_write_index. |
233 | @return parsed record end, NULL if not a complete record */ |
234 | byte* |
235 | mlog_parse_index( |
236 | /*=============*/ |
237 | byte* ptr, /*!< in: buffer */ |
238 | const byte* end_ptr,/*!< in: buffer end */ |
239 | ibool comp, /*!< in: TRUE=compact record format */ |
240 | dict_index_t** index); /*!< out, own: dummy index */ |
241 | |
242 | /** Insert, update, and maybe other functions may use this value to define an |
243 | extra mlog buffer size for variable size data */ |
244 | #define MLOG_BUF_MARGIN 256 |
245 | |
246 | #include "mtr0log.ic" |
247 | |
248 | #endif /* mtr0log_h */ |
249 | |