~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/innodb_plugin/include/mtr0mtr.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 1995, 2009, Innobase Oy. 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., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
/**************************************************//**
 
20
@file include/mtr0mtr.h
 
21
Mini-transaction buffer
 
22
 
 
23
Created 11/26/1995 Heikki Tuuri
 
24
*******************************************************/
 
25
 
 
26
#ifndef mtr0mtr_h
 
27
#define mtr0mtr_h
 
28
 
 
29
#include "univ.i"
 
30
#include "mem0mem.h"
 
31
#include "dyn0dyn.h"
 
32
#include "buf0types.h"
 
33
#include "sync0rw.h"
 
34
#include "ut0byte.h"
 
35
#include "mtr0types.h"
 
36
#include "page0types.h"
 
37
 
 
38
/* Logging modes for a mini-transaction */
 
39
#define MTR_LOG_ALL             21      /* default mode: log all operations
 
40
                                        modifying disk-based data */
 
41
#define MTR_LOG_NONE            22      /* log no operations */
 
42
/*#define       MTR_LOG_SPACE   23 */   /* log only operations modifying
 
43
                                        file space page allocation data
 
44
                                        (operations in fsp0fsp.* ) */
 
45
#define MTR_LOG_SHORT_INSERTS   24      /* inserts are logged in a shorter
 
46
                                        form */
 
47
 
 
48
/* Types for the mlock objects to store in the mtr memo; NOTE that the
 
49
first 3 values must be RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
 
50
#define MTR_MEMO_PAGE_S_FIX     RW_S_LATCH
 
51
#define MTR_MEMO_PAGE_X_FIX     RW_X_LATCH
 
52
#define MTR_MEMO_BUF_FIX        RW_NO_LATCH
 
53
#define MTR_MEMO_MODIFY         54
 
54
#define MTR_MEMO_S_LOCK         55
 
55
#define MTR_MEMO_X_LOCK         56
 
56
 
 
57
/** @name Log item types
 
58
The log items are declared 'byte' so that the compiler can warn if val
 
59
and type parameters are switched in a call to mlog_write_ulint. NOTE!
 
60
For 1 - 8 bytes, the flag value must give the length also! @{ */
 
61
#define MLOG_SINGLE_REC_FLAG    128             /*!< if the mtr contains only
 
62
                                                one log record for one page,
 
63
                                                i.e., write_initial_log_record
 
64
                                                has been called only once,
 
65
                                                this flag is ORed to the type
 
66
                                                of that first log record */
 
67
#define MLOG_1BYTE              (1)             /*!< one byte is written */
 
68
#define MLOG_2BYTES             (2)             /*!< 2 bytes ... */
 
69
#define MLOG_4BYTES             (4)             /*!< 4 bytes ... */
 
70
#define MLOG_8BYTES             (8)             /*!< 8 bytes ... */
 
71
#define MLOG_REC_INSERT         ((byte)9)       /*!< record insert */
 
72
#define MLOG_REC_CLUST_DELETE_MARK ((byte)10)   /*!< mark clustered index record
 
73
                                                deleted */
 
74
#define MLOG_REC_SEC_DELETE_MARK ((byte)11)     /*!< mark secondary index record
 
75
                                                deleted */
 
76
#define MLOG_REC_UPDATE_IN_PLACE ((byte)13)     /*!< update of a record,
 
77
                                                preserves record field sizes */
 
78
#define MLOG_REC_DELETE         ((byte)14)      /*!< delete a record from a
 
79
                                                page */
 
80
#define MLOG_LIST_END_DELETE    ((byte)15)      /*!< delete record list end on
 
81
                                                index page */
 
82
#define MLOG_LIST_START_DELETE  ((byte)16)      /*!< delete record list start on
 
83
                                                index page */
 
84
#define MLOG_LIST_END_COPY_CREATED ((byte)17)   /*!< copy record list end to a
 
85
                                                new created index page */
 
86
#define MLOG_PAGE_REORGANIZE    ((byte)18)      /*!< reorganize an
 
87
                                                index page in
 
88
                                                ROW_FORMAT=REDUNDANT */
 
89
#define MLOG_PAGE_CREATE        ((byte)19)      /*!< create an index page */
 
