~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

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