~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Daniel Nichter
  • Date: 2011-10-23 16:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2448.
  • Revision ID: daniel@percona.com-20111023160137-7ac3blgz8z4tf8za
Add Administration Getting Started and Logging.  Capitalize SQL clause keywords.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************
2
 
Transaction system
3
 
 
4
 
(c) 1996 Innobase Oy
5
 
 
6
 
Created 3/26/1996 Heikki Tuuri
7
 
*******************************************************/
8
 
 
9
 
#include "srv0srv.h"
10
 
#include "trx0trx.h"
11
 
#include "data0type.h"
12
 
 
13
 
/* The typedef for rseg slot in the file copy */
14
 
typedef byte    trx_sysf_rseg_t;
15
 
 
16
 
/* Rollback segment specification slot offsets */
17
 
/*-------------------------------------------------------------*/
18
 
#define TRX_SYS_RSEG_SPACE      0       /* space where the the segment
19
 
                                        header is placed; starting with
20
 
                                        MySQL/InnoDB 5.1.7, this is
21
 
                                        UNIV_UNDEFINED if the slot is unused */
22
 
#define TRX_SYS_RSEG_PAGE_NO    4       /*  page number where the the segment
23
 
                                        header is placed; this is FIL_NULL
24
 
                                        if the slot is unused */
25
 
/*-------------------------------------------------------------*/
26
 
/* Size of a rollback segment specification slot */
27
 
#define TRX_SYS_RSEG_SLOT_SIZE  8
28
 
 
29
 
/*********************************************************************
30
 
Writes the value of max_trx_id to the file based trx system header. */
31
 
UNIV_INTERN
32
 
void
33
 
trx_sys_flush_max_trx_id(void);
34
 
/*==========================*/
35
 
 
36
 
/*******************************************************************
37
 
Checks if a page address is the trx sys header page. */
38
 
UNIV_INLINE
39
 
ibool
40
 
trx_sys_hdr_page(
41
 
/*=============*/
42
 
                        /* out: TRUE if trx sys header page */
43
 
        ulint   space,  /* in: space */
44
 
        ulint   page_no)/* in: page number */
45
 
{
46
 
        if ((space == TRX_SYS_SPACE) && (page_no == TRX_SYS_PAGE_NO)) {
47
 
 
48
 
                return(TRUE);
49
 
        }
50
 
 
51
 
        return(FALSE);
52
 
}
53
 
 
54
 
/*******************************************************************
55
 
Gets the pointer in the nth slot of the rseg array. */
56
 
UNIV_INLINE
57
 
trx_rseg_t*
58
 
trx_sys_get_nth_rseg(
59
 
/*=================*/
60
 
                                /* out: pointer to rseg object, NULL if slot
61
 
                                not in use */
62
 
        trx_sys_t*      sys,    /* in: trx system */
63
 
        ulint           n)      /* in: index of slot */
64
 
{
65
 
        ut_ad(mutex_own(&(kernel_mutex)));
66
 
        ut_ad(n < TRX_SYS_N_RSEGS);
67
 
 
68
 
        return(sys->rseg_array[n]);
69
 
}
70
 
 
71
 
/*******************************************************************
72
 
Sets the pointer in the nth slot of the rseg array. */
73
 
UNIV_INLINE
74
 
void
75
 
trx_sys_set_nth_rseg(
76
 
/*=================*/
77
 
        trx_sys_t*      sys,    /* in: trx system */
78
 
        ulint           n,      /* in: index of slot */
79
 
        trx_rseg_t*     rseg)   /* in: pointer to rseg object, NULL if slot
80
 
                                not in use */
81
 
{
82
 
        ut_ad(n < TRX_SYS_N_RSEGS);
83
 
 
84
 
        sys->rseg_array[n] = rseg;
85
 
}
86
 
 
87
 
/**************************************************************************
88
 
Gets a pointer to the transaction system header and x-latches its page. */
89
 
