1
/******************************************************
6
Created 3/26/1996 Heikki Tuuri
7
*******************************************************/
11
#include "data0type.h"
13
/* The typedef for rseg slot in the file copy */
14
typedef byte trx_sysf_rseg_t;
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
29
/*********************************************************************
30
Writes the value of max_trx_id to the file based trx system header. */
33
trx_sys_flush_max_trx_id(void);
34
/*==========================*/
36
/*******************************************************************
37
Checks if a page address is the trx sys header page. */
42
/* out: TRUE if trx sys header page */
43
ulint space, /* in: space */
44
ulint page_no)/* in: page number */
46
if ((space == TRX_SYS_SPACE) && (page_no == TRX_SYS_PAGE_NO)) {
54
/*******************************************************************
55
Gets the pointer in the nth slot of the rseg array. */
60
/* out: pointer to rseg object, NULL if slot
62
trx_sys_t* sys, /* in: trx system */
63
ulint n) /* in: index of slot */
65
ut_ad(mutex_own(&(kernel_mutex)));
66
ut_ad(n < TRX_SYS_N_RSEGS);
68
return(sys->rseg_array[n]);
71
/*******************************************************************
72
Sets the pointer in the nth slot of the rseg array. */
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
82
ut_ad(n < TRX_SYS_N_RSEGS);
84
sys->rseg_array[n] = rseg;
87
/**************************************************************************
88
Gets a pointer to the transaction system header and x-latches its page. */
93
/* out: pointer to system header, page x-latched. */
94
mtr_t* mtr) /* in: mtr */
100
header = TRX_SYS + buf_page_get(TRX_SYS_SPACE, TRX_SYS_PAGE_NO,
103
#ifdef UNIV_SYNC_DEBUG
104
buf_page_dbg_add_level(header, SYNC_TRX_SYS_HEADER);
105
#endif /* UNIV_SYNC_DEBUG */
110
/*********************************************************************
111
Gets the space of the nth rollback segment slot in the trx system
115
trx_sysf_rseg_get_space(
116
/*====================*/
118
trx_sysf_t* sys_header, /* in: trx sys header */
119
ulint i, /* in: slot index == rseg id */
120
mtr_t* mtr) /* in: mtr */
122
ut_ad(mutex_own(&(kernel_mutex)));
124
ut_ad(i < TRX_SYS_N_RSEGS);
126
return(mtr_read_ulint(sys_header + TRX_SYS_RSEGS
127
+ i * TRX_SYS_RSEG_SLOT_SIZE
128
+ TRX_SYS_RSEG_SPACE, MLOG_4BYTES, mtr));
131
/*********************************************************************
132
Gets the page number of the nth rollback segment slot in the trx system
136
trx_sysf_rseg_get_page_no(
137
/*======================*/
138
/* out: page number, FIL_NULL
140
trx_sysf_t* sys_header, /* in: trx system header */
141
ulint i, /* in: slot index == rseg id */
142
mtr_t* mtr) /* in: mtr */
145
ut_ad(mutex_own(&(kernel_mutex)));
146
ut_ad(i < TRX_SYS_N_RSEGS);
148
return(mtr_read_ulint(sys_header + TRX_SYS_RSEGS
149
+ i * TRX_SYS_RSEG_SLOT_SIZE
150
+ TRX_SYS_RSEG_PAGE_NO, MLOG_4BYTES, mtr));
153
/*********************************************************************
154
Sets the space id of the nth rollback segment slot in the trx system
158
trx_sysf_rseg_set_space(
159
/*====================*/
160
trx_sysf_t* sys_header, /* in: trx sys file copy */
161
ulint i, /* in: slot index == rseg id */
162
ulint space, /* in: space id */
163
mtr_t* mtr) /* in: mtr */
165
ut_ad(mutex_own(&(kernel_mutex)));
167
ut_ad(i < TRX_SYS_N_RSEGS);
169
mlog_write_ulint(sys_header + TRX_SYS_RSEGS
170
+ i * TRX_SYS_RSEG_SLOT_SIZE
171
+ TRX_SYS_RSEG_SPACE,
176
/*********************************************************************
177
Sets the page number of the nth rollback segment slot in the trx system
181
trx_sysf_rseg_set_page_no(
182
/*======================*/
183
trx_sysf_t* sys_header, /* in: trx sys header */
184
ulint i, /* in: slot index == rseg id */
185
ulint page_no, /* in: page number, FIL_NULL if the
186
slot is reset to unused */
187
mtr_t* mtr) /* in: mtr */
189
ut_ad(mutex_own(&(kernel_mutex)));
191
ut_ad(i < TRX_SYS_N_RSEGS);
193
mlog_write_ulint(sys_header + TRX_SYS_RSEGS
194
+ i * TRX_SYS_RSEG_SLOT_SIZE
195
+ TRX_SYS_RSEG_PAGE_NO,
200
/*********************************************************************
201
Writes a trx id to an index page. In case that the id size changes in
202
some future version, this function should be used instead of
208
byte* ptr, /* in: pointer to memory where written */
209
dulint id) /* in: id */
211
ut_ad(DATA_TRX_ID_LEN == 6);
213
mach_write_to_6(ptr, id);
216
/*********************************************************************
217
Reads a trx id from an index page. In case that the id size changes in
218
some future version, this function should be used instead of
225
byte* ptr) /* in: pointer to memory from where to read */
227
ut_ad(DATA_TRX_ID_LEN == 6);
229
return(mach_read_from_6(ptr));
232
/********************************************************************
233
Looks for the trx handle with the given id in trx_list. */
238
/* out: the trx handle or NULL if not found */
239
dulint trx_id) /* in: trx id to search for */
243
ut_ad(mutex_own(&(kernel_mutex)));
245
trx = UT_LIST_GET_FIRST(trx_sys->trx_list);
247
while (trx != NULL) {
248
if (0 == ut_dulint_cmp(trx_id, trx->id)) {
253
trx = UT_LIST_GET_NEXT(trx_list, trx);
259
/********************************************************************
260
Returns the minumum trx id in trx list. This is the smallest id for which
261
the trx can possibly be active. (But, you must look at the trx->conc_state to
262
find out if the minimum trx id transaction itself is active, or already
266
trx_list_get_min_trx_id(void)
267
/*=========================*/
268
/* out: the minimum trx id, or trx_sys->max_trx_id
269
if the trx list is empty */
273
ut_ad(mutex_own(&(kernel_mutex)));
275
trx = UT_LIST_GET_LAST(trx_sys->trx_list);
279
return(trx_sys->max_trx_id);
285
/********************************************************************
286
Checks if a transaction with the given id is active. */
291
/* out: TRUE if active */
292
dulint trx_id) /* in: trx id of the transaction */
296
ut_ad(mutex_own(&(kernel_mutex)));
298
if (ut_dulint_cmp(trx_id, trx_list_get_min_trx_id()) < 0) {
303
if (ut_dulint_cmp(trx_id, trx_sys->max_trx_id) >= 0) {
305
/* There must be corruption: we return TRUE because this
306
function is only called by lock_clust_rec_some_has_impl()
307
and row_vers_impl_x_locked_off_kernel() and they have
308
diagnostic prints in this case */
313
trx = trx_get_on_id(trx_id);
314
if (trx && (trx->conc_state == TRX_ACTIVE
315
|| trx->conc_state == TRX_PREPARED)) {
323
/*********************************************************************
324
Allocates a new transaction id. */
327
trx_sys_get_new_trx_id(void)
328
/*========================*/
329
/* out: new, allocated trx id */
333
ut_ad(mutex_own(&kernel_mutex));
335
/* VERY important: after the database is started, max_trx_id value is
336
divisible by TRX_SYS_TRX_ID_WRITE_MARGIN, and the following if
337
will evaluate to TRUE when this function is first time called,
338
and the value for trx id will be written to disk-based header!
339
Thus trx id values will not overlap when the database is
340
repeatedly started! */
342
if (ut_dulint_get_low(trx_sys->max_trx_id)
343
% TRX_SYS_TRX_ID_WRITE_MARGIN == 0) {
345
trx_sys_flush_max_trx_id();
348
id = trx_sys->max_trx_id;
350
UT_DULINT_INC(trx_sys->max_trx_id);
355
/*********************************************************************
356
Allocates a new transaction number. */
359
trx_sys_get_new_trx_no(void)
360
/*========================*/
361
/* out: new, allocated trx number */
363
ut_ad(mutex_own(&kernel_mutex));
365
return(trx_sys_get_new_trx_id());