~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/trx0trx.h

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
 
3
Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
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
 
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
15
St, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/******************************************************
 
19
/**************************************************//**
 
20
@file include/trx0trx.h
20
21
The transaction
21
22
 
22
23
Created 3/26/1996 Heikki Tuuri
27
28
 
28
29
#include "univ.i"
29
30
#include "trx0types.h"
 
31
#include "dict0types.h"
 
32
#ifndef UNIV_HOTBACKUP
30
33
#include "lock0types.h"
31
34
#include "usr0types.h"
32
35
#include "que0types.h"
33
36
#include "mem0mem.h"
34
37
#include "read0types.h"
35
 
#include "dict0types.h"
36
38
#include "trx0xa.h"
37
39
#include "ut0vec.h"
38
40
 
39
 
/* Dummy session used currently in MySQL interface */
 
41
namespace drizzled { class Session; }
 
42
 
 
43
/** Dummy session used currently in MySQL interface */
40
44
extern sess_t*  trx_dummy_sess;
41
45
 
42
 
/* Number of transactions currently allocated for MySQL: protected by
 
46
/** Number of transactions currently allocated for MySQL: protected by
43
47
the kernel mutex */
44
48
extern ulint    trx_n_mysql_transactions;
45
49
 
46
 
/*****************************************************************
47
 
Resets the new record lock info in a transaction struct. */
48
 
UNIV_INLINE
49
 
void
50
 
trx_reset_new_rec_lock_info(
51
 
/*========================*/
52
 
        trx_t*  trx);   /* in: transaction struct */
53
 
/*****************************************************************
54
 
Registers that we have set a new record lock on an index. We only have space
55
 
to store 2 indexes! If this is called to store more than 2 indexes after
56
 
trx_reset_new_rec_lock_info(), then this function does nothing. */
57
 
UNIV_INLINE
58
 
void
59
 
trx_register_new_rec_lock(
60
 
/*======================*/
61
 
        trx_t*          trx,    /* in: transaction struct */
62
 
        dict_index_t*   index); /* in: trx sets a new record lock on this
63
 
                                index */
64
 
/*****************************************************************
65
 
Checks if trx has set a new record lock on an index. */
66
 
UNIV_INLINE
67
 
ibool
68
 
trx_new_rec_locks_contain(
69
 
/*======================*/
70
 
                                /* out: TRUE if trx has set a new record lock
71
 
                                on index */
72
 
        trx_t*          trx,    /* in: transaction struct */
73
 
        dict_index_t*   index); /* in: index */
74
 
/************************************************************************
 
50
/********************************************************************//**
75
51
Releases the search latch if trx has reserved it. */
76
52
UNIV_INTERN
77
53
void
78
54
trx_search_latch_release_if_reserved(
79
55
/*=================================*/
80
 
        trx_t*     trx); /* in: transaction */
81
 
/**********************************************************************
 
56
        trx_t*     trx); /*!< in: transaction */
 
57
/******************************************************************//**
82
58
Set detailed error message for the transaction. */
83
59
UNIV_INTERN
84
60
void
85
61
trx_set_detailed_error(
86
62
/*===================*/
87
 
        trx_t*          trx,    /* in: transaction struct */
88
 
        const char*     msg);   /* in: detailed error message */
89
 
/*****************************************************************
 
63
        trx_t*          trx,    /*!< in: transaction struct */
 
64
        const char*     msg);   /*!< in: detailed error message */
 
65
/*************************************************************//**
90
66
Set detailed error message for the transaction from a file. Note that the
91
67
file is rewinded before reading from it. */
92
68
UNIV_INTERN
93
69
void
94
70
trx_set_detailed_error_from_file(
95
71
/*=============================*/
96
 
        trx_t*  trx,    /* in: transaction struct */
97
 
        FILE*   file);  /* in: file to read message from */
98
 
/********************************************************************
99
 
Retrieves the error_info field from a trx. */
 
72
        trx_t*  trx,    /*!< in: transaction struct */
 
73
        FILE*   file);  /*!< in: file to read message from */
 
74
/****************************************************************//**
 
75
Checks if the commit id should be logged to the sys header file
 
76
@return TRUE if the commit id should be logged */ 
 
77
UNIV_INLINE
 
78
ibool
 
79
trx_log_commit_id(
 
80
/*==============*/
 
81
        const trx_t*    trx);   /*!< in: trx object */
 
82
/****************************************************************//**
 
83
Retrieves the error_info field from a trx.
 
84
@return the error info */
100
85
UNIV_INLINE
101
86
const dict_index_t*
102
87
trx_get_error_info(
103
88
/*===============*/
104
 
                                /* out: the error info */
105
 
        const trx_t*    trx);   /* in: trx object */
106
 
/********************************************************************
107
 
Creates and initializes a transaction object. */
 
89
        const trx_t*    trx);   /*!< in: trx object */
 
90
/****************************************************************//**
 
91
Creates and initializes a transaction object.
 
92
@return own: the transaction */
108
93
UNIV_INTERN
109
94
trx_t*
110
95
trx_create(
111
96
/*=======*/
112
 
                        /* out, own: the transaction */
113
 
        sess_t* sess)   /* in: session */
 
97
        sess_t* sess)   /*!< in: session */
114
98
        __attribute__((nonnull));
115
 
/************************************************************************
116
 
Creates a transaction object for MySQL. */
 
99
/********************************************************************//**
 
100
Creates a transaction object for MySQL.
 
101
@return own: transaction object */
117
102
UNIV_INTERN
118
103
trx_t*
119
104
trx_allocate_for_mysql(void);
120
105
/*========================*/
121
 
                                /* out, own: transaction object */
122
 
/************************************************************************
123
 
Creates a transaction object for background operations by the master thread. */
 
106
/********************************************************************//**
 
107
Creates a transaction object for background operations by the master thread.
 
108
@return own: transaction object */
124
109
UNIV_INTERN
125
110
trx_t*
126
111
trx_allocate_for_background(void);
127
112
/*=============================*/
128
 
                                /* out, own: transaction object */