UNIV_INLINE
90
 
trx_sysf_t*
91
 
trx_sysf_get(
92
 
/*=========*/
93
 
                        /* out: pointer to system header, page x-latched. */
94
 
        mtr_t*  mtr)    /* in: mtr */
95
 
{
96
 
        buf_block_t*    block;
97
 
        trx_sysf_t*     header;
98
 
 
99
 
        ut_ad(mtr);
100
 
 
101
 
        block = buf_page_get(TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO,
102
 
                             RW_X_LATCH, mtr);
103
 
#ifdef UNIV_SYNC_DEBUG
104
 
        buf_block_dbg_add_level(block, SYNC_TRX_SYS_HEADER);
105
 
#endif /* UNIV_SYNC_DEBUG */
106
 
        header = TRX_SYS + buf_block_get_frame(block);
107
 
 
108
 
        return(header);
109
 
}
110
 
 
111
 
/*********************************************************************
112
 
Gets the space of the nth rollback segment slot in the trx system
113
 
file copy. */
114
 
UNIV_INLINE
115
 
ulint
116
 
trx_sysf_rseg_get_space(
117
 
/*====================*/
118
 
                                        /* out: space id */
119
 
        trx_sysf_t*     sys_header,     /* in: trx sys header */
120
 
        ulint           i,              /* in: slot index == rseg id */
121
 
        mtr_t*          mtr)            /* in: mtr */
122
 
{
123
 
        ut_ad(mutex_own(&(kernel_mutex)));
124
 
        ut_ad(sys_header);
125
 
        ut_ad(i < TRX_SYS_N_RSEGS);
126
 
 
127
 
        return(mtr_read_ulint(sys_header + TRX_SYS_RSEGS
128
 
                              + i * TRX_SYS_RSEG_SLOT_SIZE
129
 
                              + TRX_SYS_RSEG_SPACE, MLOG_4BYTES, mtr));
130
 
}
131
 
 
132
 
/*********************************************************************
133
 
Gets the page number of the nth rollback segment slot in the trx system
134
 
header. */
135
 
UNIV_INLINE
136
 
ulint
137
 
trx_sysf_rseg_get_page_no(
138
 
/*======================*/
139
 
                                        /* out: page number, FIL_NULL
140
 
                                        if slot unused */
141
 
        trx_sysf_t*     sys_header,     /* in: trx system header */
142
 
        ulint           i,              /* in: slot index == rseg id */
143
 
        mtr_t*          mtr)            /* in: mtr */
144
 
{
145
 
        ut_ad(sys_header);
146
 
        ut_ad(mutex_own(&(kernel_mutex)));
147
 
        ut_ad(i < TRX_SYS_N_RSEGS);
148
 
 
149
 
        return(mtr_read_ulint(sys_header + TRX_SYS_RSEGS
150
 
                              + i * TRX_SYS_RSEG_SLOT_SIZE
151
 
                              + TRX_SYS_RSEG_PAGE_NO, MLOG_4BYTES, mtr));
152
 
}
153
 
 
154
 
/*********************************************************************
155
 
Sets the space id of the nth rollback segment slot in the trx system
156
 
file copy. */
157
 
UNIV_INLINE
158
 
void
159
 
trx_sysf_rseg_set_space(
160
 
/*====================*/
161
 
        trx_sysf_t*     sys_header,     /* in: trx sys file copy */
162
 
        ulint           i,              /* in: slot index == rseg id */
163
 
        ulint           space,          /* in: space id */
164
 
        mtr_t*          mtr)            /* in: mtr */
165
 
{
166
 
        ut_ad(mutex_own(&(kernel_mutex)));
167
 
        ut_ad(sys_header);
168
 
        ut_ad(i < TRX_SYS_N_RSEGS);
169
 
 
170
 
        mlog_write_ulint(sys_header + TRX_SYS_RSEGS
171
 
                         + i * TRX_SYS_RSEG_SLOT_SIZE
172
 
                         + TRX_SYS_RSEG_SPACE,
173
 
                         space,
174
 
                         MLOG_4BYTES, mtr);
175
 
}
176
 
 
177
 
