~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/innobase/include/mtr0mtr.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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
#define MLOG_INIT_FILE_PAGE     ((byte)29)      /*!< this means that a
 
110
                                                file page is taken
 
111
                                                into use and the prior
 
112
                                                contents of the page
 
113
                                                should be ignored: in
 
114
                                                recovery we must not
 
115
                                                trust the lsn values
 
116
                                                stored to the file
 
117
                                                page */
 
118
#define MLOG_WRITE_STRING       ((byte)30)      /*!< write a string to
 
119
                                                a page */
 
120
#define MLOG_MULTI_REC_END      ((byte)31)      /*!< if a single mtr writes
 
121
                                                log records for several pages,
 
122
                                                this log record ends the
 
123
                                                sequence of these records */
 
124
#define MLOG_DUMMY_RECORD       ((byte)32)      /*!< dummy log record used to
 
125
                                                pad a log block full */
 
126
#define MLOG_FILE_CREATE        ((byte)33)      /*!< log record about an .ibd
 
127
                                                file creation */
 
128
#define MLOG_FILE_RENAME        ((byte)34)      /*!< log record about an .ibd
 
129
                                                file rename */
 
130
#define MLOG_FILE_DELETE        ((byte)35)      /*!< log record about an .ibd
 
131
                                                file deletion */
 
132
#define MLOG_COMP_REC_MIN_MARK  ((byte)36)      /*!< mark a compact
 
133
                                                index record as the
 
134
                                                predefined minimum
 
135
                                                record */
 
136
#define MLOG_COMP_PAGE_CREATE   ((byte)37)      /*!< create a compact
 
137
                                                index page */
 
138
#define MLOG_COMP_REC_INSERT    ((byte)38)      /*!< compact record insert */
 
139
#define MLOG_COMP_REC_CLUST_DELETE_MARK ((byte)39)
 
140
                                                /*!< mark compact
 
141
                                                clustered index record
 
142
                                                deleted */
 
143
#define MLOG_COMP_REC_SEC_DELETE_MARK ((byte)40)/*!< mark compact
 
144
                                                secondary index record
 
145
                                                deleted; this log
 
146
                                                record type is
 
147
                                                redundant, as
 
148
                                                MLOG_REC_SEC_DELETE_MARK
 
149
                                                is independent of the
 
150
                                                record format. */
 
151
#define MLOG_COMP_REC_UPDATE_IN_PLACE ((byte)41)/*!< update of a
 
152
                                                compact record,
 
153
                                                preserves record field
 
154
                                                sizes */
 
155
#define MLOG_COMP_REC_DELETE    ((byte)42)      /*!< delete a compact record
 
156
                                                from a page */
 
157
#define MLOG_COMP_LIST_END_DELETE ((byte)43)    /*!< delete compact record list
 
158
                                                end on index page */
 
159
#define MLOG_COMP_LIST_START_DELETE ((byte)44)  /*!< delete compact record list
 
160
                                                start on index page */
 
161
#define MLOG_COMP_LIST_END_COPY_CREATED ((byte)45)
 
162
                                                /*!< copy compact
 
163
                                                record list end to a
 
164
                                                new created index
 
165
                                                page */
 
166
#define MLOG_COMP_PAGE_REORGANIZE ((byte)46)    /*!< reorganize an index page */
 
167
#define MLOG_FILE_CREATE2       ((byte)47)      /*!< log record about creating
 
168
                                                an .ibd file, with format */
 
169
#define MLOG_ZIP_WRITE_NODE_PTR ((byte)48)      /*!< write the node pointer of
 
170
                                                a record on a compressed
 
171
                                                non-leaf B-tree page */
 
172
#define MLOG_ZIP_WRITE_BLOB_PTR ((byte)49)      /*!< write the BLOB pointer
 
173
                                                of an externally stored column
 
174
                                                on a compressed page */
 
175
#define MLOG_ZIP_WRITE_HEADER   ((byte)50)      /*!< write to compressed page
 
176
                                                header */
 
177
#define MLOG_ZIP_PAGE_COMPRESS  ((byte)51)      /*!< compress an index page */
 
178
#define MLOG_BIGGEST_TYPE       ((byte)51)      /*!< biggest value (used in
 
179
                                                assertions) */
 
180
/* @} */
 
181
 
 
182
/** @name Flags for MLOG_FILE operations
 
183
(stored in the page number parameter, called log_flags in the
 
184
functions).  The page number parameter was originally written as 0. @{ */
 
185
#define MLOG_FILE_FLAG_TEMP     1       /*!< identifies TEMPORARY TABLE in
 
186
                                        MLOG_FILE_CREATE, MLOG_FILE_CREATE2 */
 
187
/* @} */
 
188
 
 
189
/***************************************************************//**
 
190
Starts a mini-transaction and creates a mini-transaction handle
 
191
and buffer in the memory buffer given by the caller.
 
192
@return mtr buffer which also acts as the mtr handle */
 
193
UNIV_INLINE
 
194
mtr_t*
 
195
mtr_start(
 
196
/*======*/
 
197
        mtr_t*  mtr);   /*!< in: memory buffer for the mtr buffer */
 