129
 
/************************************************************************
 
113
/********************************************************************//**
130
114
Frees a transaction object. */
131
115
UNIV_INTERN
132
116
void
133
117
trx_free(
134
118
/*=====*/
135
 
        trx_t*  trx);   /* in, own: trx object */
136
 
/************************************************************************
 
119
        trx_t*  trx);   /*!< in, own: trx object */
 
120
/********************************************************************//**
137
121
Frees a transaction object for MySQL. */
138
122
UNIV_INTERN
139
123
void
140
124
trx_free_for_mysql(
141
125
/*===============*/
142
 
        trx_t*  trx);   /* in, own: trx object */
143
 
/************************************************************************
 
126
        trx_t*  trx);   /*!< in, own: trx object */
 
127
/********************************************************************//**
144
128
Frees a transaction object of a background operation of the master thread. */
145
129
UNIV_INTERN
146
130
void
147
131
trx_free_for_background(
148
132
/*====================*/
149
 
        trx_t*  trx);   /* in, own: trx object */
150
 
/********************************************************************
 
133
        trx_t*  trx);   /*!< in, own: trx object */
 
134
/****************************************************************//**
151
135
Creates trx objects for transactions and initializes the trx list of
152
136
trx_sys at database start. Rollback segment and undo log lists must
153
137
already exist when this function is called, because the lists of
157
141
void
158
142
trx_lists_init_at_db_start(void);
159
143
/*============================*/
160
 
/********************************************************************
161
 
Starts a new transaction. */
 
144
/****************************************************************//**
 
145
Starts a new transaction.
 
146
@return TRUE if success, FALSE if the rollback segment could not
 
147
support this many transactions */
162
148
UNIV_INTERN
163
149
ibool
164
150
trx_start(
165
151
/*======*/
166
 
                        /* out: TRUE if success, FALSE if the rollback
167
 
                        segment could not support this many transactions */
168
 
        trx_t*  trx,    /* in: transaction */
169
 
        ulint   rseg_id);/* in: rollback segment id; if ULINT_UNDEFINED
 
152
        trx_t*  trx,    /*!< in: transaction */
 
153
        ulint   rseg_id);/*!< in: rollback segment id; if ULINT_UNDEFINED
170
154
                        is passed, the system chooses the rollback segment
171
155
                        automatically in a round-robin fashion */
172
 
/********************************************************************
173
 
Starts a new transaction. */
 
156
/****************************************************************//**
 
157
Starts a new transaction.
 
158
@return TRUE */
174
159
UNIV_INTERN
175
160
ibool
176
161
trx_start_low(
177
162
/*==========*/
178
 
                        /* out: TRUE */
179
 
        trx_t*  trx,    /* in: transaction */
180
 
        ulint   rseg_id);/* in: rollback segment id; if ULINT_UNDEFINED
 
163
        trx_t*  trx,    /*!< in: transaction */
 
164
        ulint   rseg_id);/*!< in: rollback segment id; if ULINT_UNDEFINED
181
165
                        is passed, the system chooses the rollback segment
182
166
                        automatically in a round-robin fashion */
183
 
/*****************************************************************
 
167
/*************************************************************//**
184
168
Starts the transaction if it is not yet started. */
185
169
UNIV_INLINE
186
170
void
187
171
trx_start_if_not_started(
188
172
/*=====================*/
189
 
        trx_t*  trx);   /* in: transaction */
190
 
/*****************************************************************
 
173
        trx_t*  trx);   /*!< in: transaction */
 
174
/*************************************************************//**
191
175
Starts the transaction if it is not yet started. Assumes we have reserved
192
176
the kernel mutex! */
193
177
UNIV_INLINE
194
178
void
195
179
trx_start_if_not_started_low(
196
180
/*=========================*/
197
 
        trx_t*  trx);   /* in: transaction */
198
 
/********************************************************************
 
181
        trx_t*  trx);   /*!< in: transaction */
 
182
/****************************************************************//**
199
183
Commits a transaction. */
200
184
UNIV_INTERN
201
185
void
202
186
trx_commit_off_kernel(
203
187
/*==================*/
204
 
        trx_t*  trx);   /* in: transaction */
205
 
/********************************************************************
 
188
        trx_t*  trx);   /*!< in: transaction */
 
189
/****************************************************************//**
206
190
Cleans up a transaction at database startup. The cleanup is needed if
207
191
the transaction already got to the middle of a commit when the database
208
 
crashed, andf we cannot roll it back. */
 
192
crashed, and we cannot roll it back. */
209
193
UNIV_INTERN
210
194
void
211
195
trx_cleanup_at_db_startup(
212
196
/*======================*/
213
 
        trx_t*  trx);   /* in: transaction */
214
 
/**************************************************************************
215
 
Does the transaction commit for MySQL. */
 
197
        trx_t*  trx);   /*!< in: transaction */
 
198
/**********************************************************************//**
 
199
Does the transaction commit for MySQL.
 
200
@return DB_SUCCESS or error number */
216
201
UNIV_INTERN
217
202
ulint
218
203
trx_commit_for_mysql(
219
204
/*=================*/
220
 
                        /* out: DB_SUCCESS or error number */
221
 
        trx_t*  trx);   /* in: trx handle */
222
 
/**************************************************************************
223
 
Does the transaction prepare for MySQL. */
 
205
        trx_t*  trx);   /*!< in: trx handle */
 
206
/**********************************************************************//**
 
207
Does the transaction prepare for MySQL.
 
208
@return 0 or error number */
224
209
UNIV_INTERN
225
210
ulint
226
211
trx_prepare_for_mysql(
227
212
/*==================*/
228
 
                        /* out: 0 or error number */
229
 
        trx_t*  trx);   /* in: trx handle */
230
 
/**************************************************************************
 
213
        trx_t*  trx);   /*!< in: trx handle */
 