90
#define MLOG_UNDO_INSERT        ((byte)20)      /*!< insert entry in an undo
 
91
                                                log */
 
92
#define MLOG_UNDO_ERASE_END     ((byte)21)      /*!< erase an undo log
 
93
                                                page end */
 
94
#define MLOG_UNDO_INIT          ((byte)22)      /*!< initialize a page in an
 
95
                                                undo log */
 
96
#define MLOG_UNDO_HDR_DISCARD   ((byte)23)      /*!< discard an update undo log
 
97
                                                header */
 
98
#define MLOG_UNDO_HDR_REUSE     ((byte)24)      /*!< reuse an insert undo log
 
99
                                                header */
 
100
#define MLOG_UNDO_HDR_CREATE    ((byte)25)      /*!< create an undo
 
101
                                                log header */
 
102
#define MLOG_REC_MIN_MARK       ((byte)26)      /*!< mark an index
 
103
                                                record as the
 
104
                                                predefined minimum
 
105
                                                record */
 
106
#define MLOG_IBUF_BITMAP_INIT   ((byte)27)      /*!< initialize an
 
107
                                                ibuf bitmap page */
 
108
/*#define       MLOG_FULL_PAGE  ((byte)28)      full contents of a page */
 
109
#ifdef UNIV_LOG_LSN_DEBUG
 
110
# define MLOG_LSN               ((byte)28)      /* current LSN */
 
111
#endif
 
112
#define MLOG_INIT_FILE_PAGE     ((byte)29)      /*!< this means that a
 
113
                                                file page is taken
 
114
                                                into use and the prior
 
115
                                                contents of the page
 
116
                                                should be ignored: in
 
117
                                                recovery we must not
 
118
                                                trust the lsn values
 
119
                                                stored to the file
 
120
                                                page */
 
121
#define MLOG_WRITE_STRING       ((byte)30)      /*!< write a string to
 
122
                                                a page */
 
123
#define MLOG_MULTI_REC_END      ((byte)31)      /*!< if a single mtr writes
 
124
                                                several log records,
 
125
                                                this log record ends the
 
126
                                                sequence of these records */
 
127
#define MLOG_DUMMY_RECORD       ((byte)32)      /*!< dummy log record used to
 
128
                                                pad a log block full */
 
129
#define MLOG_FILE_CREATE        ((byte)33)      /*!< log record about an .ibd
 
130
                                                file creation */
 
131
#define MLOG_FILE_RENAME        ((byte)34)      /*!< log record about an .ibd
 
132
                                                file rename */
 
133
#define MLOG_FILE_DELETE        ((byte)35)      /*!< log record about an .ibd
 
134
                                                file deletion */
 
135
#define MLOG_COMP_REC_MIN_MARK  ((byte)36)      /*!< mark a compact
 
136
                                                index record as the
 
137
                                                predefined minimum
 
138
                                                record */
 
139
#define MLOG_COMP_PAGE_CREATE   ((byte)37)      /*!< create a compact
 
140
                                                index page */
 
141
#define MLOG_COMP_REC_INSERT    ((byte)38)      /*!< compact record insert */
 
142
#define MLOG_COMP_REC_CLUST_DELETE_MARK ((byte)39)
 
143
                                                /*!< mark compact
 
144
                                                clustered index record
 
145
                                                deleted */
 
146
#define MLOG_COMP_REC_SEC_DELETE_MARK ((byte)40)/*!< mark compact
 
147
                                                secondary index record
 
148
                                                deleted; this log
 
149
                                                record type is
 
150
                                                redundant, as
 
151
                                                MLOG_REC_SEC_DELETE_MARK
 
152
                                                is independent of the
 
153
                                                record format. */
 
154
#define MLOG_COMP_REC_UPDATE_IN_PLACE ((byte)41)/*!< update of a
 
155
                                                compact record,
 
156
                                                preserves record field
 
157
                                                sizes */
 
158
#define MLOG_COMP_REC_DELETE    ((byte)42)      /*!< delete a compact record
 
159
                                                from a page */
 
160
#define MLOG_COMP_LIST_END_DELETE ((byte)43)    /*!< delete compact record list
 
161
                                                end on index page */
 
