1
/*****************************************************************************
3
Copyright (c) 1995, 2009, 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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 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);
76
slot = (mtr_memo_slot_t*) dyn_array_push(memo, sizeof *slot);
78
slot->object = object;
82
/**********************************************************//**
83
Sets and returns a savepoint in mtr.
89
mtr_t* mtr) /*!< in: mtr */
94
ut_ad(mtr->magic_n == MTR_MAGIC_N);
98
return(dyn_array_get_data_size(memo));
101
#ifndef UNIV_HOTBACKUP
102
/**********************************************************//**
103
Releases the (index tree) s-latch stored in an mtr memo after a
107
mtr_release_s_latch_at_savepoint(
108
/*=============================*/
109
mtr_t* mtr, /*!< in: mtr */
110
ulint savepoint, /*!< in: savepoint */
111
rw_lock_t* lock) /*!< in: latch to release */
113
mtr_memo_slot_t* slot;
117
ut_ad(mtr->magic_n == MTR_MAGIC_N);
118
ut_ad(mtr->state == MTR_ACTIVE);
122
ut_ad(dyn_array_get_data_size(memo) > savepoint);
124
slot = (mtr_memo_slot_t*) dyn_array_get_element(memo, savepoint);
126
ut_ad(slot->object == lock);
127
ut_ad(slot->type == MTR_MEMO_S_LOCK);
129
rw_lock_s_unlock(lock);
135
/**********************************************************//**
136
Checks if memo contains the given item.
137
@return TRUE if contains */
142
mtr_t* mtr, /*!< in: mtr */
143
const void* object, /*!< in: object to search */
144
ulint type) /*!< in: type of object */
146
mtr_memo_slot_t* slot;
151
ut_ad(mtr->magic_n == MTR_MAGIC_N);
155
offset = dyn_array_get_data_size(memo);
158
offset -= sizeof(mtr_memo_slot_t);
160
slot = dyn_array_get_element(memo, offset);
162
if ((object == slot->object) && (type == slot->type)) {
170
# endif /* UNIV_DEBUG */
171
#endif /* !UNIV_HOTBACKUP */
173
/***************************************************************//**
174
Returns the log object of a mini-transaction buffer.
180
mtr_t* mtr) /*!< in: mini-transaction */
183
ut_ad(mtr->magic_n == MTR_MAGIC_N);
188
/***************************************************************//**
189
Gets the logging mode of a mini-transaction.
190
@return logging mode: MTR_LOG_NONE, ... */
195
mtr_t* mtr) /*!< in: mtr */
198
ut_ad(mtr->log_mode >= MTR_LOG_ALL);
199
ut_ad(mtr->log_mode <= MTR_LOG_SHORT_INSERTS);
201
return(mtr->log_mode);
204
/***************************************************************//**
205
Changes the logging mode of a mini-transaction.
211
mtr_t* mtr, /*!< in: mtr */
212
ulint mode) /*!< in: logging mode: MTR_LOG_NONE, ... */
217
ut_ad(mode >= MTR_LOG_ALL);
218
ut_ad(mode <= MTR_LOG_SHORT_INSERTS);
220
old_mode = mtr->log_mode;
222
if ((mode == MTR_LOG_SHORT_INSERTS) && (old_mode == MTR_LOG_NONE)) {
225
mtr->log_mode = mode;
228
ut_ad(old_mode >= MTR_LOG_ALL);
229
ut_ad(old_mode <= MTR_LOG_SHORT_INSERTS);
234
#ifndef UNIV_HOTBACKUP
235
/*********************************************************************//**
236
Locks a lock in s-mode. */
241
rw_lock_t* lock, /*!< in: rw-lock */
242
const char* file, /*!< in: file name */
243
ulint line, /*!< in: line number */
244
mtr_t* mtr) /*!< in: mtr */
249
rw_lock_s_lock_func(lock, 0, file, line);
251
mtr_memo_push(mtr, lock, MTR_MEMO_S_LOCK);
254
/*********************************************************************//**
255
Locks a lock in x-mode. */
260
rw_lock_t* lock, /*!< in: rw-lock */
261
const char* file, /*!< in: file name */
262
ulint line, /*!< in: line number */
263
mtr_t* mtr) /*!< in: mtr */
268
rw_lock_x_lock_func(lock, 0, file, line);
270
mtr_memo_push(mtr, lock, MTR_MEMO_X_LOCK);
272
#endif /* !UNIV_HOTBACKUP */