214
/**********************************************************************//**
231
215
This function is used to find number of prepared transactions and
232
 
their transaction objects for a recovery. */
 
216
their transaction objects for a recovery.
 
217
@return number of prepared transactions */
233
218
UNIV_INTERN
234
219
int
235
220
trx_recover_for_mysql(
236
221
/*==================*/
237
 
                                /* out: number of prepared transactions */
238
 
        XID*    xid_list,       /* in/out: prepared transactions */
239
 
        ulint   len);           /* in: number of slots in xid_list */
240
 
/***********************************************************************
 
222
        XID*    xid_list,       /*!< in/out: prepared transactions */
 
223
        ulint   len);           /*!< in: number of slots in xid_list */
 
224
/*******************************************************************//**
241
225
This function is used to find one X/Open XA distributed transaction
242
 
which is in the prepared state */
 
226
which is in the prepared state
 
227
@return trx or NULL */
243
228
UNIV_INTERN
244
229
trx_t *
245
230
trx_get_trx_by_xid(
246
231
/*===============*/
247
 
                        /* out: trx or NULL */
248
 
        XID*    xid);   /*  in: X/Open XA transaction identification */
249
 
/**************************************************************************
 
232
        XID*    xid);   /*!< in: X/Open XA transaction identification */
 
233
/**********************************************************************//**
250
234
If required, flushes the log to disk if we called trx_commit_for_mysql()
251
 
with trx->flush_log_later == TRUE. */
 
235
with trx->flush_log_later == TRUE.
 
236
@return 0 or error number */
252
237
UNIV_INTERN
253
238
ulint
254
239
trx_commit_complete_for_mysql(
255
240
/*==========================*/
256
 
                        /* out: 0 or error number */
257
 
        trx_t*  trx);   /* in: trx handle */
258
 
/**************************************************************************
 
241
        trx_t*  trx);   /*!< in: trx handle */
 
242
/**********************************************************************//**
259
243
Marks the latest SQL statement ended. */
260
244
UNIV_INTERN
261
245
void
262
246
trx_mark_sql_stat_end(
263
247
/*==================*/
264
 
        trx_t*  trx);   /* in: trx handle */
265
 
/************************************************************************
 
248
        trx_t*  trx);   /*!< in: trx handle */
 
249
/********************************************************************//**
266
250
Assigns a read view for a consistent read query. All the consistent reads
267
251
within the same transaction will get the same read view, which is created
268
 
when this function is first called for a new started transaction. */
 
252
when this function is first called for a new started transaction.
 
253
@return consistent read view */
269
254
UNIV_INTERN
270
255
read_view_t*
271
256
trx_assign_read_view(
272
257
/*=================*/
273
 
                        /* out: consistent read view */
274
 
        trx_t*  trx);   /* in: active transaction */
275
 
/***************************************************************
 
258
        trx_t*  trx);   /*!< in: active transaction */
 
259
/***********************************************************//**
276
260
The transaction must be in the TRX_QUE_LOCK_WAIT state. Puts it to
277
261
the TRX_QUE_RUNNING state and releases query threads which were
278
262
waiting for a lock in the wait_thrs list. */
280
264
void
281
265
trx_end_lock_wait(
282
266
/*==============*/
283
 
        trx_t*  trx);   /* in: transaction */
284
 
/********************************************************************
 
267
        trx_t*  trx);   /*!< in: transaction */
 
268
/****************************************************************//**
285
269
Sends a signal to a trx object. */
286
270
UNIV_INTERN
287
271
void
288
272
trx_sig_send(
289
273
/*=========*/
290
 
        trx_t*          trx,            /* in: trx handle */
291
 
        ulint           type,           /* in: signal type */
292
 
        ulint           sender,         /* in: TRX_SIG_SELF or
 
274
        trx_t*          trx,            /*!< in: trx handle */
 
275
        ulint           type,           /*!< in: signal type */
 
276
        ulint           sender,         /*!< in: TRX_SIG_SELF or
293
277
                                        TRX_SIG_OTHER_SESS */
294
 
        que_thr_t*      receiver_thr,   /* in: query thread which wants the
 
278
        que_thr_t*      receiver_thr,   /*!< in: query thread which wants the
295
279
                                        reply, or NULL; if type is
296
280
                                        TRX_SIG_END_WAIT, this must be NULL */
297
 
        trx_savept_t*   savept,         /* in: possible rollback savepoint, or
 
281
        trx_savept_t*   savept,         /*!< in: possible rollback savepoint, or
298
282
                                        NULL */
299
 
        que_thr_t**     next_thr);      /* in/out: next query thread to run;
 
283
        que_thr_t**     next_thr);      /*!< in/out: next query thread to run;
300
284
                                        if the value which is passed in is
301
285
                                        a pointer to a NULL pointer, then the
302
286
                                        calling function can start running
303
287
                                        a new query thread; if the parameter
304
288
                                        is NULL, it is ignored */
305
 
/********************************************************************
 
289
/****************************************************************//**
306
290
Send the reply message when a signal in the queue of the trx has
307
291
been handled. */
308
292
UNIV_INTERN
309
293
void
310
294
trx_sig_reply(
311
295
/*==========*/
312
 
        trx_sig_t*      sig,            /* in: signal */
313
 
        que_thr_t**     next_thr);      /* in/out: next query thread to run;
 
296
        trx_sig_t*      sig,            /*!< in: signal */
 
297
        que_thr_t**     next_thr);      /*!< in/out: next query thread to run;
314
298
                                        if the value which is passed in is
315
299
                                        a pointer to a NULL pointer, then the
316
300
                                        calling function can start running
317
301
                                        a new query thread */
318
 
/********************************************************************
 
302
/****************************************************************//**
319
303
Removes the signal object from a trx signal queue. */
320
304
UNIV_INTERN
321
305
void
322
306
trx_sig_remove(
323
307
/*===========*/
324
 
        trx_t*          trx,    /* in: trx handle */
325
 
        trx_sig_t*      sig);   /* in, own: signal */