162
#define MLOG_COMP_LIST_START_DELETE ((byte)44)  /*!< delete compact record list
 
163
                                                start on index page */
 
164
#define MLOG_COMP_LIST_END_COPY_CREATED ((byte)45)
 
165
                                                /*!< copy compact
 
166
                                                record list end to a
 
167
                                                new created index
 
168
                                                page */
 
169
#define MLOG_COMP_PAGE_REORGANIZE ((byte)46)    /*!< reorganize an index page */
 
170
#define MLOG_FILE_CREATE2       ((byte)47)      /*!< log record about creating
 
171
                                                an .ibd file, with format */
 
172
#define MLOG_ZIP_WRITE_NODE_PTR ((byte)48)      /*!< write the node pointer of
 
173
                                                a record on a compressed
 
174
                                                non-leaf B-tree page */
 
175
#define MLOG_ZIP_WRITE_BLOB_PTR ((byte)49)      /*!< write the BLOB pointer
 
176
                                                of an externally stored column
 
177
                                                on a compressed page */
 
178
#define MLOG_ZIP_WRITE_HEADER   ((byte)50)      /*!< write to compressed page
 
179
                                                header */
 
180
#define MLOG_ZIP_PAGE_COMPRESS  ((byte)51)      /*!< compress an index page */
 
181
#define MLOG_BIGGEST_TYPE       ((byte)51)      /*!< biggest value (used in
 
182
                                                assertions) */
 
183
/* @} */
 
184
 
 
185
/** @name Flags for MLOG_FILE operations
 
186
(stored in the page number parameter, called log_flags in the
 
187
functions).  The page number parameter was originally written as 0. @{ */
 
188
#define MLOG_FILE_FLAG_TEMP     1       /*!< identifies TEMPORARY TABLE in
 
189
                                        MLOG_FILE_CREATE, MLOG_FILE_CREATE2 */
 
190
/* @} */
 
191
 
 
192
/***************************************************************//**
 
193
Starts a mini-transaction and creates a mini-transaction handle
 
194
and buffer in the memory buffer given by the caller.
 
195
@return mtr buffer which also acts as the mtr handle */
 
196
UNIV_INLINE
 
197
mtr_t*
 
198
mtr_start(
 
199
/*======*/
 
200
        mtr_t*  mtr);   /*!< in: memory buffer for the mtr buffer */
 
201
/***************************************************************//**
 
202
Commits a mini-transaction. */
 
203
UNIV_INTERN
 
204
void
 
205
mtr_commit(
 
206
/*=======*/
 
207
        mtr_t*  mtr);   /*!< in: mini-transaction */
 
208
/**********************************************************//**
 
209
Sets and returns a savepoint in mtr.
 
210
@return savepoint */
 
211
UNIV_INLINE
 
212
ulint
 
213
mtr_set_savepoint(
 
214
/*==============*/
 
215
        mtr_t*  mtr);   /*!< in: mtr */
 
216
/**********************************************************//**
 
217
Releases the latches stored in an mtr memo down to a savepoint.
 
218
NOTE! The mtr must not have made changes to buffer pages after the
 
219
savepoint, as these can be handled only by mtr_commit. */
 
220
UNIV_INTERN
 
221
void
 
222
mtr_rollback_to_savepoint(
 
223
/*======================*/
 
224
        mtr_t*  mtr,            /*!< in: mtr */
 
225
        ulint   savepoint);     /*!< in: savepoint */
 
226
#ifndef UNIV_HOTBACKUP
 
227
/**********************************************************//**
 
228
Releases the (index tree) s-latch stored in an mtr memo after a
 
229
savepoint. */
 
230
UNIV_INLINE
 
231
void
 
232
mtr_release_s_latch_at_savepoint(
 
233
/*=============================*/
 
234
        mtr_t*          mtr,            /*!< in: mtr */
 
235
        ulint           savepoint,      /*!< in: savepoint */
 
236
        rw_lock_t*      lock);          /*!< in: latch to release */
 
237
#else /* !UNIV_HOTBACKUP */
 
238
# define mtr_release_s_latch_at_savepoint(mtr,savepoint,lock) ((void) 0)
 
