~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/mtr0mtr.ic

  • Committer: Patrick Crews
  • Date: 2010-09-14 20:21:03 UTC
  • mto: (1771.1.1 pcrews)
  • mto: This revision was merged to the branch mainline in revision 1772.
  • Revision ID: gleebix@gmail.com-20100914202103-1db2n0bshzafep19
Moved transaction_log tests into updated non-publisher-based tree

Show diffs side-by-side

added added

removed removed

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