326
 
/********************************************************************
 
308
        trx_t*          trx,    /*!< in: trx handle */
 
309
        trx_sig_t*      sig);   /*!< in, own: signal */
 
310
/****************************************************************//**
327
311
Starts handling of a trx signal. */
328
312
UNIV_INTERN
329
313
void
330
314
trx_sig_start_handle(
331
315
/*=================*/
332
 
        trx_t*          trx,            /* in: trx handle */
333
 
        que_thr_t**     next_thr);      /* in/out: next query thread to run;
 
316
        trx_t*          trx,            /*!< in: trx handle */
 
317
        que_thr_t**     next_thr);      /*!< in/out: next query thread to run;
334
318
                                        if the value which is passed in is
335
319
                                        a pointer to a NULL pointer, then the
336
320
                                        calling function can start running
337
321
                                        a new query thread */
338
 
/********************************************************************
 
322
/****************************************************************//**
339
323
Ends signal handling. If the session is in the error state, and
340
324
trx->graph_before_signal_handling != NULL, returns control to the error
341
325
handling routine of the graph (currently only returns the control to the
344
328
void
345
329
trx_end_signal_handling(
346
330
/*====================*/
347
 
        trx_t*  trx);   /* in: trx */
348
 
/*************************************************************************
349
 
Creates a commit command node struct. */
 
331
        trx_t*  trx);   /*!< in: trx */
 
332
/*********************************************************************//**
 
333
Creates a commit command node struct.
 
334
@return own: commit node struct */
350
335
UNIV_INTERN
351
336
commit_node_t*
352
337
commit_node_create(
353
338
/*===============*/
354
 
                                /* out, own: commit node struct */
355
 
        mem_heap_t*     heap);  /* in: mem heap where created */
356
 
/***************************************************************
357
 
Performs an execution step for a commit type node in a query graph. */
 
339
        mem_heap_t*     heap);  /*!< in: mem heap where created */
 
340
/***********************************************************//**
 
341
Performs an execution step for a commit type node in a query graph.
 
342
@return query thread to run next, or NULL */
358
343
UNIV_INTERN
359
344
que_thr_t*
360
345
trx_commit_step(
361
346
/*============*/
362
 
                                /* out: query thread to run next, or NULL */
363
 
        que_thr_t*      thr);   /* in: query thread */
 
347
        que_thr_t*      thr);   /*!< in: query thread */
364
348
 
365
 
/**************************************************************************
 
349
/**********************************************************************//**
366
350
Prints info about a transaction to the given file. The caller must own the
367
 
kernel mutex and must have called
368
 
innobase_mysql_prepare_print_arbitrary_thd(), unless he knows that MySQL
369
 
or InnoDB cannot meanwhile change the info printed here. */
 
351
kernel mutex. */
370
352
UNIV_INTERN
371
353
void
372
354
trx_print(
373
355
/*======*/
374
 
        FILE*   f,              /* in: output stream */
375
 
        trx_t*  trx,            /* in: transaction */
376
 
        ulint   max_query_len); /* in: max query length to print, or 0 to
 
356
        FILE*   f,              /*!< in: output stream */
 
357
        trx_t*  trx,            /*!< in: transaction */
 
358
        ulint   max_query_len); /*!< in: max query length to print, or 0 to
377
359
                                   use the default max length */
378
360
 
379
361
/** Type of data dictionary operation */
380
 
enum trx_dict_op {
 
362
typedef enum trx_dict_op {
381
363
        /** The transaction is not modifying the data dictionary. */
382
364
        TRX_DICT_OP_NONE = 0,
383
365
        /** The transaction is creating a table or an index, or
389
371
        existing table.  In crash recovery, the the data dictionary
390
372
        must be locked, but the table must not be dropped. */
391
373
        TRX_DICT_OP_INDEX = 2
392
 
};
 
374
} trx_dict_op_t;
393
375
 
394
 
/**************************************************************************
395
 
Determine if a transaction is a dictionary operation. */
 
376
/**********************************************************************//**
 
377
Determine if a transaction is a dictionary operation.
 
378
@return dictionary operation mode */
396
379
UNIV_INLINE
397
380
enum trx_dict_op
398
381
trx_get_dict_operation(
399
382
/*===================*/
400
 
                                /* out: dictionary operation mode */
401
 
        const trx_t*    trx)    /* in: transaction */
 
383
        const trx_t*    trx)    /*!< in: transaction */
402
384
        __attribute__((pure));
403
 
/**************************************************************************
 
385
/**********************************************************************//**
404
386
Flag a transaction a dictionary operation. */
405
387
UNIV_INLINE
406
388
void
407
389
trx_set_dict_operation(
408
390
/*===================*/
409
 
        trx_t*                  trx,    /* in/out: transaction */
410
 
        enum trx_dict_op        op);    /* in: operation, not
 
391
        trx_t*                  trx,    /*!< in/out: transaction */
 
392
        enum trx_dict_op        op);    /*!< in: operation, not
411
393
                                        TRX_DICT_OP_NONE */
412
394
 
413
395
#ifndef UNIV_HOTBACKUP
414
 
/**************************************************************************
415
 
Determines if the currently running transaction has been interrupted. */
 
396
/**********************************************************************//**
 
397
Determines if the currently running transaction has been interrupted.
 
398
@return TRUE if interrupted */
416
399
UNIV_INTERN
417
400
ibool
418
401
trx_is_interrupted(
419
402
/*===============*/
420
 
                        /* out: TRUE if interrupted */
421
 
        trx_t*  trx);   /* in: transaction */
 
403
        trx_t*  trx);   /*!< in: transaction */
 
404
/**********************************************************************//**
 
405
Determines if the currently running transaction is in strict mode.
 
406
@return TRUE if strict */
 
407
UNIV_INTERN
 
408
ibool
 
409
trx_is_strict(
 
410
/*==========*/
 
411
        trx_t*  trx);   /*!< in: transaction */
