~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-11-08 11:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20111108113113-3ulw01fvi4vn8m25
Tags: upstream-5.5.17
ImportĀ upstreamĀ versionĀ 5.5.17

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., 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. */
 
34
UNIV_INLINE
 
35
void
 
36
mtr_start(
 
37
/*======*/
 
38
        mtr_t*  mtr)    /*!< out: mini-transaction */
 
39
{
 
40
        UNIV_MEM_INVALID(mtr, sizeof *mtr);
 
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->inside_ibuf = FALSE;
 
48
        mtr->n_log_recs = 0;
 
49
 
 
50
        ut_d(mtr->state = MTR_ACTIVE);
 
51
        ut_d(mtr->magic_n = MTR_MAGIC_N);
 
52
}
 
53
 
 
54
/***************************************************//**
 
55
Pushes an object to an mtr memo stack. */
 
56
UNIV_INLINE
 
57
void
 
58
mtr_memo_push(
 
59
/*==========*/
 
60
        mtr_t*  mtr,    /*!< in: mtr */
 
61
        void*   object, /*!< in: object */
 
62
        ulint   type)   /*!< in: object type: MTR_MEMO_S_LOCK, ... */
 
63
{
 
64
        dyn_array_t*            memo;
 
65
        mtr_memo_slot_t*        slot;
 
66
 
 
67
        ut_ad(object);
 
68
        ut_ad(type >= MTR_MEMO_PAGE_S_FIX);
 
69
        ut_ad(type <= MTR_MEMO_X_LOCK);
 
70
        ut_ad(mtr);
 
71
        ut_ad(mtr->magic_n == MTR_MAGIC_N);
 
72
        ut_ad(mtr->state == MTR_ACTIVE);
 
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
        ut_ad(mtr->state == MTR_ACTIVE);
 
96
 
 
97
        memo = &(mtr->memo);
 
98
 
 
99
        return(dyn_array_get_data_size(memo));
 
100
}
 
101
 
 
102
#ifndef UNIV_HOTBACKUP
 
103
/**********************************************************//**
 
104
Releases the (index tree) s-latch stored in an mtr memo after a
 
105
savepoint. */
 
106
UNIV_INLINE
 
107
void
 
108
mtr_release_s_latch_at_savepoint(
 
109
/*=============================*/
 
110
        mtr_t*          mtr,            /*!< in: mtr */
 
111
        ulint           savepoint,      /*!< in: savepoint */
 
112
        rw_lock_t*      lock)           /*!< in: latch to release */
 
113
{
 
114
        mtr_memo_slot_t* slot;
 
115
        dyn_array_t*    memo;
 
116
 
 
117
        ut_ad(mtr);
 
118
        ut_ad(mtr->magic_n == MTR_MAGIC_N);
 
119
        ut_ad(mtr->state == MTR_ACTIVE);
 
120
 
 
121
        memo = &(mtr->memo);
 
122
 
 
123
        ut_ad(dyn_array_get_data_size(memo) > savepoint);
 
124
 
 
125
        slot = (mtr_memo_slot_t*) dyn_array_get_element(memo, savepoint);
 
126
 
 
127
        ut_ad(slot->object == lock);
 
128
        ut_ad(slot->type == MTR_MEMO_S_LOCK);
 
129
 
 
130
        rw_lock_s_unlock(lock);
 
131
 
 
132
        slot->object = NULL;
 
133
}
 
134
 
 
135
# ifdef UNIV_DEBUG
 
136
/**********************************************************//**
 
137
Checks if memo contains the given item.
 
138
@return TRUE if contains */
 
139
UNIV_INLINE
 
140
ibool
 
141
mtr_memo_contains(
 
142
/*==============*/
 
143
        mtr_t*          mtr,    /*!< in: mtr */
 
144
        const void*     object, /*!< in: object to search */
 
145
        ulint           type)   /*!< in: type of object */
 
146
{
 
147
        mtr_memo_slot_t* slot;
 
148
        dyn_array_t*    memo;
 
149
        ulint           offset;
 
150
 
 
151
        ut_ad(mtr);
 
152
        ut_ad(mtr->magic_n == MTR_MAGIC_N);
 
153
        ut_ad(mtr->state == MTR_ACTIVE || mtr->state == MTR_COMMITTING);
 
154
 
 
155
        memo = &(mtr->memo);
 
156
 
 
157
        offset = dyn_array_get_data_size(memo);
 
158
 
 
159
        while (offset > 0) {
 
160
                offset -= sizeof(mtr_memo_slot_t);
 
161
 
 
162
                slot = (mtr_memo_slot_t*) dyn_array_get_element(memo, offset);
 
163
 
 
164
                if ((object == slot->object) && (type == slot->type)) {
 
165
 
 
166
                        return(TRUE);
 
167
                }
 
168
        }
 
169
 
 
170
        return(FALSE);
 
171
}
 