/*********************************************************************
178
 
Sets the page number of the nth rollback segment slot in the trx system
179
 
header. */
180
 
UNIV_INLINE
181
 
void
182
 
trx_sysf_rseg_set_page_no(
183
 
/*======================*/
184
 
        trx_sysf_t*     sys_header,     /* in: trx sys header */
185
 
        ulint           i,              /* in: slot index == rseg id */
186
 
        ulint           page_no,        /* in: page number, FIL_NULL if the
187
 
                                        slot is reset to unused */
188
 
        mtr_t*          mtr)            /* in: mtr */
189
 
{
190
 
        ut_ad(mutex_own(&(kernel_mutex)));
191
 
        ut_ad(sys_header);
192
 
        ut_ad(i < TRX_SYS_N_RSEGS);
193
 
 
194
 
        mlog_write_ulint(sys_header + TRX_SYS_RSEGS
195
 
                         + i * TRX_SYS_RSEG_SLOT_SIZE
196
 
                         + TRX_SYS_RSEG_PAGE_NO,
197
 
                         page_no,
198
 
                         MLOG_4BYTES, mtr);
199
 
}
200
 
 
201
 
/*********************************************************************
202
 
Writes a trx id to an index page. In case that the id size changes in
203
 
some future version, this function should be used instead of
204
 
mach_write_... */
205
 
UNIV_INLINE
206
 
void
207
 
trx_write_trx_id(
208
 
/*=============*/
209
 
        byte*   ptr,    /* in: pointer to memory where written */
210
 
        dulint  id)     /* in: id */
211
 
{
212
 
#if DATA_TRX_ID_LEN != 6
213
 
# error "DATA_TRX_ID_LEN != 6"
214
 
#endif
215
 
        mach_write_to_6(ptr, id);
216
 
}
217
 
 
218
 
/*********************************************************************
219
 
Reads a trx id from an index page. In case that the id size changes in
220
 
some future version, this function should be used instead of
221
 
mach_read_... */
222
 
UNIV_INLINE
223
 
dulint
224
 
trx_read_trx_id(
225
 
/*============*/
226
 
                                /* out: id */
227
 
        const byte*     ptr)    /* in: pointer to memory from where to read */
228
 
{
229
 
#if DATA_TRX_ID_LEN != 6
230
 
# error "DATA_TRX_ID_LEN != 6"
231
 
#endif
232
 
        return(mach_read_from_6(ptr));
233
 
}
234
 
 
235
 
/********************************************************************
236
 
Looks for the trx handle with the given id in trx_list. */
237
 
UNIV_INLINE
238
 
trx_t*
239
 
trx_get_on_id(
240
 
/*==========*/
241
 
                        /* out: the trx handle or NULL if not found */
242
 
        dulint  trx_id) /* in: trx id to search for */
243
 
{
244
 
        trx_t*  trx;
245
 
 
246
 
        ut_ad(mutex_own(&(kernel_mutex)));
247
 
 
248
 
        trx = UT_LIST_GET_FIRST(trx_sys->trx_list);
249
 
 
250
 
        while (trx != NULL) {
251
 
                if (0 == ut_dulint_cmp(trx_id, trx->id)) {
252
 
 
253
 
                        return(trx);
254
 
                }
255
 
 
256
 
                trx = UT_LIST_GET_NEXT(trx_list, trx);
257
 
        }
258
 
 
259
 
        return(NULL);
260
 
}
261
 
 
262
 
/********************************************************************
263
 
Returns the minumum trx id in trx list. This is the smallest id for which
264
 
the trx can possibly be active. (But, you must look at the trx->conc_state to
265
 
find out if the minimum trx id transaction itself is active, or already
266
 
committed.) */
267
 