422
412
#else /* !UNIV_HOTBACKUP */
423
413
#define trx_is_interrupted(trx) FALSE
424
414
#endif /* !UNIV_HOTBACKUP */
425
415
 
426
 
/***********************************************************************
 
416
/*******************************************************************//**
427
417
Calculates the "weight" of a transaction. The weight of one transaction
428
418
is estimated as the number of altered rows + the number of locked rows.
429
 
*/
430
 
 
431
 
#define TRX_WEIGHT(t)   \
432
 
        ut_dulint_add((t)->undo_no, UT_LIST_GET_LEN((t)->trx_locks))
433
 
 
434
 
/***********************************************************************
 
419
@param t        transaction
 
420
@return         transaction weight */
 
421
#define TRX_WEIGHT(t)   ((t)->undo_no + UT_LIST_GET_LEN((t)->trx_locks))
 
422
 
 
423
/*******************************************************************//**
435
424
Compares the "weight" (or size) of two transactions. Transactions that
436
425
have edited non-transactional tables are considered heavier than ones
437
 
that have not. */
 
426
that have not.
 
427
@return TRUE if weight(a) >= weight(b) */
438
428
UNIV_INTERN
439
 
int
440
 
trx_weight_cmp(
441
 
/*===========*/
442
 
                                /* out: <0, 0 or >0; similar to strcmp(3) */
443
 
        const trx_t*    a,      /* in: the first transaction to be compared */
444
 
        const trx_t*    b);     /* in: the second transaction to be compared */
445
 
 
446
 
/***********************************************************************
447
 
Retrieves transacion's id, represented as unsigned long long. */
448
 
UNIV_INLINE
449
 
ullint
450
 
trx_get_id(
451
 
/*=======*/
452
 
                                /* out: transaction's id */
453
 
        const trx_t*    trx);   /* in: transaction */
 
429
ibool
 
430
trx_weight_ge(
 
431
/*==========*/
 
432
        const trx_t*    a,      /*!< in: the first transaction to be compared */
 
433
        const trx_t*    b);     /*!< in: the second transaction to be compared */
454
434
 
455
435
/* Maximum length of a string that can be returned by
456
436
trx_get_que_state_str(). */
457
437
#define TRX_QUE_STATE_STR_MAX_LEN       12 /* "ROLLING BACK" */
458
438
 
459
 
/***********************************************************************
 
439
/*******************************************************************//**
460
440
Retrieves transaction's que state in a human readable string. The string
461
 
should not be free()'d or modified. */
 
441
should not be free()'d or modified.
 
442
@return string in the data segment */
462
443
UNIV_INLINE
463
444
const char*
464
445
trx_get_que_state_str(
465
446
/*==================*/
466
 
                                /* out: string in the data segment */
467
 
        const trx_t*    trx);   /* in: transaction */
 
447
        const trx_t*    trx);   /*!< in: transaction */
468
448
 
469
449
/* Signal to a transaction */
470
450
struct trx_sig_struct{
471
 
        unsigned        type:3;         /* signal type */
472
 
        unsigned        sender:1;       /* TRX_SIG_SELF or
 
451
        unsigned        type:3;         /*!< signal type */
 
452
        unsigned        sender:1;       /*!< TRX_SIG_SELF or
473
453
                                        TRX_SIG_OTHER_SESS */
474
 
        que_thr_t*      receiver;       /* non-NULL if the sender of the signal
 
454
        que_thr_t*      receiver;       /*!< non-NULL if the sender of the signal
475
455
                                        wants reply after the operation induced
476
456
                                        by the signal is completed */
477
 
        trx_savept_t    savept;         /* possible rollback savepoint */
 
457
        trx_savept_t    savept;         /*!< possible rollback savepoint */
478
458
        UT_LIST_NODE_T(trx_sig_t)
479
 
                        signals;        /* queue of pending signals to the
 
459
                        signals;        /*!< queue of pending signals to the
480
460
                                        transaction */
481
461
        UT_LIST_NODE_T(trx_sig_t)
482
 
                        reply_signals;  /* list of signals for which the sender
 
462
                        reply_signals;  /*!< list of signals for which the sender
483
463
                                        transaction is waiting a reply */
484
464
};
485
465
 
491
471
 
492
472
struct trx_struct{
493
473
        ulint           magic_n;
494
 
        /* All the next fields are protected by the kernel mutex, except the
495
 
        undo logs which are protected by undo_mutex */
496
 
        const char*     op_info;        /* English text describing the
 
474
 
 
475
        /* These fields are not protected by any mutex. */
 
476
        const char*     op_info;        /*!< English text describing the
497
477
                                        current operation, or an empty
498
478
                                        string */
499
 
        unsigned        is_purge:1;     /* 0=user transaction, 1=purge */
500
 
        unsigned        is_recovered:1; /* 0=normal transaction,
501
 
                                        1=recovered, must be rolled back */
502
 
        unsigned        conc_state:2;   /* state of the trx from the point
 
479
        ulint           conc_state;     /*!< state of the trx from the point
503
480
                                        of view of concurrency control:
504
481
                                        TRX_ACTIVE, TRX_COMMITTED_IN_MEMORY,
505
482
                                        ... */
506
 
        unsigned        que_state:2;    /* valid when conc_state == TRX_ACTIVE:
507
 
                                        TRX_QUE_RUNNING, TRX_QUE_LOCK_WAIT,
508
 
                                        ... */
509
 
        unsigned        isolation_level:2;/* TRX_ISO_REPEATABLE_READ, ... */
510
 
        unsigned        check_foreigns:1;/* normally TRUE, but if the user
 
483
        ulint           isolation_level;/* TRX_ISO_REPEATABLE_READ, ... */
 
484
        ulint           check_foreigns; /* normally TRUE, but if the user
511
485
                                        wants to suppress foreign key checks,
512
486
                                        (in table imports, for example) we
513
487
                                        set this FALSE */
514
 