198
/***************************************************************//**
 
199
Commits a mini-transaction. */
 
200
UNIV_INTERN
 
201
void
 
202
mtr_commit(
 
203
/*=======*/
 
204
        mtr_t*  mtr);   /*!< in: mini-transaction */
 
205
/**********************************************************//**
 
206
Sets and returns a savepoint in mtr.
 
207
@return savepoint */
 
208
UNIV_INLINE
 
209
ulint
 
210
mtr_set_savepoint(
 
211
/*==============*/
 
212
        mtr_t*  mtr);   /*!< in: mtr */
 
213
/**********************************************************//**
 
214
Releases the latches stored in an mtr memo down to a savepoint.
 
215
NOTE! The mtr must not have made changes to buffer pages after the
 
216
savepoint, as these can be handled only by mtr_commit. */
 
217
UNIV_INTERN
 
218
void
 
219
mtr_rollback_to_savepoint(
 
220
/*======================*/
 
221
        mtr_t*  mtr,            /*!< in: mtr */
 
222
        ulint   savepoint);     /*!< in: savepoint */
 
223
#ifndef UNIV_HOTBACKUP
 
224
/**********************************************************//**
 
225
Releases the (index tree) s-latch stored in an mtr memo after a
 
226
savepoint. */
 
227
UNIV_INLINE
 
228
void
 
229
mtr_release_s_latch_at_savepoint(
 
230
/*=============================*/
 
231
        mtr_t*          mtr,            /*!< in: mtr */
 
232
        ulint           savepoint,      /*!< in: savepoint */
 
233
        rw_lock_t*      lock);          /*!< in: latch to release */
 
234
#else /* !UNIV_HOTBACKUP */
 
235
# define mtr_release_s_latch_at_savepoint(mtr,savepoint,lock) ((void) 0)
 
236
#endif /* !UNIV_HOTBACKUP */
 
237
/***************************************************************//**
 
238
Gets the logging mode of a mini-transaction.
 
239
@return logging mode: MTR_LOG_NONE, ... */
 
240
UNIV_INLINE
 
241
ulint
 
242
mtr_get_log_mode(
 
243
/*=============*/
 
244
        mtr_t*  mtr);   /*!< in: mtr */
 
245
/***************************************************************//**
 
246
Changes the logging mode of a mini-transaction.
 
247
@return old mode */
 
248
UNIV_INLINE
 
249
ulint
 
250
mtr_set_log_mode(
 
251
/*=============*/
 
252
        mtr_t*  mtr,    /*!< in: mtr */
 
253
        ulint   mode);  /*!< in: logging mode: MTR_LOG_NONE, ... */
 
254
/********************************************************//**
 
255
Reads 1 - 4 bytes from a file page buffered in the buffer pool.
 
256
@return value read */
 
257
UNIV_INTERN
 
258
ulint
 
259
mtr_read_ulint(
 
260
/*===========*/
 
261
        const byte*     ptr,    /*!< in: pointer from where to read */
 
262
        ulint           type,   /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
 
263
        mtr_t*          mtr);   /*!< in: mini-transaction handle */
 
264
/********************************************************//**
 
265
Reads 8 bytes from a file page buffered in the buffer pool.
 
266
@return value read */
 
267
UNIV_INTERN
 
268
dulint
 
269
mtr_read_dulint(
 
270
/*============*/
 
271
        const byte*     ptr,    /*!< in: pointer from where to read */
 
272
        mtr_t*          mtr);   /*!< in: mini-transaction handle */
 
273
#ifndef UNIV_HOTBACKUP
 
274
/*********************************************************************//**
 
275
This macro locks an rw-lock in s-mode. */
 
276
#define mtr_s_lock(B, MTR)      mtr_s_lock_func((B), __FILE__, __LINE__,\
 
277
                                                (MTR))
 
278
/*********************************************************************//**
 
279
This macro locks an rw-lock in x-mode. */
 
280
#define mtr_x_lock(B, MTR)      mtr_x_lock_func((B), __FILE__, __LINE__,\
 
281
                                                (MTR))
 
282
/*********************************************************************//**
 
283
NOTE! Use the macro above!
 
284
Locks a lock in s-mode. */
 
285
UNIV_INLINE
 
286
void
 
287
mtr_s_lock_func(
 
288
/*============*/
 
289
        rw_lock_t*      lock,   /*!< in: rw-lock */
 
290
        const char*     file,   /*!< in: file name */
 
291
        ulint           line,   /*!< in: line number */
 
292
        mtr_t*          mtr);   /*!< in: mtr */
 
293
/*********************************************************************//**
 
294
NOTE! Use the macro above!
 
295
Locks a lock in x-mode. */
 
296
UNIV_INLINE
 
297
void
 
298
mtr_x_lock_func(
 
299
/*============*/
 
300
        rw_lock_t*      lock,   /*!< in: rw-lock */
 
301
        const char*     file,   /*!< in: file name */
 
302
        ulint           line,   /*!< in: line number */
 
303
        mtr_t*          mtr);   /*!< in: mtr */
 
