1
/******************************************************
2
Mini-transaction buffer
6
Created 11/26/1995 Heikki Tuuri
7
*******************************************************/
11
#include "mach0data.h"
13
/*******************************************************************
14
Starts a mini-transaction and creates a mini-transaction handle
15
and a buffer in the memory buffer given by the caller. */
20
/* out: mtr buffer which also acts as
22
mtr_t* mtr) /* in: memory buffer for the mtr buffer */
24
dyn_array_create(&(mtr->memo));
25
dyn_array_create(&(mtr->log));
27
mtr->log_mode = MTR_LOG_ALL;
28
mtr->modifications = FALSE;
32
mtr->state = MTR_ACTIVE;
33
mtr->magic_n = MTR_MAGIC_N;
38
/*******************************************************
39
Pushes an object to an mtr memo stack. */
44
mtr_t* mtr, /* in: mtr */
45
void* object, /* in: object */
46
ulint type) /* in: object type: MTR_MEMO_S_LOCK, ... */
49
mtr_memo_slot_t* slot;
52
ut_ad(type >= MTR_MEMO_PAGE_S_FIX);
53
ut_ad(type <= MTR_MEMO_X_LOCK);
55
ut_ad(mtr->magic_n == MTR_MAGIC_N);
59
slot = dyn_array_push(memo, sizeof(mtr_memo_slot_t));
61
slot->object = object;
65
/**************************************************************
66
Sets and returns a savepoint in mtr. */
72
mtr_t* mtr) /* in: mtr */
77
ut_ad(mtr->magic_n == MTR_MAGIC_N);
81
return(dyn_array_get_data_size(memo));
84
/**************************************************************
85
Releases the (index tree) s-latch stored in an mtr memo after a
89
mtr_release_s_latch_at_savepoint(
90
/*=============================*/
91
mtr_t* mtr, /* in: mtr */
92
ulint savepoint, /* in: savepoint */
93
rw_lock_t* lock) /* in: latch to release */
95
mtr_memo_slot_t* slot;
99
ut_ad(mtr->magic_n == MTR_MAGIC_N);
100
ut_ad(mtr->state == MTR_ACTIVE);
104
ut_ad(dyn_array_get_data_size(memo) > savepoint);
106
slot = dyn_array_get_element(memo, savepoint);
108
ut_ad(slot->object == lock);
109
ut_ad(slot->type == MTR_MEMO_S_LOCK);
111
rw_lock_s_unlock(lock);
117
/**************************************************************
118
Checks if memo contains the given item. */
123
/* out: TRUE if contains */
124
mtr_t* mtr, /* in: mtr */
125
void* object, /* in: object to search */
126
ulint type) /* in: type of object */
128
mtr_memo_slot_t* slot;
133
ut_ad(mtr->magic_n == MTR_MAGIC_N);
137
offset = dyn_array_get_data_size(memo);
140
offset -= sizeof(mtr_memo_slot_t);
142
slot = dyn_array_get_element(memo, offset);
144
if ((object == slot->object) && (type == slot->type)) {
152
#endif /* UNIV_DEBUG */
154
/*******************************************************************
155
Returns the log object of a mini-transaction buffer. */
161
mtr_t* mtr) /* in: mini-transaction */
164
ut_ad(mtr->magic_n == MTR_MAGIC_N);
169
/*******************************************************************
170
Gets the logging mode of a mini-transaction. */
175
/* out: logging mode: MTR_LOG_NONE, ... */
176
mtr_t* mtr) /* in: mtr */
179
ut_ad(mtr->log_mode >= MTR_LOG_ALL);
180
ut_ad(mtr->log_mode <= MTR_LOG_SHORT_INSERTS);
182
return(mtr->log_mode);
185
/*******************************************************************
186
Changes the logging mode of a mini-transaction. */
192
mtr_t* mtr, /* in: mtr */
193
ulint mode) /* in: logging mode: MTR_LOG_NONE, ... */
198
ut_ad(mode >= MTR_LOG_ALL);
199
ut_ad(mode <= MTR_LOG_SHORT_INSERTS);
201
old_mode = mtr->log_mode;
203
if ((mode == MTR_LOG_SHORT_INSERTS) && (old_mode == MTR_LOG_NONE)) {
206
mtr->log_mode = mode;
209
ut_ad(old_mode >= MTR_LOG_ALL);
210
ut_ad(old_mode <= MTR_LOG_SHORT_INSERTS);
215
/*************************************************************************
216
Locks a lock in s-mode. */
221
rw_lock_t* lock, /* in: rw-lock */
222
const char* file, /* in: file name */
223
ulint line, /* in: line number */
224
mtr_t* mtr) /* in: mtr */
229
rw_lock_s_lock_func(lock, 0, file, line);
231
mtr_memo_push(mtr, lock, MTR_MEMO_S_LOCK);
234
/*************************************************************************
235
Locks a lock in x-mode. */
240
rw_lock_t* lock, /* in: rw-lock */
241
const char* file, /* in: file name */
242
ulint line, /* in: line number */
243
mtr_t* mtr) /* in: mtr */
248
rw_lock_x_lock_func(lock, 0, file, line);
250
mtr_memo_push(mtr, lock, MTR_MEMO_X_LOCK);