~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/innodb_plugin/include/mtr0mtr.ic

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
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
 
 
74
        memo = &(mtr->memo);
 
75
 
 
76
        slot = (mtr_memo_slot_t*) dyn_array_push(memo, sizeof *slot);
 
77
 
 
78
        slot->object = object;
 
79
        slot->type = type;
 
80
}
 
81
 
 
82
/**********************************************************//**
 
83
Sets and returns a savepoint in mtr.
 
84
@return savepoint */
 
85
UNIV_INLINE
 
86
ulint
 
87
mtr_set_savepoint(
 
88
/*==============*/
 
89
        mtr_t*  mtr)    /*!< in: mtr */
 
90
{
 
91
        dyn_array_t*    memo;
 
92
 
 
93
        ut_ad(mtr);
 
94
        ut_ad(mtr->magic_n == MTR_MAGIC_N);
 
95
 
 
96
        memo = &(mtr->memo);
 
97
 
 
98
        return(dyn_array_get_data_size(memo));
 
99
}
 
100
 
 
101
#ifndef UNIV_HOTBACKUP
 
102
/**********************************************************//**
 
103
Releases the (index tree) s-latch stored in an mtr memo after a
 
104
savepoint. */
 
105
UNIV_INLINE
 
106
void
 
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 */
 
112
{
 
113
        mtr_memo_slot_t* slot;
 
114
        dyn_array_t*    memo;
 
115
 
 
116
        ut_ad(mtr);
 
117
        ut_ad(mtr->magic_n == MTR_MAGIC_N);
 
118
        ut_ad(mtr->state == MTR_ACTIVE);
 
119
 
 
120
        memo = &(mtr->memo);
 
121
 
 
122
        ut_ad(dyn_array_get_data_size(memo) > savepoint);
 
123
 
 
124
        slot = (mtr_memo_slot_t*) dyn_array_get_element(memo, savepoint);
 
125
 
 
126
        ut_ad(slot->object == lock);
 
127
        ut_ad(slot->type == MTR_MEMO_S_LOCK);
 
128
 
 
129
        rw_lock_s_unlock(lock);
 
130
 
 
131
        slot->object = NULL;
 
132
}
 
133
 
 
134
# ifdef UNIV_DEBUG
 
135
/**********************************************************//**
 
136
Checks if memo contains the given item.
 
137
@return TRUE if contains */
 
138
UNIV_INLINE
 
139
ibool
 
140
mtr_memo_contains(
 
141
/*==============*/
 
142
        mtr_t*          mtr,    /*!< in: mtr */
 
143
        const void*     object, /*!< in: object to search */
 
144
        ulint           type)   /*!< in: type of object */
 
145
{
 
146
        mtr_memo_slot_t* slot;
 
147
        dyn_array_t*    memo;
 
148
        ulint           offset;
 
149
 
 
150
        ut_ad(mtr);
 
151
        ut_ad(mtr->magic_n == MTR_MAGIC_N);
 
152
 
 
153
        memo = &(mtr->memo);
 
154
 
 
155
        offset = dyn_array_get_data_size(memo);
 
156
 
 
157
        while (offset > 0) {
 
158
                offset -= sizeof(mtr_memo_slot_t);
 
159
 
 
160
                slot = dyn_array_get_element(memo, offset);
 
161
 
 
162
                if ((object == slot->object) && (type == slot->type)) {
 
163
 
 
164
                        return(TRUE);
 
165
                }
 
166
        }
 
167
 
 
168
        return(FALSE);
 
169
}
 
170
# endif /* UNIV_DEBUG */
 
171
#endif /* !UNIV_HOTBACKUP */
 
172
 
 
173
/***************************************************************//**
 
174
Returns the log object of a mini-transaction buffer.
 
175
@return log */
 
176
UNIV_INLINE
 
177
dyn_array_t*
 
178
mtr_get_log(
 
179
/*========*/
 
180
        mtr_t*  mtr)    /*!< in: mini-transaction */
 
181
{
 
182
        ut_ad(mtr);
 
183
        ut_ad(mtr->magic_n == MTR_MAGIC_N);
 
184
 
 
185
        return(&(mtr->log));
 
186
}
 
187
 
 
188
/***************************************************************//**
 
189
Gets the logging mode of a mini-transaction.
 
190
@return logging mode: MTR_LOG_NONE, ... */
 
191
UNIV_INLINE
 
192
ulint
 
193
mtr_get_log_mode(
 
194
/*=============*/
 
195
        mtr_t*  mtr)    /*!< in: mtr */
 
196
{
 
197
        ut_ad(mtr);
 
198
        ut_ad(mtr->log_mode >= MTR_LOG_ALL);
 
199
        ut_ad(mtr->log_mode <= MTR_LOG_SHORT_INSERTS);
 
200
 
 
201
        return(mtr->log_mode);
 
202
}
 
203
 
 
204
/***************************************************************//**
 
205
Changes the logging mode of a mini-transaction.
 
206
@return old mode */
 
207
UNIV_INLINE
 
208
ulint
 
209
mtr_set_log_mode(
 
210
/*=============*/
 
211
        mtr_t*  mtr,    /*!< in: mtr */
 
212
        ulint   mode)   /*!< in: logging mode: MTR_LOG_NONE, ... */
 
213
{
 
214
        ulint   old_mode;
 
215
 
 
216
        ut_ad(mtr);
 
217
        ut_ad(mode >= MTR_LOG_ALL);
 
218
        ut_ad(mode <= MTR_LOG_SHORT_INSERTS);
 
219
 
 
220
        old_mode = mtr->log_mode;
 
221
 
 
222
        if ((mode == MTR_LOG_SHORT_INSERTS) && (old_mode == MTR_LOG_NONE)) {
 
223
                /* Do nothing */
 
224
        } else {
 
225
                mtr->log_mode = mode;
 
226
        }
 
227
 
 
228
        ut_ad(old_mode >= MTR_LOG_ALL);
 
229
        ut_ad(old_mode <= MTR_LOG_SHORT_INSERTS);
 
230
 
 
231
        return(old_mode);
 
232
}
 
233
 
 
234
#ifndef UNIV_HOTBACKUP
 
235
/*********************************************************************//**
 
236
Locks a lock in s-mode. */
 
237
UNIV_INLINE
 
238
void
 
239
mtr_s_lock_func(
 
240
/*============*/
 
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 */
 
245
{
 
246
        ut_ad(mtr);
 
247
        ut_ad(lock);
 
248
 
 
249
        rw_lock_s_lock_func(lock, 0, file, line);
 
250
 
 
251
        mtr_memo_push(mtr, lock, MTR_MEMO_S_LOCK);
 
252
}
 
253
 
 
254
/*********************************************************************//**
 
255
Locks a lock in x-mode. */
 
256
UNIV_INLINE
 
257
void
 
258
mtr_x_lock_func(
 
259
/*============*/
 
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 */
 
264
{
 
265
        ut_ad(mtr);
 
266
        ut_ad(lock);
 
267
 
 
268
        rw_lock_x_lock_func(lock, 0, file, line);
 
269
 
 
270
        mtr_memo_push(mtr, lock, MTR_MEMO_X_LOCK);
 
271
}
 
272
#endif /* !UNIV_HOTBACKUP */