304
#endif /* !UNIV_HOTBACKUP */
 
305
 
 
306
/***************************************************//**
 
307
Releases an object in the memo stack. */
 
308
UNIV_INTERN
 
309
void
 
310
mtr_memo_release(
 
311
/*=============*/
 
312
        mtr_t*  mtr,    /*!< in: mtr */
 
313
        void*   object, /*!< in: object */
 
314
        ulint   type);  /*!< in: object type: MTR_MEMO_S_LOCK, ... */
 
315
#ifdef UNIV_DEBUG
 
316
# ifndef UNIV_HOTBACKUP
 
317
/**********************************************************//**
 
318
Checks if memo contains the given item.
 
319
@return TRUE if contains */
 
320
UNIV_INLINE
 
321
ibool
 
322
mtr_memo_contains(
 
323
/*==============*/
 
324
        mtr_t*          mtr,    /*!< in: mtr */
 
325
        const void*     object, /*!< in: object to search */
 
326
        ulint           type);  /*!< in: type of object */
 
327
 
 
328
/**********************************************************//**
 
329
Checks if memo contains the given page.
 
330
@return TRUE if contains */
 
331
UNIV_INTERN
 
332
ibool
 
333
mtr_memo_contains_page(
 
334
/*===================*/
 
335
        mtr_t*          mtr,    /*!< in: mtr */
 
336
        const byte*     ptr,    /*!< in: pointer to buffer frame */
 
337
        ulint           type);  /*!< in: type of object */
 
338
/*********************************************************//**
 
339
Prints info of an mtr handle. */
 
340
UNIV_INTERN
 
341
void
 
342
mtr_print(
 
343
/*======*/
 
344
        mtr_t*  mtr);   /*!< in: mtr */
 
345
# else /* !UNIV_HOTBACKUP */
 
346
#  define mtr_memo_contains(mtr, object, type)          TRUE
 
347
#  define mtr_memo_contains_page(mtr, ptr, type)        TRUE
 
348
# endif /* !UNIV_HOTBACKUP */
 
349
#endif /* UNIV_DEBUG */
 
350
/*######################################################################*/
 
351
 
 
352
#define MTR_BUF_MEMO_SIZE       200     /* number of slots in memo */
 
353
 
 
354
/***************************************************************//**
 
355
Returns the log object of a mini-transaction buffer.
 
356
@return log */
 
357
UNIV_INLINE
 
358
dyn_array_t*
 
359
mtr_get_log(
 
360
/*========*/
 
361
        mtr_t*  mtr);   /*!< in: mini-transaction */
 
362
/***************************************************//**
 
363
Pushes an object to an mtr memo stack. */
 
364
UNIV_INLINE
 
365
void
 
366
mtr_memo_push(
 
367
/*==========*/
 
368
        mtr_t*  mtr,    /*!< in: mtr */
 
369
        void*   object, /*!< in: object */
 
370
        ulint   type);  /*!< in: object type: MTR_MEMO_S_LOCK, ... */
 
371
 
 
372
 
 
373
/* Type definition of a mini-transaction memo stack slot. */
 
374
typedef struct mtr_memo_slot_struct     mtr_memo_slot_t;
 
375
struct mtr_memo_slot_struct{
 
376
        ulint   type;   /*!< type of the stored object (MTR_MEMO_S_LOCK, ...) */
 
377
        void*   object; /*!< pointer to the object */
 
378
};
 
379
 
 
380
/* Mini-transaction handle and buffer */
 
381
struct mtr_struct{
 
382
#ifdef UNIV_DEBUG
 
383
        ulint           state;  /*!< MTR_ACTIVE, MTR_COMMITTING, MTR_COMMITTED */
 
384
#endif
 
385
        dyn_array_t     memo;   /*!< memo stack for locks etc. */
 
386
        dyn_array_t     log;    /*!< mini-transaction log */
 
387
        ibool           modifications;
 
388
                                /* TRUE if the mtr made modifications to
 
389
                                buffer pool pages */
 
390
        ulint           n_log_recs;
 
391
                                /* count of how many page initial log records
 
392
                                have been written to the mtr log */
 
393
        ulint           log_mode; /* specifies which operations should be
 
394
                                logged; default value MTR_LOG_ALL */
 
395
        ib_uint64_t     start_lsn;/* start lsn of the possible log entry for
 
396
                                this mtr */
 
397
        ib_uint64_t     end_lsn;/* end lsn of the possible log entry for
 
398
                                this mtr */
 
399
#ifdef UNIV_DEBUG
 
400
        ulint           magic_n;
 
401
#endif /* UNIV_DEBUG */
 
402
};
 
403
 
 
404
#ifdef UNIV_DEBUG
 
405
# define MTR_MAGIC_N            54551
 
406
#endif /* UNIV_DEBUG */
 
407
 
 
408
#define MTR_ACTIVE              12231
 
409
#define MTR_COMMITTING          56456
 
410
#define MTR_COMMITTED           34676
 
411
 
 
412
#ifndef UNIV_NONINL
 
413
#include "mtr0mtr.ic"
 
414
#endif
 
415
 
 
416
#endif