1/*****************************************************************************
2
3Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc.,
1551 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16
17*****************************************************************************/
18
19/**************************************************//**
20@file include/mtr0log.h
21Mini-transaction logging routines
22
23Created 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
34struct dict_index_t;
35
36/********************************************************//**
37Writes 1, 2 or 4 bytes to a file page. Writes the corresponding log
38record to the mini-transaction log if mtr is not NULL. */
39void
40mlog_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/********************************************************//**
48Writes 8 bytes to a file page. Writes the corresponding log
49record to the mini-transaction log, only if mtr is not NULL */
50void
51mlog_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/********************************************************//**
57Writes a string to a file page buffered in the buffer pool. Writes the
58corresponding log record to the mini-transaction log. */
59void
60mlog_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/********************************************************//**
67Logs a write of a string to a file page buffered in the buffer pool.
68Writes the corresponding log record to the mini-transaction log. */
69void
70mlog_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/********************************************************//**
76Writes initial part of a log record consisting of one-byte item
77type and four-byte space and page numbers. */
78void
79mlog_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/********************************************************//**
87Catenates 1 - 4 bytes to the mtr log. The value is not compressed. */
88UNIV_INLINE
89void
90mlog_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/********************************************************//**
96Catenates 1 - 4 bytes to the mtr log. */
97UNIV_INLINE
98void
99mlog_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/********************************************************//**
105Catenates n bytes to the mtr log. */
106void
107mlog_catenate_string(
108/*=================*/
109 mtr_t* mtr, /*!< in: mtr */
110 const byte* str, /*!< in: string to write */
111 ulint len); /*!< in: string length */
112/********************************************************//**
113Catenates a compressed ulint to mlog. */
114UNIV_INLINE
115void
116mlog_catenate_ulint_compressed(
117/*===========================*/
118 mtr_t* mtr, /*!< in: mtr */
119 ulint val); /*!< in: value to write */
120/********************************************************//**
121Catenates a compressed 64-bit integer to mlog. */
122UNIV_INLINE
123void
124mlog_catenate_ull_compressed(
125/*=========================*/
126 mtr_t* mtr, /*!< in: mtr */
127 ib_uint64_t val); /*!< in: value to write */
128/********************************************************//**
129Opens a buffer to mlog. It must be closed with mlog_close.
130@return buffer, NULL if log mode MTR_LOG_NONE */
131UNIV_INLINE
132byte*
133mlog_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/********************************************************//**
139Closes a buffer opened to mlog. */
140UNIV_INLINE
141void
142mlog_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 */
155UNIV_INLINE
156byte*
157mlog_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/********************************************************//**
165Writes the initial part of a log record (3..11 bytes).
166If the implementation of this function is changed, all
167size parameters to mlog_open() should be adjusted accordingly!
168@return new value of log_ptr */
169UNIV_INLINE
170byte*
171mlog_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/********************************************************//**
181Parses an initial log record written by mlog_write_initial_log_record.
182@return parsed record end, NULL if not a complete record */
183byte*
184mlog_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/********************************************************//**
192Parses a log record written by mlog_write_ulint or mlog_write_ull.
193@return parsed record end, NULL if not a complete record */
194byte*
195mlog_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/********************************************************//**
204Parses a log record written by mlog_write_string.
205@return parsed record end, NULL if not a complete record */
206byte*
207mlog_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/********************************************************//**
215Opens a buffer for mlog, writes the initial log record and,
216if needed, the field lengths of an index. Reserves space
217for further log entries. The log entry must be closed with
218mtr_close().
219@return buffer, NULL if log mode MTR_LOG_NONE */
220byte*
221mlog_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/********************************************************//**
232Parses a log record written by mlog_open_and_write_index.
233@return parsed record end, NULL if not a complete record */
234byte*
235mlog_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
243extra mlog buffer size for variable size data */
244#define MLOG_BUF_MARGIN 256
245
246#include "mtr0log.ic"
247
248#endif /* mtr0log_h */
249