239
#endif /* !UNIV_HOTBACKUP */
 
240
/***************************************************************//**
 
241
Gets the logging mode of a mini-transaction.
 
242
@return logging mode: MTR_LOG_NONE, ... */
 
243
UNIV_INLINE
 
244
ulint
 
245
mtr_get_log_mode(
 
246
/*=============*/
 
247
        mtr_t*  mtr);   /*!< in: mtr */
 
248
/***************************************************************//**
 
249
Changes the logging mode of a mini-transaction.
 
250
@return old mode */
 
251
UNIV_INLINE
 
252
ulint
 
253
mtr_set_log_mode(
 
254
/*=============*/
 
255
        mtr_t*  mtr,    /*!< in: mtr */
 
256
        ulint   mode);  /*!< in: logging mode: MTR_LOG_NONE, ... */
 
257
/********************************************************//**
 
258
Reads 1 - 4 bytes from a file page buffered in the buffer pool.
 
259
@return value read */
 
260
UNIV_INTERN
 
261
ulint
 
262
mtr_read_ulint(
 
263
/*===========*/
 
264
        const byte*     ptr,    /*!< in: pointer from where to read */
 
265
        ulint           type,   /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
 
266
        mtr_t*          mtr);   /*!< in: mini-transaction handle */
 
267
/********************************************************//**
 
268
Reads 8 bytes from a file page buffered in the buffer pool.
 
269
@return value read */
 
270
UNIV_INTERN
 
271
dulint
 
272
mtr_read_dulint(
 
273
/*============*/
 
274
        const byte*     ptr,    /*!< in: pointer from where to read */
 
275
        mtr_t*          mtr);   /*!< in: mini-transaction handle */
 
276
#ifndef UNIV_HOTBACKUP
 
277
/*********************************************************************//**
 
278
This macro locks an rw-lock in s-mode. */
 
279
#define mtr_s_lock(B, MTR)      mtr_s_lock_func((B), __FILE__, __LINE__,\
 
280
                                                (MTR))
 
281
/*********************************************************************//**
 
282
This macro locks an rw-lock in x-mode. */
 
283
#define mtr_x_lock(B, MTR)      mtr_x_lock_func((B), __FILE__, __LINE__,\
 
284
                                                (MTR))
 
285
/*********************************************************************//**
 
286
NOTE! Use the macro above!
 
287
Locks a lock in s-mode. */
 
288
UNIV_INLINE
 
289
void
 
290
mtr_s_lock_func(
 
291
/*============*/
 
292
        rw_lock_t*      lock,   /*!< in: rw-lock */
 
293
        const char*     file,   /*!< in: file name */
 
294
        ulint           line,   /*!< in: line number */
 
295
        mtr_t*          mtr);   /*!< in: mtr */
 
296
/*********************************************************************//**
 
297
NOTE! Use the macro above!
 
298
Locks a lock in x-mode. */
 
299
UNIV_INLINE
 
300
void
 
301
mtr_x_lock_func(
 
302
/*============*/
 
303
        rw_lock_t*      lock,   /*!< in: rw-lock */
 
304
        const char*     file,   /*!< in: file name */
 
305
        ulint           line,   /*!< in: line number */
 
306
        mtr_t*          mtr);   /*!< in: mtr */
 
307
#endif /* !UNIV_HOTBACKUP */
 
308
 
 
309
/***************************************************//**
 
310
Releases an object in the memo stack. */
 
311
UNIV_INTERN
 
312
void
 
313
mtr_memo_release(
 
314
/*=============*/
 
315
        mtr_t*  mtr,    /*!< in: mtr */
 
316
        void*   object, /*!< in: object */
 
317
        ulint   type);  /*!< in: object type: MTR_MEMO_S_LOCK, ... */
 
318
#ifdef UNIV_DEBUG
 
319
# ifndef UNIV_HOTBACKUP
 
320
/**********************************************************//**
 
321
Checks if memo contains the given item.
 
322
@return TRUE if contains */
 
323
UNIV_INLINE
 
324
ibool
 
325
mtr_memo_contains(
 
326
/*==============*/
 
327
        mtr_t*          mtr,    /*!< in: mtr */
 
328
        const void*     object, /*!< in: object to search */
 
329
        ulint           type);  /*!< in: type of object */
 
