mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innodb_plugin / include / mtr0log.ic
blob87d43032ed92dc832a1546d8b553154eb8d55511
1 /*****************************************************************************
3 Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
17 *****************************************************************************/
19 /**************************************************//**
20 @file include/mtr0log.ic
21 Mini-transaction logging routines
23 Created 12/7/1995 Heikki Tuuri
24 *******************************************************/
26 #include "mach0data.h"
27 #include "ut0lst.h"
28 #include "buf0buf.h"
29 #include "fsp0types.h"
30 #include "trx0sys.h"
32 /********************************************************//**
33 Opens a buffer to mlog. It must be closed with mlog_close.
34 @return buffer, NULL if log mode MTR_LOG_NONE */
35 UNIV_INLINE
36 byte*
37 mlog_open(
38 /*======*/
39         mtr_t*  mtr,    /*!< in: mtr */
40         ulint   size)   /*!< in: buffer size in bytes; MUST be
41                         smaller than DYN_ARRAY_DATA_SIZE! */
43         dyn_array_t*    mlog;
45         mtr->modifications = TRUE;
47         if (mtr_get_log_mode(mtr) == MTR_LOG_NONE) {
49                 return(NULL);
50         }
52         mlog = &(mtr->log);
54         return(dyn_array_open(mlog, size));
57 /********************************************************//**
58 Closes a buffer opened to mlog. */
59 UNIV_INLINE
60 void
61 mlog_close(
62 /*=======*/
63         mtr_t*  mtr,    /*!< in: mtr */
64         byte*   ptr)    /*!< in: buffer space from ptr up was not used */
66         dyn_array_t*    mlog;
68         ut_ad(mtr_get_log_mode(mtr) != MTR_LOG_NONE);
70         mlog = &(mtr->log);
72         dyn_array_close(mlog, ptr);
75 #ifndef UNIV_HOTBACKUP
76 /********************************************************//**
77 Catenates 1 - 4 bytes to the mtr log. The value is not compressed. */
78 UNIV_INLINE
79 void
80 mlog_catenate_ulint(
81 /*================*/
82         mtr_t*  mtr,    /*!< in: mtr */
83         ulint   val,    /*!< in: value to write */
84         ulint   type)   /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
86         dyn_array_t*    mlog;
87         byte*           ptr;
89         if (mtr_get_log_mode(mtr) == MTR_LOG_NONE) {
91                 return;
92         }
94         mlog = &(mtr->log);
96 #if MLOG_1BYTE != 1
97 # error "MLOG_1BYTE != 1"
98 #endif
99 #if MLOG_2BYTES != 2
100 # error "MLOG_2BYTES != 2"
101 #endif
102 #if MLOG_4BYTES != 4
103 # error "MLOG_4BYTES != 4"
104 #endif
105 #if MLOG_8BYTES != 8
106 # error "MLOG_8BYTES != 8"
107 #endif
108         ptr = (byte*) dyn_array_push(mlog, type);
110         if (type == MLOG_4BYTES) {
111                 mach_write_to_4(ptr, val);
112         } else if (type == MLOG_2BYTES) {
113                 mach_write_to_2(ptr, val);
114         } else {
115                 ut_ad(type == MLOG_1BYTE);
116                 mach_write_to_1(ptr, val);
117         }
120 /********************************************************//**
121 Catenates a compressed ulint to mlog. */
122 UNIV_INLINE
123 void
124 mlog_catenate_ulint_compressed(
125 /*===========================*/
126         mtr_t*  mtr,    /*!< in: mtr */
127         ulint   val)    /*!< in: value to write */
129         byte*   log_ptr;
131         log_ptr = mlog_open(mtr, 10);
133         /* If no logging is requested, we may return now */
134         if (log_ptr == NULL) {
136                 return;
137         }
139         log_ptr += mach_write_compressed(log_ptr, val);
141         mlog_close(mtr, log_ptr);
144 /********************************************************//**
145 Catenates a compressed dulint to mlog. */
146 UNIV_INLINE
147 void
148 mlog_catenate_dulint_compressed(
149 /*============================*/
150         mtr_t*  mtr,    /*!< in: mtr */
151         dulint  val)    /*!< in: value to write */
153         byte*   log_ptr;
155         log_ptr = mlog_open(mtr, 15);
157         /* If no logging is requested, we may return now */
158         if (log_ptr == NULL) {
160                 return;
161         }
163         log_ptr += mach_dulint_write_compressed(log_ptr, val);
165         mlog_close(mtr, log_ptr);
168 /********************************************************//**
169 Writes the initial part of a log record (3..11 bytes).
170 If the implementation of this function is changed, all
171 size parameters to mlog_open() should be adjusted accordingly!
172 @return new value of log_ptr */
173 UNIV_INLINE
174 byte*
175 mlog_write_initial_log_record_fast(
176 /*===============================*/
177         const byte*     ptr,    /*!< in: pointer to (inside) a buffer
178                                 frame holding the file page where
179                                 modification is made */
180         byte            type,   /*!< in: log item type: MLOG_1BYTE, ... */
181         byte*           log_ptr,/*!< in: pointer to mtr log which has
182                                 been opened */
183         mtr_t*          mtr)    /*!< in: mtr */
185 #ifdef UNIV_DEBUG
186         buf_block_t*    block;
187 #endif
188         const byte*     page;
189         ulint           space;
190         ulint           offset;
192         ut_ad(mtr_memo_contains_page(mtr, ptr, MTR_MEMO_PAGE_X_FIX));
193         ut_ad(type <= MLOG_BIGGEST_TYPE);
194         ut_ad(ptr && log_ptr);
196         page = (const byte*) ut_align_down(ptr, UNIV_PAGE_SIZE);
197         space = mach_read_from_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
198         offset = mach_read_from_4(page + FIL_PAGE_OFFSET);
200         /* check whether the page is in the doublewrite buffer;
201         the doublewrite buffer is located in pages
202         FSP_EXTENT_SIZE, ..., 3 * FSP_EXTENT_SIZE - 1 in the
203         system tablespace */
204         if (space == TRX_SYS_SPACE
205             && offset >= FSP_EXTENT_SIZE && offset < 3 * FSP_EXTENT_SIZE) {
206                 if (trx_doublewrite_buf_is_being_created) {
207                         /* Do nothing: we only come to this branch in an
208                         InnoDB database creation. We do not redo log
209                         anything for the doublewrite buffer pages. */
210                         return(log_ptr);
211                 } else {
212                         fprintf(stderr,
213                                 "Error: trying to redo log a record of type "
214                                 "%d on page %lu of space %lu in the "
215                                 "doublewrite buffer, continuing anyway.\n"
216                                 "Please post a bug report to "
217                                 "bugs.mysql.com.\n",
218                                 type, offset, space);
219                 }
220         }
222         mach_write_to_1(log_ptr, type);
223         log_ptr++;
224         log_ptr += mach_write_compressed(log_ptr, space);
225         log_ptr += mach_write_compressed(log_ptr, offset);
227         mtr->n_log_recs++;
229 #ifdef UNIV_LOG_DEBUG
230         fprintf(stderr,
231                 "Adding to mtr log record type %lu space %lu page no %lu\n",
232                 (ulong) type, space, offset);
233 #endif
235 #ifdef UNIV_DEBUG
236         /* We now assume that all x-latched pages have been modified! */
237         block = (buf_block_t*) buf_block_align(ptr);
239         if (!mtr_memo_contains(mtr, block, MTR_MEMO_MODIFY)) {
241                 mtr_memo_push(mtr, block, MTR_MEMO_MODIFY);
242         }
243 #endif
244         return(log_ptr);
247 /********************************************************//**
248 Writes a log record about an .ibd file create/delete/rename.
249 @return new value of log_ptr */
250 UNIV_INLINE
251 byte*
252 mlog_write_initial_log_record_for_file_op(
253 /*======================================*/
254         ulint   type,   /*!< in: MLOG_FILE_CREATE, MLOG_FILE_DELETE, or
255                         MLOG_FILE_RENAME */
256         ulint   space_id,/*!< in: space id, if applicable */
257         ulint   page_no,/*!< in: page number (not relevant currently) */
258         byte*   log_ptr,/*!< in: pointer to mtr log which has been opened */
259         mtr_t*  mtr)    /*!< in: mtr */
261         ut_ad(log_ptr);
263         mach_write_to_1(log_ptr, type);
264         log_ptr++;
266         /* We write dummy space id and page number */
267         log_ptr += mach_write_compressed(log_ptr, space_id);
268         log_ptr += mach_write_compressed(log_ptr, page_no);
270         mtr->n_log_recs++;
272         return(log_ptr);
274 #endif /* !UNIV_HOTBACKUP */