        unsigned        check_unique_secondary:1;
 
488
        unsigned        check_unique_secondary;
515
489
                                        /* normally TRUE, but if the user
516
490
                                        wants to speed up inserts by
517
491
                                        suppressing unique key checks
518
492
                                        for secondary indexes when we decide
519
493
                                        if we can use the insert buffer for
520
494
                                        them, we set this FALSE */
521
 
        unsigned        support_xa:1;   /* normally we do the XA two-phase
 
495
        unsigned        support_xa;     /*!< normally we do the XA two-phase
522
496
                                        commit steps, but by setting this to
523
497
                                        FALSE, one can save CPU time and about
524
498
                                        150 bytes in the undo log size as then
525
499
                                        we skip XA steps */
526
 
        unsigned        flush_log_later:1;/* when we commit the transaction
527
 
                                        in MySQL's binlog write, we will
528
 
                                        flush the log to disk later in
529
 
                                        a separate call */
530
 
        unsigned        must_flush_log_later:1;/* this flag is set to TRUE in
 
500
        unsigned        flush_log_later;/* In 2PC, we hold the
 
501
                                        prepare_commit mutex across
 
502
                                        both phases. In that case, we
 
503
                                        defer flush of the logs to disk
 
504
                                        until after we release the
 
505
                                        mutex. */
 
506
        unsigned        must_flush_log_later;/* this flag is set to TRUE in
531
507
                                        trx_commit_off_kernel() if
532
508
                                        flush_log_later was TRUE, and there
533
509
                                        were modifications by the transaction;
534
510
                                        in that case we must flush the log
535
511
                                        in trx_commit_complete_for_mysql() */
536
 
        unsigned        dict_operation:2;/**< @see enum trx_dict_op */
537
 
        unsigned        duplicates:2;   /* TRX_DUP_IGNORE | TRX_DUP_REPLACE */
538
 
        unsigned        active_trans:2; /* 1 - if a transaction in MySQL
539
 
                                        is active. 2 - if prepare_commit_mutex
540
 
                                        was taken */
541
 
        unsigned        has_search_latch:1;
 
512
        ulint           duplicates;     /*!< TRX_DUP_IGNORE | TRX_DUP_REPLACE */
 
513
        unsigned        has_search_latch;
542
514
                                        /* TRUE if this trx has latched the
543
515
                                        search system latch in S-mode */
544
 
        unsigned        declared_to_be_inside_innodb:1;
 
516
        ulint           deadlock_mark;  /*!< a mark field used in deadlock
 
517
                                        checking algorithm.  */
 
518
        trx_dict_op_t   dict_operation; /**< @see enum trx_dict_op */
 
519
 
 
520
        /* Fields protected by the srv_conc_mutex. */
 
521
        ulint           declared_to_be_inside_innodb;
545
522
                                        /* this is TRUE if we have declared
546
523
                                        this transaction in
547
524
                                        srv_conc_enter_innodb to be inside the
548
525
                                        InnoDB engine */
549
 
        unsigned        handling_signals:1;/* this is TRUE as long as the trx
550
 
                                        is handling signals */
551
 
        unsigned        dict_operation_lock_mode:2;
552
 
                                        /* 0, RW_S_LATCH, or RW_X_LATCH:
 
526
 
 
527
        /* Fields protected by dict_operation_lock. The very latch
 
528
        it is used to track. */
 
529
        ulint           dict_operation_lock_mode;
 
530
                                        /*!< 0, RW_S_LATCH, or RW_X_LATCH:
553
531
                                        the latch mode trx currently holds
554
532
                                        on dict_operation_lock */
555
 
        time_t          start_time;     /* time the trx object was created
 
533
 
 
534
        /* All the next fields are protected by the kernel mutex, except the
 
535
        undo logs which are protected by undo_mutex */
 
536
        ulint           is_purge;       /*!< 0=user transaction, 1=purge */
 
537
        ulint           is_recovered;   /*!< 0=normal transaction,
 
538
                                        1=recovered, must be rolled back */
 
539
        ulint           que_state;      /*!< valid when conc_state
 
540
                                        == TRX_ACTIVE: TRX_QUE_RUNNING,
 
541
                                        TRX_QUE_LOCK_WAIT, ... */
 
542
        ulint           handling_signals;/* this is TRUE as long as the trx
 
543
                                        is handling signals */
 
544
        time_t          start_time;     /*!< time the trx object was created
556
545
                                        or the state last time became
557
546
                                        TRX_ACTIVE */
558
 
        dulint          id;             /* transaction id */
559
 
        XID             xid;            /* X/Open XA transaction
 
547
        trx_id_t        id;             /*!< transaction id */
 
548
        XID             xid;            /*!< X/Open XA transaction
560
549
                                        identification to identify a
561
550
                                        transaction branch */
562
 
        dulint          no;             /* transaction serialization number ==
 
551
        trx_id_t        no;             /*!< transaction serialization number ==
563
552
                                        max trx id when the transaction is
564
553
                                        moved to COMMITTED_IN_MEMORY state */
565
 
        ib_uint64_t     commit_lsn;     /* lsn at the time of the commit */
566
 
        dulint          table_id;       /* Table to drop iff dict_operation
567
 
                                        is TRUE, or ut_dulint_zero. */
 
554
        ib_uint64_t     commit_lsn;     /*!< lsn at the time of the commit */
 
555
        table_id_t      table_id;       /*!< Table to drop iff dict_operation
 
556
                                        is TRUE, or 0. */
568
557
        /*------------------------------*/
569
 
        void*           mysql_thd;      /* MySQL thread handle corresponding
 
558
        drizzled::Session *mysql_thd;   /*!< MySQL thread handle corresponding
570
559
                                        to this trx, or NULL */
571
 