330
 
 
331
/**********************************************************//**
 
332
Checks if memo contains the given page.
 
333
@return TRUE if contains */
 
334
UNIV_INTERN
 
335
ibool
 
336
mtr_memo_contains_page(
 
337
/*===================*/
 
338
        mtr_t*          mtr,    /*!< in: mtr */
 
339
        const byte*     ptr,    /*!< in: pointer to buffer frame */
 
340
        ulint           type);  /*!< in: type of object */
 
341
/*********************************************************//**
 
342
Prints info of an mtr handle. */
 
343
UNIV_INTERN
 
344
void
 
345
mtr_print(
 
346
/*======*/
 
347
        mtr_t*  mtr);   /*!< in: mtr */
 
348
# else /* !UNIV_HOTBACKUP */
 
349
#  define mtr_memo_contains(mtr, object, type)          TRUE
 
350
#  define mtr_memo_contains_page(mtr, ptr, type)        TRUE
 
351
# endif /* !UNIV_HOTBACKUP */
 
352
#endif /* UNIV_DEBUG */
 
353
/*######################################################################*/
 
354
 
 
355
#define MTR_BUF_MEMO_SIZE       200     /* number of slots in memo */
 
356
 
 
357
/***************************************************************//**
 
358
Returns the log object of a mini-transaction buffer.
 
359
@return log */
 
360
UNIV_INLINE
 
361
dyn_array_t*
 
362
mtr_get_log(
 
363
/*========*/
 
364
        mtr_t*  mtr);   /*!< in: mini-transaction */
 
365
/***************************************************//**
 
366
Pushes an object to an mtr memo stack. */
 
367
UNIV_INLINE
 
368
void
 
369
mtr_memo_push(
 
370
/*==========*/
 
371
        mtr_t*  mtr,    /*!< in: mtr */
 
372
        void*   object, /*!< in: object */
 
373
        ulint   type);  /*!< in: object type: MTR_MEMO_S_LOCK, ... */
 
374
 
 
375
 
 
376
/* Type definition of a mini-transaction memo stack slot. */
 
377
typedef struct mtr_memo_slot_struct     mtr_memo_slot_t;
 
378
struct mtr_memo_slot_struct{
 
379
        ulint   type;   /*!< type of the stored object (MTR_MEMO_S_LOCK, ...) */
 
380
        void*   object; /*!< pointer to the object */
 
381
};
 
382
 
 
383
/* Mini-transaction handle and buffer */
 
384
struct mtr_struct{
 
385
#ifdef UNIV_DEBUG
 
386
        ulint           state;  /*!< MTR_ACTIVE, MTR_COMMITTING, MTR_COMMITTED */
 
387
#endif
 
388
        dyn_array_t     memo;   /*!< memo stack for locks etc. */
 
389
        dyn_array_t     log;    /*!< mini-transaction log */
 
390
        ibool           modifications;
 
391
                                /* TRUE if the mtr made modifications to
 
392
                                buffer pool pages */
 
393
        ulint           n_log_recs;
 
394
                                /* count of how many page initial log records
 
395
                                have been written to the mtr log */
 
396
        ulint           log_mode; /* specifies which operations should be
 
397
                                logged; default value MTR_LOG_ALL */
 
398
        ib_uint64_t     start_lsn;/* start lsn of the possible log entry for
 
399
                                this mtr */
 
400
        ib_uint64_t     end_lsn;/* end lsn of the possible log entry for
 
401
                                this mtr */
 
402
#ifdef UNIV_DEBUG
 
403
        ulint           magic_n;
 
404
#endif /* UNIV_DEBUG */
 
405
};
 
406
 
 
407
#ifdef UNIV_DEBUG
 
408
# define MTR_MAGIC_N            54551
 
409
#endif /* UNIV_DEBUG */
 
410
 
 
411
#define MTR_ACTIVE              12231
 
412
#define MTR_COMMITTING          56456
 
413
#define MTR_COMMITTED           34676
 
414
 
 
415
#ifndef UNIV_NONINL
 
416
#include "mtr0mtr.ic"
 
417
#endif
 
418
 
 
419
#endif