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 */
101
block = buf_page_get(TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO,
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);
111
/*********************************************************************
112
Gets the space of the nth rollback segment slot in the trx system
116
trx_sysf_rseg_get_space(
117
/*====================*/
119
trx_sysf_t* sys_header, /* in: trx sys header */
120
ulint i, /* in: slot index == rseg id */
121
mtr_t* mtr) /* in: mtr */
123
ut_ad(mutex_own(&(kernel_mutex)));
125
ut_ad(i < TRX_SYS_N_RSEGS);
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));
132
/*********************************************************************
133
Gets the page number of the nth rollback segment slot in the trx system
137
trx_sysf_rseg_get_page_no(
138
/*======================*/
139
/* out: page number, FIL_NULL
141
trx_sysf_t* sys_header, /* in: trx system header */
142
ulint i, /* in: slot index == rseg id */
143
mtr_t* mtr) /* in: mtr */
146
ut_ad(mutex_own(&(kernel_mutex)));
147
ut_ad(i < TRX_SYS_N_RSEGS);
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));
154
/*********************************************************************
155
Sets the space id of the nth rollback segment slot in the trx system
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 */
166
ut_ad(mutex_own(&(kernel_mutex)));
168
ut_ad(i < TRX_SYS_N_RSEGS);
170
mlog_write_ulint(sys_header + TRX_SYS_RSEGS
171
+ i * TRX_SYS_RSEG_SLOT_SIZE
172
+ TRX_SYS_RSEG_SPACE,
177
/*********************************************************************
178
Sets the page number of the nth rollback segment slot in the trx system
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 */
190
ut_ad(mutex_own(&(kernel_mutex)));
192
ut_ad(i < TRX_SYS_N_RSEGS);
194
mlog_write_ulint(sys_header + TRX_SYS_RSEGS
195
+ i * TRX_SYS_RSEG_SLOT_SIZE
196
+ TRX_SYS_RSEG_PAGE_NO,
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
209
byte* ptr, /* in: pointer to memory where written */
210
dulint id) /* in: id */
212
#if DATA_TRX_ID_LEN != 6
213
# error "DATA_TRX_ID_LEN != 6"
215
mach_write_to_6(ptr, id);
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
227
const byte* ptr) /* in: pointer to memory from where to read */
229
#if DATA_TRX_ID_LEN != 6
230
# error "DATA_TRX_ID_LEN != 6"
232
return(mach_read_from_6(ptr));
235
/********************************************************************
236
Looks for the trx handle with the given id in trx_list. */
241
/* out: the trx handle or NULL if not found */
242
dulint trx_id) /* in: trx id to search for */
246
ut_ad(mutex_own(&(kernel_mutex)));
248
trx = UT_LIST_GET_FIRST(trx_sys->trx_list);
250
while (trx != NULL) {
251
if (0 == ut_dulint_cmp(trx_id, trx->id)) {
256
trx = UT_LIST_GET_NEXT(trx_list, trx);
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
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 */
276
ut_ad(mutex_own(&(kernel_mutex)));
278
trx = UT_LIST_GET_LAST(trx_sys->trx_list);
282
return(trx_sys->max_trx_id);
288
/********************************************************************
289
Checks if a transaction with the given id is active. */
294
/* out: TRUE if active */
295
dulint trx_id) /* in: trx id of the transaction */
299
ut_ad(mutex_own(&(kernel_mutex)));
301
if (ut_dulint_cmp(trx_id, trx_list_get_min_trx_id()) < 0) {
306
if (ut_dulint_cmp(trx_id, trx_sys->max_trx_id) >= 0) {
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 */
316
trx = trx_get_on_id(trx_id);
317
if (trx && (trx->conc_state == TRX_ACTIVE
318
|| trx->conc_state == TRX_PREPARED)) {
326
/*********************************************************************
327
Allocates a new transaction id. */
330
trx_sys_get_new_trx_id(void)
331
/*========================*/
332
/* out: new, allocated trx id */
336
ut_ad(mutex_own(&kernel_mutex));
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! */
345
if (ut_dulint_get_low(trx_sys->max_trx_id)
346
% TRX_SYS_TRX_ID_WRITE_MARGIN == 0) {
348
trx_sys_flush_max_trx_id();
351
id = trx_sys->max_trx_id;
353
UT_DULINT_INC(trx_sys->max_trx_id);
358
/*********************************************************************
359
Allocates a new transaction number. */
362
trx_sys_get_new_trx_no(void)
363
/*========================*/
364
/* out: new, allocated trx number */
366
ut_ad(mutex_own(&kernel_mutex));
368
return(trx_sys_get_new_trx_id());