UNIV_INLINE
268
 
dulint
269
 
trx_list_get_min_trx_id(void)
270
 
/*=========================*/
271
 
                        /* out: the minimum trx id, or trx_sys->max_trx_id
272
 
                        if the trx list is empty */
273
 
{
274
 
        trx_t*  trx;
275
 
 
276
 
        ut_ad(mutex_own(&(kernel_mutex)));
277
 
 
278
 
        trx = UT_LIST_GET_LAST(trx_sys->trx_list);
279
 
 
280
 
        if (trx == NULL) {
281
 
 
282
 
                return(trx_sys->max_trx_id);
283
 
        }
284
 
 
285
 
        return(trx->id);
286
 
}
287
 
 
288
 
/********************************************************************
289
 
Checks if a transaction with the given id is active. */
290
 
UNIV_INLINE
291
 
ibool
292
 
trx_is_active(
293
 
/*==========*/
294
 
                        /* out: TRUE if active */
295
 
        dulint  trx_id) /* in: trx id of the transaction */
296
 
{
297
 
        trx_t*  trx;
298
 
 
299
 
        ut_ad(mutex_own(&(kernel_mutex)));
300
 
 
301
 
        if (ut_dulint_cmp(trx_id, trx_list_get_min_trx_id()) < 0) {
302
 
 
303
 
                return(FALSE);
304
 
        }
305
 
 
306
 
        if (ut_dulint_cmp(trx_id, trx_sys->max_trx_id) >= 0) {
307
 
 
308
 
                /* There must be corruption: we return TRUE because this
309
 
                function is only called by lock_clust_rec_some_has_impl()
310
 
                and row_vers_impl_x_locked_off_kernel() and they have
311
 
                diagnostic prints in this case */
312
 
 
313
 
                return(TRUE);
314
 
        }
315
 
 
316
 
        trx = trx_get_on_id(trx_id);
317
 
        if (trx && (trx->conc_state == TRX_ACTIVE
318
 
                    || trx->conc_state == TRX_PREPARED)) {
319
 
 
320
 
                return(TRUE);
321
 
        }
322
 
 
323
 
        return(FALSE);
324
 
}
325
 
 
326
 
/*********************************************************************
327
 
Allocates a new transaction id. */
328
 
UNIV_INLINE
329
 
dulint
330
 
trx_sys_get_new_trx_id(void)
331
 
/*========================*/
332
 
                        /* out: new, allocated trx id */
333
 
{
334
 
        dulint  id;
335
 
 
336
 
        ut_ad(mutex_own(&kernel_mutex));
337
 
 
338
 
        /* VERY important: after the database is started, max_trx_id value is
339
 
        divisible by TRX_SYS_TRX_ID_WRITE_MARGIN, and the following if
340
 
        will evaluate to TRUE when this function is first time called,
341
 
        and the value for trx id will be written to disk-based header!
342
 
        Thus trx id values will not overlap when the database is
343
 
        repeatedly started! */
344
 
 
345
 
        if (ut_dulint_get_low(trx_sys->max_trx_id)
346
 
            % TRX_SYS_TRX_ID_WRITE_MARGIN == 0) {
347
 
 
348
 
                trx_sys_flush_max_trx_id();
349
 
        }
350
 
 
351
 
        id = trx_sys->max_trx_id;
352
 
 
353
 
        UT_DULINT_INC(trx_sys->max_trx_id);
354
 
 
355
 
        return(id);
356
 
}
357
 
 
358
 
/*********************************************************************
359
 
Allocates a new transaction number. */
360
 
UNIV_INLINE
361
 
dulint
362
 
trx_sys_get_new_trx_no(void)
363
 
/*========================*/
364
 
                        /* out: new, allocated trx number */
365
 
{
366
 
        ut_ad(mutex_own(&kernel_mutex));
367
 
 
368
 
        return(trx_sys_get_new_trx_id());
369
 
}