        char**          mysql_query_str;/* pointer to the field in mysqld_thd
572
 
                                        which contains the pointer to the
573
 
                                        current SQL query string */
574
560
        const char*     mysql_log_file_name;
575
561
                                        /* if MySQL binlog is used, this field
576
562
                                        contains a pointer to the latest file
584
570
        ulint           mysql_process_no;/* since in Linux, 'top' reports
585
571
                                        process id's and not thread id's, we
586
572
                                        store the process number too */
587
 
        /*------------------------------*/
588
 
        ulint           n_mysql_tables_in_use; /* number of Innobase tables
589
 
                                        used in the processing of the current
590
 
                                        SQL statement in MySQL */
591
573
        ulint           mysql_n_tables_locked;
592
574
                                        /* how many tables the current SQL
593
575
                                        statement uses, except those
609
591
                                        to srv_conc_innodb_enter, if the value
610
592
                                        here is > 0, we decrement this by 1 */
611
593
        /*------------------------------*/
612
 
        dict_index_t*   new_rec_locks[2];/* these are normally NULL; if
613
 
                                        srv_locks_unsafe_for_binlog is TRUE
614
 
                                        or session is using READ COMMITTED
615
 
                                        isolation level,
616
 
                                        in a cursor search, if we set a new
617
 
                                        record lock on an index, this is set
618
 
                                        to point to the index; this is
619
 
                                        used in releasing the locks under the
620
 
                                        cursors if we are performing an UPDATE
621
 
                                        and we determine after retrieving
622
 
                                        the row that it does not need to be
623
 
                                        locked; thus, these can be used to
624
 
                                        implement a 'mini-rollback' that
625
 
                                        releases the latest record locks */
626
 
        UT_LIST_NODE_T(trx_t)
627
 
                        trx_list;       /* list of transactions */
628
 
        UT_LIST_NODE_T(trx_t)
629
 
                        mysql_trx_list; /* list of transactions created for
 
594
        UT_LIST_NODE_T(trx_t)
 
595
                        trx_list;       /*!< list of transactions */
 
596
        UT_LIST_NODE_T(trx_t)
 
597
                        mysql_trx_list; /*!< list of transactions created for
630
598
                                        MySQL */
631
599
        /*------------------------------*/
632
 
        ulint           error_state;    /* 0 if no error, otherwise error
 
600
        ulint           error_state;    /*!< 0 if no error, otherwise error
633
601
                                        number; NOTE That ONLY the thread
634
602
                                        doing the transaction is allowed to
635
603
                                        set this field: this is NOT protected
636
604
                                        by the kernel mutex */
637
 
        const dict_index_t*error_info;  /* if the error number indicates a
 
605
        const dict_index_t*error_info;  /*!< if the error number indicates a
638
606
                                        duplicate key error, a pointer to
639
607
                                        the problematic index is stored here */
640
 
        ulint           error_key_num;  /* if the index creation fails to a
 
608
        ulint           error_key_num;  /*!< if the index creation fails to a
641
609
                                        duplicate key error, a mysql key
642
610
                                        number of that index is stored here */
643
 
        sess_t*         sess;           /* session of the trx, NULL if none */
644
 
        que_t*          graph;          /* query currently run in the session,
 
611
        sess_t*         sess;           /*!< session of the trx, NULL if none */
 
612
        que_t*          graph;          /*!< query currently run in the session,
645
613
                                        or NULL if none; NOTE that the query
646
614
                                        belongs to the session, and it can
647
615
                                        survive over a transaction commit, if
648
616
                                        it is a stored procedure with a COMMIT
649
617
                                        WORK statement, for instance */
650
 
        ulint           n_active_thrs;  /* number of active query threads */
 
618
        ulint           n_active_thrs;  /*!< number of active query threads */
651
619
        que_t*          graph_before_signal_handling;
652
620
                                        /* value of graph when signal handling
653
621
                                        for this trx started: this is used to
654
622
                                        return control to the original query
655
623
                                        graph for error processing */
656
 
        trx_sig_t       sig;            /* one signal object can be allocated
 
624
        trx_sig_t       sig;            /*!< one signal object can be allocated
657
625
                                        in this space, avoiding mem_alloc */
658
626
        UT_LIST_BASE_NODE_T(trx_sig_t)
659
 
                        signals;        /* queue of processed or pending
 
627
                        signals;        /*!< queue of processed or pending
660
628
                                        signals to the trx */
661
629
        UT_LIST_BASE_NODE_T(trx_sig_t)
662
 
                        reply_signals;  /* list of signals sent by the query
 
630
                        reply_signals;  /*!< list of signals sent by the query
663
631
                                        threads of this trx for which a thread
664
632
                                        is waiting for a reply; if this trx is
665
633
                                        killed, the reply requests in the list
666
634
                                        must be canceled */
667
635
        /*------------------------------*/
668
 
        lock_t*         wait_lock;      /* if trx execution state is
 
636
        lock_t*         wait_lock;      /*!< if trx execution state is
669
637
                                        TRX_QUE_LOCK_WAIT, this points to
670
638
                                        the lock request, otherwise this is
671
639
                                        NULL */
675
643
                                        if another transaction chooses this
676
644
                                        transaction as a victim in deadlock
677
645
                                        resolution, it sets this to TRUE */
678
 
        time_t          wait_started;   /* lock wait started at this time */
 
646
        time_t          wait_started;   /*!< lock wait started at this time */
679
647
        UT_LIST_BASE_NODE_T(que_thr_t)
680
 
                        wait_thrs;      /* query threads belonging to this
 
648
                        wait_thrs;      /*!< query threads belonging to this
681
649
                                        trx that are in the QUE_THR_LOCK_WAIT
682
650
                                        state */
683
 
        ulint           deadlock_mark;  /* a mark field used in deadlock
684
 
                                        checking algorithm.  This must be
685
 
                                        in its own machine word, because
686
 
                                        it can be changed by other
687
 
                                        threads while holding kernel_mutex. */
688
651
        /*------------------------------*/
689
 
