1
/*****************************************************************************
3
Copyright (C) 1995, 2010, 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., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/mtr0mtr.ic
21
Mini-transaction buffer
23
Created 11/26/1995 Heikki Tuuri
24
*******************************************************/
26
#ifndef UNIV_HOTBACKUP
27
# include "sync0sync.h"
29
#endif /* !UNIV_HOTBACKUP */
30
#include "mach0data.h"
32
/***************************************************************//**
33
Starts a mini-transaction and creates a mini-transaction handle
34
and a buffer in the memory buffer given by the caller.
35
@return mtr buffer which also acts as the mtr handle */
40
mtr_t* mtr) /*!< in: memory buffer for the mtr buffer */
42
dyn_array_create(&(mtr->memo));
43
dyn_array_create(&(mtr->log));
45
mtr->log_mode = MTR_LOG_ALL;
46
mtr->modifications = FALSE;
49
ut_d(mtr->state = MTR_ACTIVE);
50
ut_d(mtr->magic_n = MTR_MAGIC_N);
55
/***************************************************//**
56
Pushes an object to an mtr memo stack. */
61
mtr_t* mtr, /*!< in: mtr */
62
void* object, /*!< in: object */
63
ulint type) /*!< in: object type: MTR_MEMO_S_LOCK, ... */
66
mtr_memo_slot_t* slot;
69
ut_ad(type >= MTR_MEMO_PAGE_S_FIX);
70
ut_ad(type <= MTR_MEMO_X_LOCK);
72
ut_ad(mtr->magic_n == MTR_MAGIC_N);
73
ut_ad(mtr->state == MTR_ACTIVE);
77
slot = (mtr_memo_slot_t*) dyn_array_push(memo, sizeof *slot);
79
slot->object = object;
83
/**********************************************************//**
84
Sets and returns a savepoint in mtr.
90
mtr_t* mtr) /*!< in: mtr */
95
ut_ad(mtr->magic_n == MTR_MAGIC_N);
96
ut_ad(mtr->state == MTR_ACTIVE);
100
return(dyn_array_get_data_size(memo));
103
#ifndef UNIV_HOTBACKUP
104
/**********************************************************//**
105
Releases the (index tree) s-latch stored in an mtr memo after a
109
mtr_release_s_latch_at_savepoint(
110
/*=============================*/
111
mtr_t* mtr, /*!< in: mtr */
112
ulint savepoint, /*!< in: savepoint */
113
rw_lock_t* lock) /*!< in: latch to release */
115
mtr_memo_slot_t* slot;
119
ut_ad(mtr->magic_n == MTR_MAGIC_N);
120
ut_ad(mtr->state == MTR_ACTIVE);
124
ut_ad(dyn_array_get_data_size(memo) > savepoint);
126
slot = (mtr_memo_slot_t*) dyn_array_get_element(memo, savepoint);
128
ut_ad(slot->object == lock);
129
ut_ad(slot->type == MTR_MEMO_S_LOCK);
131
rw_lock_s_unlock(lock);
137
/**********************************************************//**
138
Checks if memo contains the given item.
139
@return TRUE if contains */
144
mtr_t* mtr, /*!< in: mtr */
145
const void* object, /*!< in: object to search */
146
ulint type) /*!< in: type of object */
148
mtr_memo_slot_t* slot;
153
ut_ad(mtr->magic_n == MTR_MAGIC_N);
154
ut_ad(mtr->state == MTR_ACTIVE || mtr->state == MTR_COMMITTING);
158
offset = dyn_array_get_data_size(memo);
161
offset -= sizeof(mtr_memo_slot_t);
163
slot = dyn_array_get_element(memo, offset);
165
if ((object == slot->object) && (type == slot->type)) {
173
# endif /* UNIV_DEBUG */
174
#endif /* !UNIV_HOTBACKUP */
176
/***************************************************************//**
177
Returns the log object of a mini-transaction buffer.
183
mtr_t* mtr) /*!< in: mini-transaction */
186
ut_ad(mtr->magic_n == MTR_MAGIC_N);
191
/***************************************************************//**
192
Gets the logging mode of a mini-transaction.
193
@return logging mode: MTR_LOG_NONE, ... */
198
mtr_t* mtr) /*!< in: mtr */
201
ut_ad(mtr->log_mode >= MTR_LOG_ALL);
202
ut_ad(mtr->log_mode <= MTR_LOG_SHORT_INSERTS);
204
return(mtr->log_mode);
207
/***************************************************************//**
208
Changes the logging mode of a mini-transaction.
214
mtr_t* mtr, /*!< in: mtr */
215
ulint mode) /*!< in: logging mode: MTR_LOG_NONE, ... */
220
ut_ad(mode >= MTR_LOG_ALL);
221
ut_ad(mode <= MTR_LOG_SHORT_INSERTS);
223
old_mode = mtr->log_mode;
225
if ((mode == MTR_LOG_SHORT_INSERTS) && (old_mode == MTR_LOG_NONE)) {
228
mtr->log_mode = mode;
231
ut_ad(old_mode >= MTR_LOG_ALL);
232
ut_ad(old_mode <= MTR_LOG_SHORT_INSERTS);
237
#ifndef UNIV_HOTBACKUP
238
/*********************************************************************//**
239
Locks a lock in s-mode. */
244
rw_lock_t* lock, /*!< in: rw-lock */
245
const char* file, /*!< in: file name */
246
ulint line, /*!< in: line number */
247
mtr_t* mtr) /*!< in: mtr */
252
rw_lock_s_lock_func(lock, 0, file, line);
254
mtr_memo_push(mtr, lock, MTR_MEMO_S_LOCK);
257
/*********************************************************************//**
258
Locks a lock in x-mode. */
263
rw_lock_t* lock, /*!< in: rw-lock */
264
const char* file, /*!< in: file name */
265
ulint line, /*!< in: line number */
266
mtr_t* mtr) /*!< in: mtr */
271
rw_lock_x_lock_func(lock, 0, file, line);
273
mtr_memo_push(mtr, lock, MTR_MEMO_X_LOCK);
275
#endif /* !UNIV_HOTBACKUP */