1
/*****************************************************************************
3
Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved.
4
Copyright (c) 2012, Facebook Inc.
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.
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.
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
18
*****************************************************************************/
20
/**************************************************//**
21
@file include/mtr0mtr.h
22
Mini-transaction buffer
24
Created 11/26/1995 Heikki Tuuri
25
*******************************************************/
33
#include "buf0types.h"
36
#include "mtr0types.h"
37
#include "page0types.h"
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
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
56
# define MTR_MEMO_MODIFY 54
57
#endif /* UNIV_DEBUG */
58
#define MTR_MEMO_S_LOCK 55
59
#define MTR_MEMO_X_LOCK 56
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
78
#define MLOG_REC_SEC_DELETE_MARK ((byte)11) /*!< mark secondary index record
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
84
#define MLOG_LIST_END_DELETE ((byte)15) /*!< delete record list end on
86
#define MLOG_LIST_START_DELETE ((byte)16) /*!< delete record list start on
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
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
96
#define MLOG_UNDO_ERASE_END ((byte)21) /*!< erase an undo log
98
#define MLOG_UNDO_INIT ((byte)22) /*!< initialize a page in an
100
#define MLOG_UNDO_HDR_DISCARD ((byte)23) /*!< discard an update undo log
102
#define MLOG_UNDO_HDR_REUSE ((byte)24) /*!< reuse an insert undo log
104
#define MLOG_UNDO_HDR_CREATE ((byte)25) /*!< create an undo
106
#define MLOG_REC_MIN_MARK ((byte)26) /*!< mark an index
110
#define MLOG_IBUF_BITMAP_INIT ((byte)27) /*!< initialize an
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 */
116
#define MLOG_INIT_FILE_PAGE ((byte)29) /*!< this means that a
118
into use and the prior
120
should be ignored: in
125
#define MLOG_WRITE_STRING ((byte)30) /*!< write a string to
127
#define MLOG_MULTI_REC_END ((byte)31) /*!< if a single mtr writes
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
135
#define MLOG_FILE_RENAME ((byte)34) /*!< log record about an .ibd
137
#define MLOG_FILE_DELETE ((byte)35) /*!< log record about an .ibd
139
#define MLOG_COMP_REC_MIN_MARK ((byte)36) /*!< mark a compact
143
#define MLOG_COMP_PAGE_CREATE ((byte)37) /*!< create a compact
145
#define MLOG_COMP_REC_INSERT ((byte)38) /*!< compact record insert */
146
#define MLOG_COMP_REC_CLUST_DELETE_MARK ((byte)39)
148
clustered index record
150
#define MLOG_COMP_REC_SEC_DELETE_MARK ((byte)40)/*!< mark compact
151
secondary index record
155
MLOG_REC_SEC_DELETE_MARK
156
is independent of the
158
#define MLOG_COMP_REC_UPDATE_IN_PLACE ((byte)41)/*!< update of a
160
preserves record field
162
#define MLOG_COMP_REC_DELETE ((byte)42) /*!< delete a compact record
164
#define MLOG_COMP_LIST_END_DELETE ((byte)43) /*!< delete compact record list
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)
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
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
189
#define MLOG_BIGGEST_TYPE ((byte)53) /*!< biggest value (used in
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 */
200
/* included here because it needs MLOG_LSN defined */
203
/***************************************************************//**
204
Starts a mini-transaction. */
209
mtr_t* mtr) /*!< out: mini-transaction */
210
__attribute__((nonnull));
211
/***************************************************************//**
212
Commits a mini-transaction. */
217
mtr_t* mtr) /*!< in/out: mini-transaction */
218
__attribute__((nonnull));
219
/**********************************************************//**
220
Sets and returns a savepoint in mtr.
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
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, ... */
248
mtr_t* mtr); /*!< in: mtr */
249
/***************************************************************//**
250
Changes the logging mode of a mini-transaction.
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 */
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__,\
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__,\
277
/*********************************************************************//**
278
NOTE! Use the macro above!
279
Locks a lock in s-mode. */
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. */
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 */
301
/***************************************************//**
302
Releases an object in the memo stack.
303
@return true if released */
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));
313
# ifndef UNIV_HOTBACKUP
314
/**********************************************************//**
315
Checks if memo contains the given item.
316
@return TRUE if contains */
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));
326
/**********************************************************//**
327
Checks if memo contains the given page.
328
@return TRUE if contains */
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. */
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
/*######################################################################*/
350
#define MTR_BUF_MEMO_SIZE 200 /* number of slots in memo */
352
/***************************************************************//**
353
Returns the log object of a mini-transaction buffer.
359
mtr_t* mtr); /*!< in: mini-transaction */
360
/***************************************************//**
361
Pushes an object to an mtr memo stack. */
366
mtr_t* mtr, /*!< in: mtr */
367
void* object, /*!< in: object */
368
ulint type); /*!< in: object type: MTR_MEMO_S_LOCK, ... */
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 */
376
/* Mini-transaction handle and buffer */
379
ulint state; /*!< MTR_ACTIVE, MTR_COMMITTING, MTR_COMMITTED */
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 */
392
/* count of how many page initial log records
393
have been written to the mtr log */
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
401
lsn_t end_lsn;/* end lsn of the possible log entry for
405
#endif /* UNIV_DEBUG */
409
# define MTR_MAGIC_N 54551
410
#endif /* UNIV_DEBUG */
412
#define MTR_ACTIVE 12231
413
#define MTR_COMMITTING 56456
414
#define MTR_COMMITTED 34676
417
#include "mtr0mtr.ic"