        mem_heap_t*     lock_heap;      /* memory heap for the locks of the
 
652
        mem_heap_t*     lock_heap;      /*!< memory heap for the locks of the
690
653
                                        transaction */
691
654
        UT_LIST_BASE_NODE_T(lock_t)
692
 
                        trx_locks;      /* locks reserved by the transaction */
 
655
                        trx_locks;      /*!< locks reserved by the transaction */
693
656
        /*------------------------------*/
694
657
        mem_heap_t*     global_read_view_heap;
695
658
                                        /* memory heap for the global read
697
660
        read_view_t*    global_read_view;
698
661
                                        /* consistent read view associated
699
662
                                        to a transaction or NULL */
700
 
        read_view_t*    read_view;      /* consistent read view used in the
 
663
        read_view_t*    read_view;      /*!< consistent read view used in the
701
664
                                        transaction or NULL, this read view
702
665
                                        if defined can be normal read view
703
666
                                        associated to a transaction (i.e.
705
668
                                        associated to a cursor */
706
669
        /*------------------------------*/
707
670
        UT_LIST_BASE_NODE_T(trx_named_savept_t)
708
 
                        trx_savepoints; /* savepoints set with SAVEPOINT ...,
 
671
                        trx_savepoints; /*!< savepoints set with SAVEPOINT ...,
709
672
                                        oldest first */
710
673
        /*------------------------------*/
711
 
        mutex_t         undo_mutex;     /* mutex protecting the fields in this
 
674
        mutex_t         undo_mutex;     /*!< mutex protecting the fields in this
712
675
                                        section (down to undo_no_arr), EXCEPT
713
676
                                        last_sql_stat_start, which can be
714
677
                                        accessed only when we know that there
715
678
                                        cannot be any activity in the undo
716
679
                                        logs! */
717
 
        dulint          undo_no;        /* next undo log record number to
 
680
        undo_no_t       undo_no;        /*!< next undo log record number to
718
681
                                        assign; since the undo log is
719
682
                                        private for a transaction, this
720
683
                                        is a simple ascending sequence
726
689
                                        was started: in case of an error, trx
727
690
                                        is rolled back down to this undo
728
691
                                        number; see note at undo_mutex! */
729
 
        trx_rseg_t*     rseg;           /* rollback segment assigned to the
 
692
        trx_rseg_t*     rseg;           /*!< rollback segment assigned to the
730
693
                                        transaction, or NULL if not assigned
731
694
                                        yet */
732
 
        trx_undo_t*     insert_undo;    /* pointer to the insert undo log, or
 
695
        trx_undo_t*     insert_undo;    /*!< pointer to the insert undo log, or
733
696
                                        NULL if no inserts performed yet */
734
 
        trx_undo_t*     update_undo;    /* pointer to the update undo log, or
 
697
        trx_undo_t*     update_undo;    /*!< pointer to the update undo log, or
735
698
                                        NULL if no update performed yet */
736
 
        dulint          roll_limit;     /* least undo number to undo during
 
699
        undo_no_t       roll_limit;     /*!< least undo number to undo during
737
700
                                        a rollback */
738
 
        ulint           pages_undone;   /* number of undo log pages undone
 
701
        ulint           pages_undone;   /*!< number of undo log pages undone
739
702
                                        since the last undo log truncation */
740
 
        trx_undo_arr_t* undo_no_arr;    /* array of undo numbers of undo log
 
703
        trx_undo_arr_t* undo_no_arr;    /*!< array of undo numbers of undo log
741
704
                                        records which are currently processed
742
705
                                        by a rollback operation */
743
706
        /*------------------------------*/
744
 
        ulint           n_autoinc_rows; /* no. of AUTO-INC rows required for
 
707
        ulint           n_autoinc_rows; /*!< no. of AUTO-INC rows required for
745
708
                                        an SQL statement. This is useful for
746
709
                                        multi-row INSERTs */
747
710
        ib_vector_t*    autoinc_locks;  /* AUTOINC locks held by this
750
713
                                        vector needs to be freed explicitly
751
714
                                        when the trx_t instance is desrtoyed */
752
715
        /*------------------------------*/
753
 
        char detailed_error[256];       /* detailed error message for last
 
716
        char detailed_error[256];       /*!< detailed error message for last
754
717
                                        error, or empty. */
 
718
 
 
719
        ibool           log_commit_id;  /*!< log the commit id to the sys
 
720
                                        file */
 
721
        inline drizzled::Session *session()
 
722
        {
 
723
          return mysql_thd;
 
724
        }
 
725
        inline drizzled::Session *session() const
 
726
        {
 
727
          return mysql_thd;
 
728
        }
755
729
};
756
730
 
757
731
#define TRX_MAX_N_THREADS       32      /* maximum number of
827
801
#define TRX_SIG_OTHER_SESS      1       /* sent by another session (which
828
802
                                        must hold rights to this) */
829
803
 
830
 
/* Commit command node in a query graph */
 
804
/** Commit node states */
 
805
enum commit_node_state {
 
806
        COMMIT_NODE_SEND = 1,   /*!< about to send a commit signal to
 
807
                                the transaction */
 
808
        COMMIT_NODE_WAIT        /*!< commit signal sent to the transaction,
 
809
                                waiting for completion */
 
810
};
 
811
 
 
812
/** Commit command node in a query graph */
831
813
struct commit_node_struct{
832
 
        que_common_t    common; /* node type: QUE_NODE_COMMIT */
833
 
        ulint           state;  /* node execution state */
 
814
        que_common_t    common; /*!< node type: QUE_NODE_COMMIT */
 
815
        enum commit_node_state
 
816
                        state;  /*!< node execution state */
834
817
};
835
818
 
836
 
/* Commit node states */
837
 
#define COMMIT_NODE_SEND        1
838
 
#define COMMIT_NODE_WAIT        2
839
819
 
840
820
 
841
821
#ifndef UNIV_NONINL
842
822
#include "trx0trx.ic"
843
823
#endif
 
824
#endif /* !UNIV_HOTBACKUP */
844
825
 
845
826
#endif