~drizzle-trunk/drizzle/development

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