172
# endif /* UNIV_DEBUG */
 
173
#endif /* !UNIV_HOTBACKUP */
 
174
 
 
175
/***************************************************************//**
 
176
Returns the log object of a mini-transaction buffer.
 
177
@return log */
 
178
UNIV_INLINE
 
179
dyn_array_t*
 
180
mtr_get_log(
 
181
/*========*/
 
182
        mtr_t*  mtr)    /*!< in: mini-transaction */
 
183
{
 
184
        ut_ad(mtr);
 
185
        ut_ad(mtr->magic_n == MTR_MAGIC_N);
 
186
 
 
187
        return(&(mtr->log));
 
188
}
 
189
 
 
190
/***************************************************************//**
 
191
Gets the logging mode of a mini-transaction.
 
192
@return logging mode: MTR_LOG_NONE, ... */
 
193
UNIV_INLINE
 
194
ulint
 
195
mtr_get_log_mode(
 
196
/*=============*/
 
197
        mtr_t*  mtr)    /*!< in: mtr */
 
198
{
 
199
        ut_ad(mtr);
 
200
        ut_ad(mtr->log_mode >= MTR_LOG_ALL);
 
201
        ut_ad(mtr->log_mode <= MTR_LOG_SHORT_INSERTS);
 
202
 
 
203
        return(mtr->log_mode);
 
204
}
 
205
 
 
206
/***************************************************************//**
 
207
Changes the logging mode of a mini-transaction.
 
208
@return old mode */
 
209
UNIV_INLINE
 
210
ulint
 
211
mtr_set_log_mode(
 
212
/*=============*/
 
213
        mtr_t*  mtr,    /*!< in: mtr */
 
214
        ulint   mode)   /*!< in: logging mode: MTR_LOG_NONE, ... */
 
215
{
 
216
        ulint   old_mode;
 
217
 
 
218
        ut_ad(mtr);
 
219
        ut_ad(mode >= MTR_LOG_ALL);
 
220
        ut_ad(mode <= MTR_LOG_SHORT_INSERTS);
 
221
 
 
222
        old_mode = mtr->log_mode;
 
223
 
 
224
        if ((mode == MTR_LOG_SHORT_INSERTS) && (old_mode == MTR_LOG_NONE)) {
 
225
                /* Do nothing */
 
226
        } else {
 
227
                mtr->log_mode = mode;
 
228
        }
 
229
 
 
230
        ut_ad(old_mode >= MTR_LOG_ALL);
 
231
        ut_ad(old_mode <= MTR_LOG_SHORT_INSERTS);
 
232
 
 
233
        return(old_mode);
 
234
}
 
235
 
 
236
#ifndef UNIV_HOTBACKUP
 
237
/*********************************************************************//**
 
238
Locks a lock in s-mode. */
 
239
UNIV_INLINE
 
240
void
 
241
mtr_s_lock_func(
 
242
/*============*/
 
243
        rw_lock_t*      lock,   /*!< in: rw-lock */
 
244
        const char*     file,   /*!< in: file name */
 
245
        ulint           line,   /*!< in: line number */
 
246
        mtr_t*          mtr)    /*!< in: mtr */
 
247
{
 
248
        ut_ad(mtr);
 
249
        ut_ad(lock);
 
250
 
 
251
        rw_lock_s_lock_func(lock, 0, file, line);
 
252
 
 
253
        mtr_memo_push(mtr, lock, MTR_MEMO_S_LOCK);
 
254
}
 
255
 
 
256
/*********************************************************************//**
 
257
Locks a lock in x-mode. */
 
258
UNIV_INLINE
 
259
void
 
260
mtr_x_lock_func(
 
261
/*============*/
 
262
        rw_lock_t*      lock,   /*!< in: rw-lock */
 
263
        const char*     file,   /*!< in: file name */
 
264
        ulint           line,   /*!< in: line number */
 
265
        mtr_t*          mtr)    /*!< in: mtr */
 
266
{
 
267
        ut_ad(mtr);
 
268
        ut_ad(lock);
 
269
 
 
270
        rw_lock_x_lock_func(lock, 0, file, line);
 
271
 
 
272
        mtr_memo_push(mtr, lock, MTR_MEMO_X_LOCK);
 
273
}
 
274
#endif /* !UNIV_HOTBACKUP */