641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
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 |
||
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
19 |
/******************************************************
|
20 |
Mini-transaction buffer
|
|
21 |
||
22 |
Created 11/26/1995 Heikki Tuuri
|
|
23 |
*******************************************************/
|
|
24 |
||
25 |
#include "sync0sync.h" |
|
26 |
#include "sync0rw.h" |
|
27 |
#include "mach0data.h" |
|
28 |
||
29 |
/*******************************************************************
|
|
30 |
Starts a mini-transaction and creates a mini-transaction handle
|
|
31 |
and a buffer in the memory buffer given by the caller. */
|
|
32 |
UNIV_INLINE |
|
33 |
mtr_t*
|
|
34 |
mtr_start(
|
|
35 |
/*======*/
|
|
36 |
/* out: mtr buffer which also acts as |
|
37 |
the mtr handle */
|
|
38 |
mtr_t* mtr) /* in: memory buffer for the mtr buffer */ |
|
39 |
{
|
|
40 |
dyn_array_create(&(mtr->memo)); |
|
41 |
dyn_array_create(&(mtr->log)); |
|
42 |
||
43 |
mtr->log_mode = MTR_LOG_ALL; |
|
44 |
mtr->modifications = FALSE; |
|
45 |
mtr->n_log_recs = 0; |
|
46 |
||
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
47 |
ut_d(mtr->state = MTR_ACTIVE); |
48 |
ut_d(mtr->magic_n = MTR_MAGIC_N); |
|
49 |
||
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
50 |
return(mtr); |
51 |
}
|
|
52 |
||
53 |
/*******************************************************
|
|
54 |
Pushes an object to an mtr memo stack. */
|
|
55 |
UNIV_INLINE |
|
56 |
void |
|
57 |
mtr_memo_push(
|
|
58 |
/*==========*/
|
|
59 |
mtr_t* mtr, /* in: mtr */ |
|
60 |
void* object, /* in: object */ |
|
61 |
ulint type) /* in: object type: MTR_MEMO_S_LOCK, ... */ |
|
62 |
{
|
|
63 |
dyn_array_t* memo; |
|
64 |
mtr_memo_slot_t* slot; |
|
65 |
||
66 |
ut_ad(object); |
|
67 |
ut_ad(type >= MTR_MEMO_PAGE_S_FIX); |
|
68 |
ut_ad(type <= MTR_MEMO_X_LOCK); |
|
69 |
ut_ad(mtr); |
|
70 |
ut_ad(mtr->magic_n == MTR_MAGIC_N); |
|
71 |
||
72 |
memo = &(mtr->memo); |
|
73 |
||
74 |
slot = (mtr_memo_slot_t*) dyn_array_push(memo, sizeof *slot); |
|
75 |
||
76 |
slot->object = object; |
|
77 |
slot->type = type; |
|
78 |
}
|
|
79 |
||
80 |
/**************************************************************
|
|
81 |
Sets and returns a savepoint in mtr. */
|
|
82 |
UNIV_INLINE |
|
83 |
ulint |
|
84 |
mtr_set_savepoint(
|
|
85 |
/*==============*/
|
|
86 |
/* out: savepoint */ |
|
87 |
mtr_t* mtr) /* in: mtr */ |
|
88 |
{
|
|
89 |
dyn_array_t* memo; |
|
90 |
||
91 |
ut_ad(mtr); |
|
92 |
ut_ad(mtr->magic_n == MTR_MAGIC_N); |
|
93 |
||
94 |
memo = &(mtr->memo); |
|
95 |
||
96 |
return(dyn_array_get_data_size(memo)); |
|
97 |
}
|
|
98 |
||
99 |
/**************************************************************
|
|
100 |
Releases the (index tree) s-latch stored in an mtr memo after a
|
|
101 |
savepoint. */
|
|
102 |
UNIV_INLINE |
|
103 |
void |
|
104 |
mtr_release_s_latch_at_savepoint(
|
|
105 |
/*=============================*/
|
|
106 |
mtr_t* mtr, /* in: mtr */ |
|
107 |
ulint savepoint, /* in: savepoint */ |
|
108 |
rw_lock_t* lock) /* in: latch to release */ |
|
109 |
{
|
|
110 |
mtr_memo_slot_t* slot; |
|
111 |
dyn_array_t* memo; |
|
112 |
||
113 |
ut_ad(mtr); |
|
114 |
ut_ad(mtr->magic_n == MTR_MAGIC_N); |
|
115 |
ut_ad(mtr->state == MTR_ACTIVE); |
|
116 |
||
117 |
memo = &(mtr->memo); |
|
118 |
||
119 |
ut_ad(dyn_array_get_data_size(memo) > savepoint); |
|
120 |
||
121 |
slot = (mtr_memo_slot_t*) dyn_array_get_element(memo, savepoint); |
|
122 |
||
123 |
ut_ad(slot->object == lock); |
|
124 |
ut_ad(slot->type == MTR_MEMO_S_LOCK); |
|
125 |
||
126 |
rw_lock_s_unlock(lock); |
|
127 |
||
128 |
slot->object = NULL; |
|
129 |
}
|
|
130 |
||
131 |
#ifdef UNIV_DEBUG |
|
132 |
/**************************************************************
|
|
133 |
Checks if memo contains the given item. */
|
|
134 |
UNIV_INLINE |
|
135 |
ibool |
|
136 |
mtr_memo_contains(
|
|
137 |
/*==============*/
|
|
138 |
/* out: TRUE if contains */ |
|
139 |
mtr_t* mtr, /* in: mtr */ |
|
140 |
const void* object, /* in: object to search */ |
|
141 |
ulint type) /* in: type of object */ |
|
142 |
{
|
|
143 |
mtr_memo_slot_t* slot; |
|
144 |
dyn_array_t* memo; |
|
145 |
ulint offset; |
|
146 |
||
147 |
ut_ad(mtr); |
|
148 |
ut_ad(mtr->magic_n == MTR_MAGIC_N); |
|
149 |
||
150 |
memo = &(mtr->memo); |
|
151 |
||
152 |
offset = dyn_array_get_data_size(memo); |
|
153 |
||
154 |
while (offset > 0) { |
|
155 |
offset -= sizeof(mtr_memo_slot_t); |
|
156 |
||
157 |
slot = dyn_array_get_element(memo, offset); |
|
158 |
||
159 |
if ((object == slot->object) && (type == slot->type)) { |
|
160 |
||
161 |
return(TRUE); |
|
162 |
} |
|
163 |
} |
|
164 |
||
165 |
return(FALSE); |
|
166 |
}
|
|
167 |
#endif /* UNIV_DEBUG */ |
|
168 |
||
169 |
/*******************************************************************
|
|
170 |
Returns the log object of a mini-transaction buffer. */
|
|
171 |
UNIV_INLINE |
|
172 |
dyn_array_t*
|
|
173 |
mtr_get_log(
|
|
174 |
/*========*/
|
|
175 |
/* out: log */ |
|
176 |
mtr_t* mtr) /* in: mini-transaction */ |
|
177 |
{
|
|
178 |
ut_ad(mtr); |
|
179 |
ut_ad(mtr->magic_n == MTR_MAGIC_N); |
|
180 |
||
181 |
return(&(mtr->log)); |
|
182 |
}
|
|
183 |
||
184 |
/*******************************************************************
|
|
185 |
Gets the logging mode of a mini-transaction. */
|
|
186 |
UNIV_INLINE |
|
187 |
ulint |
|
188 |
mtr_get_log_mode(
|
|
189 |
/*=============*/
|
|
190 |
/* out: logging mode: MTR_LOG_NONE, ... */ |
|
191 |
mtr_t* mtr) /* in: mtr */ |
|
192 |
{
|
|
193 |
ut_ad(mtr); |
|
194 |
ut_ad(mtr->log_mode >= MTR_LOG_ALL); |
|
195 |
ut_ad(mtr->log_mode <= MTR_LOG_SHORT_INSERTS); |
|
196 |
||
197 |
return(mtr->log_mode); |
|
198 |
}
|
|
199 |
||
200 |
/*******************************************************************
|
|
201 |
Changes the logging mode of a mini-transaction. */
|
|
202 |
UNIV_INLINE |
|
203 |
ulint |
|
204 |
mtr_set_log_mode(
|
|
205 |
/*=============*/
|
|
206 |
/* out: old mode */ |
|
207 |
mtr_t* mtr, /* in: mtr */ |
|
208 |
ulint mode) /* in: logging mode: MTR_LOG_NONE, ... */ |
|
209 |
{
|
|
210 |
ulint old_mode; |
|
211 |
||
212 |
ut_ad(mtr); |
|
213 |
ut_ad(mode >= MTR_LOG_ALL); |
|
214 |
ut_ad(mode <= MTR_LOG_SHORT_INSERTS); |
|
215 |
||
216 |
old_mode = mtr->log_mode; |
|
217 |
||
218 |
if ((mode == MTR_LOG_SHORT_INSERTS) && (old_mode == MTR_LOG_NONE)) { |
|
219 |
/* Do nothing */ |
|
220 |
} else { |
|
221 |
mtr->log_mode = mode; |
|
222 |
} |
|
223 |
||
224 |
ut_ad(old_mode >= MTR_LOG_ALL); |
|
225 |
ut_ad(old_mode <= MTR_LOG_SHORT_INSERTS); |
|
226 |
||
227 |
return(old_mode); |
|
228 |
}
|
|
229 |
||
230 |
/*************************************************************************
|
|
231 |
Locks a lock in s-mode. */
|
|
232 |
UNIV_INLINE |
|
233 |
void |
|
234 |
mtr_s_lock_func(
|
|
235 |
/*============*/
|
|
236 |
rw_lock_t* lock, /* in: rw-lock */ |
|
237 |
const char* file, /* in: file name */ |
|
238 |
ulint line, /* in: line number */ |
|
239 |
mtr_t* mtr) /* in: mtr */ |
|
240 |
{
|
|
241 |
ut_ad(mtr); |
|
242 |
ut_ad(lock); |
|
243 |
||
244 |
rw_lock_s_lock_func(lock, 0, file, line); |
|
245 |
||
246 |
mtr_memo_push(mtr, lock, MTR_MEMO_S_LOCK); |
|
247 |
}
|
|
248 |
||
249 |
/*************************************************************************
|
|
250 |
Locks a lock in x-mode. */
|
|
251 |
UNIV_INLINE |
|
252 |
void |
|
253 |
mtr_x_lock_func(
|
|
254 |
/*============*/
|
|
255 |
rw_lock_t* lock, /* in: rw-lock */ |
|
256 |
const char* file, /* in: file name */ |
|
257 |
ulint line, /* in: line number */ |
|
258 |
mtr_t* mtr) /* in: mtr */ |
|
259 |
{
|
|
260 |
ut_ad(mtr); |
|
261 |
ut_ad(lock); |
|
262 |
||
263 |
rw_lock_x_lock_func(lock, 0, file, line); |
|
264 |
||
265 |
mtr_memo_push(mtr, lock, MTR_MEMO_X_LOCK); |
|
266 |
}
|