~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merge Stewart's dead code removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1996, 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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/trx0trx.h
21
 
The transaction
22
 
 
23
 
Created 3/26/1996 Heikki Tuuri
24
 
*******************************************************/
25
 
 
26
 
#ifndef trx0trx_h
27
 
#define trx0trx_h
28
 
 
29
 
#include "univ.i"
30
 
#include "trx0types.h"
31
 
#include "dict0types.h"
32
 
#ifndef UNIV_HOTBACKUP
33
 
#include "lock0types.h"
34
 
#include "usr0types.h"
35
 
#include "que0types.h"
36
 
#include "mem0mem.h"
37
 
#include "read0types.h"
38
 
#include "trx0xa.h"
39
 
#include "ut0vec.h"
40
 
 
41
 
namespace drizzled { class Session; }
42
 
 
43
 
/** Dummy session used currently in MySQL interface */
44
 
extern sess_t*  trx_dummy_sess;
45
 
 
46
 
/** Number of transactions currently allocated for MySQL: protected by
47
 
the kernel mutex */
48
 
extern ulint    trx_n_mysql_transactions;
49
 
 
50
 
/********************************************************************//**
51
 
Releases the search latch if trx has reserved it. */
52
 
UNIV_INTERN
53
 
void
54
 
trx_search_latch_release_if_reserved(
55
 
/*=================================*/
56
 
        trx_t*     trx); /*!< in: transaction */
57
 
/******************************************************************//**
58
 
Set detailed error message for the transaction. */
59
 
UNIV_INTERN
60
 
void
61
 
trx_set_detailed_error(
62
 
/*===================*/
63
 
        trx_t*          trx,    /*!< in: transaction struct */
64
 
        const char*     msg);   /*!< in: detailed error message */
65
 
/*************************************************************//**
66
 
Set detailed error message for the transaction from a file. Note that the
67
 
file is rewinded before reading from it. */
68
 
UNIV_INTERN
69
 
void
70
 
trx_set_detailed_error_from_file(
71
 
/*=============================*/
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 */
85
 
UNIV_INLINE
86
 
const dict_index_t*
87
 
trx_get_error_info(
88
 
/*===============*/
89
 
        const trx_t*    trx);   /*!< in: trx object */
90
 
/****************************************************************//**
91
 
Creates and initializes a transaction object.
92
 
@return own: the transaction */
93
 
UNIV_INTERN
94
 
trx_t*
95
 
trx_create(
96
 
/*=======*/
97
 
        sess_t* sess)   /*!< in: session */
98
 
        __attribute__((nonnull));
99
 
/********************************************************************//**
100
 
Creates a transaction object for MySQL.
101
 
@return own: transaction object */
102
 
UNIV_INTERN
103
 
trx_t*
104
 
trx_allocate_for_mysql(void);
105
 
/*========================*/
106
 
/********************************************************************//**
107
 
Creates a transaction object for background operations by the master thread.
108
 
@return own: transaction object */
109
 
UNIV_INTERN
110
 
trx_t*
111
 
trx_allocate_for_background(void);
112
 
/*=============================*/
113
 
/********************************************************************//**
114
 
Frees a transaction object. */
115
 
UNIV_INTERN
116
 
void
117
 
trx_free(
118
 
/*=====*/
119
 
        trx_t*  trx);   /*!< in, own: trx object */
120
 
/********************************************************************//**
121
 
Frees a transaction object for MySQL. */
122
 
UNIV_INTERN
123
 
void
124
 
trx_free_for_mysql(
125
 
/*===============*/
126
 
        trx_t*  trx);   /*!< in, own: trx object */
127
 
/********************************************************************//**
128
 
Frees a transaction object of a background operation of the master thread. */
129
 
UNIV_INTERN
130
 
void
131
 
trx_free_for_background(
132
 
/*====================*/
133
 
        trx_t*  trx);   /*!< in, own: trx object */
134
 
/****************************************************************//**
135
 
Creates trx objects for transactions and initializes the trx list of
136
 
trx_sys at database start. Rollback segment and undo log lists must
137
 
already exist when this function is called, because the lists of
138
 
transactions to be rolled back or cleaned up are built based on the
139
 
undo log lists. */
140
 
UNIV_INTERN
141
 
void
142
 
trx_lists_init_at_db_start(void);
143
 
/*============================*/
144
 
/****************************************************************//**
145
 
Starts a new transaction.
146
 
@return TRUE if success, FALSE if the rollback segment could not
147
 
support this many transactions */
148
 
UNIV_INTERN
149
 
ibool
150
 
trx_start(
151
 
/*======*/
152
 
        trx_t*  trx,    /*!< in: transaction */
153
 
        ulint   rseg_id);/*!< in: rollback segment id; if ULINT_UNDEFINED
154
 
                        is passed, the system chooses the rollback segment
155
 
                        automatically in a round-robin fashion */
156
 
/****************************************************************//**
157
 
Starts a new transaction.
158
 
@return TRUE */
159
 
UNIV_INTERN
160
 
ibool
161
 
trx_start_low(
162
 
/*==========*/
163
 
        trx_t*  trx,    /*!< in: transaction */
164
 
        ulint   rseg_id);/*!< in: rollback segment id; if ULINT_UNDEFINED
165
 
                        is passed, the system chooses the rollback segment
166
 
                        automatically in a round-robin fashion */
167
 
/*************************************************************//**
168
 
Starts the transaction if it is not yet started. */
169
 
UNIV_INLINE
170
 
void
171
 
trx_start_if_not_started(
172
 
/*=====================*/
173
 
        trx_t*  trx);   /*!< in: transaction */
174
 
/*************************************************************//**
175
 
Starts the transaction if it is not yet started. Assumes we have reserved
176
 
the kernel mutex! */
177
 
UNIV_INLINE
178
 
void
179
 
trx_start_if_not_started_low(
180
 
/*=========================*/
181
 
        trx_t*  trx);   /*!< in: transaction */
182
 
/****************************************************************//**
183
 
Commits a transaction. */
184
 
UNIV_INTERN
185
 
void
186
 
trx_commit_off_kernel(
187
 
/*==================*/
188
 
        trx_t*  trx);   /*!< in: transaction */
189
 
/****************************************************************//**
190
 
Cleans up a transaction at database startup. The cleanup is needed if
191
 
the transaction already got to the middle of a commit when the database
192
 
crashed, and we cannot roll it back. */
193
 
UNIV_INTERN
194
 
void
195
 
trx_cleanup_at_db_startup(
196
 
/*======================*/
197
 
        trx_t*  trx);   /*!< in: transaction */
198
 
/**********************************************************************//**
199
 
Does the transaction commit for MySQL.
200
 
@return DB_SUCCESS or error number */
201
 
UNIV_INTERN
202
 
ulint
203
 
trx_commit_for_mysql(
204
 
/*=================*/
205
 
        trx_t*  trx);   /*!< in: trx handle */
206
 
/**********************************************************************//**
207
 
Does the transaction prepare for MySQL.
208
 
@return 0 or error number */
209
 
UNIV_INTERN
210
 
ulint
211
 
trx_prepare_for_mysql(
212
 
/*==================*/
213
 
        trx_t*  trx);   /*!< in: trx handle */
214
 
/**********************************************************************//**
215
 
This function is used to find number of prepared transactions and
216
 
their transaction objects for a recovery.
217
 
@return number of prepared transactions */
218
 
UNIV_INTERN
219
 
int
220
 
trx_recover_for_mysql(
221
 
/*==================*/
222
 
        XID*    xid_list,       /*!< in/out: prepared transactions */
223
 
        ulint   len);           /*!< in: number of slots in xid_list */
224
 
/*******************************************************************//**
225
 
This function is used to find one X/Open XA distributed transaction
226
 
which is in the prepared state
227
 
@return trx or NULL */
228
 
UNIV_INTERN
229
 
trx_t *
230
 
trx_get_trx_by_xid(
231
 
/*===============*/
232
 
        XID*    xid);   /*!< in: X/Open XA transaction identification */
233
 
/**********************************************************************//**
234
 
If required, flushes the log to disk if we called trx_commit_for_mysql()
235
 
with trx->flush_log_later == TRUE.
236
 
@return 0 or error number */
237
 
UNIV_INTERN
238
 
ulint
239
 
trx_commit_complete_for_mysql(
240
 
/*==========================*/
241
 
        trx_t*  trx);   /*!< in: trx handle */
242
 
/**********************************************************************//**
243
 
Marks the latest SQL statement ended. */
244
 
UNIV_INTERN
245
 
void
246
 
trx_mark_sql_stat_end(
247
 
/*==================*/
248
 
        trx_t*  trx);   /*!< in: trx handle */
249
 
/********************************************************************//**
250
 
Assigns a read view for a consistent read query. All the consistent reads
251
 
within the same transaction will get the same read view, which is created
252
 
when this function is first called for a new started transaction.
253
 
@return consistent read view */
254
 
UNIV_INTERN
255
 
read_view_t*
256
 
trx_assign_read_view(
257
 
/*=================*/
258
 
        trx_t*  trx);   /*!< in: active transaction */
259
 
/***********************************************************//**
260
 
The transaction must be in the TRX_QUE_LOCK_WAIT state. Puts it to
261
 
the TRX_QUE_RUNNING state and releases query threads which were
262
 
waiting for a lock in the wait_thrs list. */
263
 
UNIV_INTERN
264
 
void
265
 
trx_end_lock_wait(
266
 
/*==============*/
267
 
        trx_t*  trx);   /*!< in: transaction */
268
 
/****************************************************************//**
269
 
Sends a signal to a trx object. */
270
 
UNIV_INTERN
271
 
void
272
 
trx_sig_send(
273
 
/*=========*/
274
 
        trx_t*          trx,            /*!< in: trx handle */
275
 
        ulint           type,           /*!< in: signal type */
276
 
        ulint           sender,         /*!< in: TRX_SIG_SELF or
277
 
                                        TRX_SIG_OTHER_SESS */
278
 
        que_thr_t*      receiver_thr,   /*!< in: query thread which wants the
279
 
                                        reply, or NULL; if type is
280
 
                                        TRX_SIG_END_WAIT, this must be NULL */
281
 
        trx_savept_t*   savept,         /*!< in: possible rollback savepoint, or
282
 
                                        NULL */
283
 
        que_thr_t**     next_thr);      /*!< in/out: next query thread to run;
284
 
                                        if the value which is passed in is
285
 
                                        a pointer to a NULL pointer, then the
286
 
                                        calling function can start running
287
 
                                        a new query thread; if the parameter
288
 
                                        is NULL, it is ignored */
289
 
/****************************************************************//**
290
 
Send the reply message when a signal in the queue of the trx has
291
 
been handled. */
292
 
UNIV_INTERN
293
 
void
294
 
trx_sig_reply(
295
 
/*==========*/
296
 
        trx_sig_t*      sig,            /*!< in: signal */
297
 
        que_thr_t**     next_thr);      /*!< in/out: next query thread to run;
298
 
                                        if the value which is passed in is
299
 
                                        a pointer to a NULL pointer, then the
300
 
                                        calling function can start running
301
 
                                        a new query thread */
302
 
/****************************************************************//**
303
 
Removes the signal object from a trx signal queue. */
304
 
UNIV_INTERN
305
 
void
306
 
trx_sig_remove(
307
 
/*===========*/
308
 
        trx_t*          trx,    /*!< in: trx handle */
309
 
        trx_sig_t*      sig);   /*!< in, own: signal */
310
 
/****************************************************************//**
311
 
Starts handling of a trx signal. */
312
 
UNIV_INTERN
313
 
void
314
 
trx_sig_start_handle(
315
 
/*=================*/
316
 
        trx_t*          trx,            /*!< in: trx handle */
317
 
        que_thr_t**     next_thr);      /*!< in/out: next query thread to run;
318
 
                                        if the value which is passed in is
319
 
                                        a pointer to a NULL pointer, then the
320
 
                                        calling function can start running
321
 
                                        a new query thread */
322
 
/****************************************************************//**
323
 
Ends signal handling. If the session is in the error state, and
324
 
trx->graph_before_signal_handling != NULL, returns control to the error
325
 
handling routine of the graph (currently only returns the control to the
326
 
graph root which then sends an error message to the client). */
327
 
UNIV_INTERN
328
 
void
329
 
trx_end_signal_handling(
330
 
/*====================*/
331
 
        trx_t*  trx);   /*!< in: trx */
332
 
/*********************************************************************//**
333
 
Creates a commit command node struct.
334
 
@return own: commit node struct */
335
 
UNIV_INTERN
336
 
commit_node_t*
337
 
commit_node_create(
338
 
/*===============*/
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 */
343
 
UNIV_INTERN
344
 
que_thr_t*
345
 
trx_commit_step(
346
 
/*============*/
347
 
        que_thr_t*      thr);   /*!< in: query thread */
348
 
 
349
 
/**********************************************************************//**
350
 
Prints info about a transaction to the given file. The caller must own the
351
 
kernel mutex. */
352
 
UNIV_INTERN
353
 
void
354
 
trx_print(
355
 
/*======*/
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
359
 
                                   use the default max length */
360
 
 
361
 
/** Type of data dictionary operation */
362
 
typedef enum trx_dict_op {
363
 
        /** The transaction is not modifying the data dictionary. */
364
 
        TRX_DICT_OP_NONE = 0,
365
 
        /** The transaction is creating a table or an index, or
366
 
        dropping a table.  The table must be dropped in crash
367
 
        recovery.  This and TRX_DICT_OP_NONE are the only possible
368
 
        operation modes in crash recovery. */
369
 
        TRX_DICT_OP_TABLE = 1,
370
 
        /** The transaction is creating or dropping an index in an
371
 
        existing table.  In crash recovery, the the data dictionary
372
 
        must be locked, but the table must not be dropped. */
373
 
        TRX_DICT_OP_INDEX = 2
374
 
} trx_dict_op_t;
375
 
 
376
 
/**********************************************************************//**
377
 
Determine if a transaction is a dictionary operation.
378
 
@return dictionary operation mode */
379
 
UNIV_INLINE
380
 
enum trx_dict_op
381
 
trx_get_dict_operation(
382
 
/*===================*/
383
 
        const trx_t*    trx)    /*!< in: transaction */
384
 
        __attribute__((pure));
385
 
/**********************************************************************//**
386
 
Flag a transaction a dictionary operation. */
387
 
UNIV_INLINE
388
 
void
389
 
trx_set_dict_operation(
390
 
/*===================*/
391
 
        trx_t*                  trx,    /*!< in/out: transaction */
392
 
        enum trx_dict_op        op);    /*!< in: operation, not
393
 
                                        TRX_DICT_OP_NONE */
394
 
 
395
 
#ifndef UNIV_HOTBACKUP
396
 
/**********************************************************************//**
397
 
Determines if the currently running transaction has been interrupted.
398
 
@return TRUE if interrupted */
399
 
UNIV_INTERN
400
 
ibool
401
 
trx_is_interrupted(
402
 
/*===============*/
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 */
412
 
#else /* !UNIV_HOTBACKUP */
413
 
#define trx_is_interrupted(trx) FALSE
414
 
#endif /* !UNIV_HOTBACKUP */
415
 
 
416
 
/*******************************************************************//**
417
 
Calculates the "weight" of a transaction. The weight of one transaction
418
 
is estimated as the number of altered rows + the number of locked rows.
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
 
/*******************************************************************//**
424
 
Compares the "weight" (or size) of two transactions. Transactions that
425
 
have edited non-transactional tables are considered heavier than ones
426
 
that have not.
427
 
@return TRUE if weight(a) >= weight(b) */
428
 
UNIV_INTERN
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 */
434
 
 
435
 
/* Maximum length of a string that can be returned by
436
 
trx_get_que_state_str(). */
437
 
#define TRX_QUE_STATE_STR_MAX_LEN       12 /* "ROLLING BACK" */
438
 
 
439
 
/*******************************************************************//**
440
 
Retrieves transaction's que state in a human readable string. The string
441
 
should not be free()'d or modified.
442
 
@return string in the data segment */
443
 
UNIV_INLINE
444
 
const char*
445
 
trx_get_que_state_str(
446
 
/*==================*/
447
 
        const trx_t*    trx);   /*!< in: transaction */
448
 
 
449
 
/* Signal to a transaction */
450
 
struct trx_sig_struct{
451
 
        unsigned        type:3;         /*!< signal type */
452
 
        unsigned        sender:1;       /*!< TRX_SIG_SELF or
453
 
                                        TRX_SIG_OTHER_SESS */
454
 
        que_thr_t*      receiver;       /*!< non-NULL if the sender of the signal
455
 
                                        wants reply after the operation induced
456
 
                                        by the signal is completed */
457
 
        trx_savept_t    savept;         /*!< possible rollback savepoint */
458
 
        UT_LIST_NODE_T(trx_sig_t)
459
 
                        signals;        /*!< queue of pending signals to the
460
 
                                        transaction */
461
 
        UT_LIST_NODE_T(trx_sig_t)
462
 
                        reply_signals;  /*!< list of signals for which the sender
463
 
                                        transaction is waiting a reply */
464
 
};
465
 
 
466
 
#define TRX_MAGIC_N     91118598
467
 
 
468
 
/* The transaction handle; every session has a trx object which is freed only
469
 
when the session is freed; in addition there may be session-less transactions
470
 
rolling back after a database recovery */
471
 
 
472
 
struct trx_struct{
473
 
        ulint           magic_n;
474
 
 
475
 
        /* These fields are not protected by any mutex. */
476
 
        const char*     op_info;        /*!< English text describing the
477
 
                                        current operation, or an empty
478
 
                                        string */
479
 
        ulint           conc_state;     /*!< state of the trx from the point
480
 
                                        of view of concurrency control:
481
 
                                        TRX_ACTIVE, TRX_COMMITTED_IN_MEMORY,
482
 
                                        ... */
483
 
        ulint           isolation_level;/* TRX_ISO_REPEATABLE_READ, ... */
484
 
        ulint           check_foreigns; /* normally TRUE, but if the user
485
 
                                        wants to suppress foreign key checks,
486
 
                                        (in table imports, for example) we
487
 
                                        set this FALSE */
488
 
        unsigned        check_unique_secondary;
489
 
                                        /* normally TRUE, but if the user
490
 
                                        wants to speed up inserts by
491
 
                                        suppressing unique key checks
492
 
                                        for secondary indexes when we decide
493
 
                                        if we can use the insert buffer for
494
 
                                        them, we set this FALSE */
495
 
        unsigned        support_xa;     /*!< normally we do the XA two-phase
496
 
                                        commit steps, but by setting this to
497
 
                                        FALSE, one can save CPU time and about
498
 
                                        150 bytes in the undo log size as then
499
 
                                        we skip XA steps */
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
507
 
                                        trx_commit_off_kernel() if
508
 
                                        flush_log_later was TRUE, and there
509
 
                                        were modifications by the transaction;
510
 
                                        in that case we must flush the log
511
 
                                        in trx_commit_complete_for_mysql() */
512
 
        ulint           duplicates;     /*!< TRX_DUP_IGNORE | TRX_DUP_REPLACE */
513
 
        unsigned        has_search_latch;
514
 
                                        /* TRUE if this trx has latched the
515
 
                                        search system latch in S-mode */
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;
522
 
                                        /* this is TRUE if we have declared
523
 
                                        this transaction in
524
 
                                        srv_conc_enter_innodb to be inside the
525
 
                                        InnoDB engine */
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:
531
 
                                        the latch mode trx currently holds
532
 
                                        on dict_operation_lock */
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
545
 
                                        or the state last time became
546
 
                                        TRX_ACTIVE */
547
 
        trx_id_t        id;             /*!< transaction id */
548
 
        XID             xid;            /*!< X/Open XA transaction
549
 
                                        identification to identify a
550
 
                                        transaction branch */
551
 
        trx_id_t        no;             /*!< transaction serialization number ==
552
 
                                        max trx id when the transaction is
553
 
                                        moved to COMMITTED_IN_MEMORY state */
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. */
557
 
        /*------------------------------*/
558
 
        drizzled::Session *mysql_thd;   /*!< MySQL thread handle corresponding
559
 
                                        to this trx, or NULL */
560
 
        const char*     mysql_log_file_name;
561
 
                                        /* if MySQL binlog is used, this field
562
 
                                        contains a pointer to the latest file
563
 
                                        name; this is NULL if binlog is not
564
 
                                        used */
565
 
        ib_int64_t      mysql_log_offset;/* if MySQL binlog is used, this field
566
 
                                        contains the end offset of the binlog
567
 
                                        entry */
568
 
        os_thread_id_t  mysql_thread_id;/* id of the MySQL thread associated
569
 
                                        with this transaction object */
570
 
        ulint           mysql_process_no;/* since in Linux, 'top' reports
571
 
                                        process id's and not thread id's, we
572
 
                                        store the process number too */
573
 
        ulint           mysql_n_tables_locked;
574
 
                                        /* how many tables the current SQL
575
 
                                        statement uses, except those
576
 
                                        in consistent read */
577
 
        ulint           search_latch_timeout;
578
 
                                        /* If we notice that someone is
579
 
                                        waiting for our S-lock on the search
580
 
                                        latch to be released, we wait in
581
 
                                        row0sel.c for BTR_SEA_TIMEOUT new
582
 
                                        searches until we try to keep
583
 
                                        the search latch again over
584
 
                                        calls from MySQL; this is intended
585
 
                                        to reduce contention on the search
586
 
                                        latch */
587
 
        /*------------------------------*/
588
 
        ulint           n_tickets_to_enter_innodb;
589
 
                                        /* this can be > 0 only when
590
 
                                        declared_to_... is TRUE; when we come
591
 
                                        to srv_conc_innodb_enter, if the value
592
 
                                        here is > 0, we decrement this by 1 */
593
 
        /*------------------------------*/
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
598
 
                                        MySQL */
599
 
        /*------------------------------*/
600
 
        ulint           error_state;    /*!< 0 if no error, otherwise error
601
 
                                        number; NOTE That ONLY the thread
602
 
                                        doing the transaction is allowed to
603
 
                                        set this field: this is NOT protected
604
 
                                        by the kernel mutex */
605
 
        const dict_index_t*error_info;  /*!< if the error number indicates a
606
 
                                        duplicate key error, a pointer to
607
 
                                        the problematic index is stored here */
608
 
        ulint           error_key_num;  /*!< if the index creation fails to a
609
 
                                        duplicate key error, a mysql key
610
 
                                        number of that index is stored here */
611
 
        sess_t*         sess;           /*!< session of the trx, NULL if none */
612
 
        que_t*          graph;          /*!< query currently run in the session,
613
 
                                        or NULL if none; NOTE that the query
614
 
                                        belongs to the session, and it can
615
 
                                        survive over a transaction commit, if
616
 
                                        it is a stored procedure with a COMMIT
617
 
                                        WORK statement, for instance */
618
 
        ulint           n_active_thrs;  /*!< number of active query threads */
619
 
        que_t*          graph_before_signal_handling;
620
 
                                        /* value of graph when signal handling
621
 
                                        for this trx started: this is used to
622
 
                                        return control to the original query
623
 
                                        graph for error processing */
624
 
        trx_sig_t       sig;            /*!< one signal object can be allocated
625
 
                                        in this space, avoiding mem_alloc */
626
 
        UT_LIST_BASE_NODE_T(trx_sig_t)
627
 
                        signals;        /*!< queue of processed or pending
628
 
                                        signals to the trx */
629
 
        UT_LIST_BASE_NODE_T(trx_sig_t)
630
 
                        reply_signals;  /*!< list of signals sent by the query
631
 
                                        threads of this trx for which a thread
632
 
                                        is waiting for a reply; if this trx is
633
 
                                        killed, the reply requests in the list
634
 
                                        must be canceled */
635
 
        /*------------------------------*/
636
 
        lock_t*         wait_lock;      /*!< if trx execution state is
637
 
                                        TRX_QUE_LOCK_WAIT, this points to
638
 
                                        the lock request, otherwise this is
639
 
                                        NULL */
640
 
        ibool           was_chosen_as_deadlock_victim;
641
 
                                        /* when the transaction decides to wait
642
 
                                        for a lock, it sets this to FALSE;
643
 
                                        if another transaction chooses this
644
 
                                        transaction as a victim in deadlock
645
 
                                        resolution, it sets this to TRUE */
646
 
        time_t          wait_started;   /*!< lock wait started at this time */
647
 
        UT_LIST_BASE_NODE_T(que_thr_t)
648
 
                        wait_thrs;      /*!< query threads belonging to this
649
 
                                        trx that are in the QUE_THR_LOCK_WAIT
650
 
                                        state */
651
 
        /*------------------------------*/
652
 
        mem_heap_t*     lock_heap;      /*!< memory heap for the locks of the
653
 
                                        transaction */
654
 
        UT_LIST_BASE_NODE_T(lock_t)
655
 
                        trx_locks;      /*!< locks reserved by the transaction */
656
 
        /*------------------------------*/
657
 
        mem_heap_t*     global_read_view_heap;
658
 
                                        /* memory heap for the global read
659
 
                                        view */
660
 
        read_view_t*    global_read_view;
661
 
                                        /* consistent read view associated
662
 
                                        to a transaction or NULL */
663
 
        read_view_t*    read_view;      /*!< consistent read view used in the
664
 
                                        transaction or NULL, this read view
665
 
                                        if defined can be normal read view
666
 
                                        associated to a transaction (i.e.
667
 
                                        same as global_read_view) or read view
668
 
                                        associated to a cursor */
669
 
        /*------------------------------*/
670
 
        UT_LIST_BASE_NODE_T(trx_named_savept_t)
671
 
                        trx_savepoints; /*!< savepoints set with SAVEPOINT ...,
672
 
                                        oldest first */
673
 
        /*------------------------------*/
674
 
        mutex_t         undo_mutex;     /*!< mutex protecting the fields in this
675
 
                                        section (down to undo_no_arr), EXCEPT
676
 
                                        last_sql_stat_start, which can be
677
 
                                        accessed only when we know that there
678
 
                                        cannot be any activity in the undo
679
 
                                        logs! */
680
 
        undo_no_t       undo_no;        /*!< next undo log record number to
681
 
                                        assign; since the undo log is
682
 
                                        private for a transaction, this
683
 
                                        is a simple ascending sequence
684
 
                                        with no gaps; thus it represents
685
 
                                        the number of modified/inserted
686
 
                                        rows in a transaction */
687
 
        trx_savept_t    last_sql_stat_start;
688
 
                                        /* undo_no when the last sql statement
689
 
                                        was started: in case of an error, trx
690
 
                                        is rolled back down to this undo
691
 
                                        number; see note at undo_mutex! */
692
 
        trx_rseg_t*     rseg;           /*!< rollback segment assigned to the
693
 
                                        transaction, or NULL if not assigned
694
 
                                        yet */
695
 
        trx_undo_t*     insert_undo;    /*!< pointer to the insert undo log, or
696
 
                                        NULL if no inserts performed yet */
697
 
        trx_undo_t*     update_undo;    /*!< pointer to the update undo log, or
698
 
                                        NULL if no update performed yet */
699
 
        undo_no_t       roll_limit;     /*!< least undo number to undo during
700
 
                                        a rollback */
701
 
        ulint           pages_undone;   /*!< number of undo log pages undone
702
 
                                        since the last undo log truncation */
703
 
        trx_undo_arr_t* undo_no_arr;    /*!< array of undo numbers of undo log
704
 
                                        records which are currently processed
705
 
                                        by a rollback operation */
706
 
        /*------------------------------*/
707
 
        ulint           n_autoinc_rows; /*!< no. of AUTO-INC rows required for
708
 
                                        an SQL statement. This is useful for
709
 
                                        multi-row INSERTs */
710
 
        ib_vector_t*    autoinc_locks;  /* AUTOINC locks held by this
711
 
                                        transaction. Note that these are
712
 
                                        also in the lock list trx_locks. This
713
 
                                        vector needs to be freed explicitly
714
 
                                        when the trx_t instance is desrtoyed */
715
 
        /*------------------------------*/
716
 
        char detailed_error[256];       /*!< detailed error message for last
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
 
        }
729
 
};
730
 
 
731
 
#define TRX_MAX_N_THREADS       32      /* maximum number of
732
 
                                        concurrent threads running a
733
 
                                        single operation of a
734
 
                                        transaction, e.g., a parallel
735
 
                                        query */
736
 
/* Transaction concurrency states (trx->conc_state) */
737
 
#define TRX_NOT_STARTED         0
738
 
#define TRX_ACTIVE              1
739
 
#define TRX_COMMITTED_IN_MEMORY 2
740
 
#define TRX_PREPARED            3       /* Support for 2PC/XA */
741
 
 
742
 
/* Transaction execution states when trx->conc_state == TRX_ACTIVE */
743
 
#define TRX_QUE_RUNNING         0       /* transaction is running */
744
 
#define TRX_QUE_LOCK_WAIT       1       /* transaction is waiting for a lock */
745
 
#define TRX_QUE_ROLLING_BACK    2       /* transaction is rolling back */
746
 
#define TRX_QUE_COMMITTING      3       /* transaction is committing */
747
 
 
748
 
/* Transaction isolation levels (trx->isolation_level) */
749
 
#define TRX_ISO_READ_UNCOMMITTED        0       /* dirty read: non-locking
750
 
                                                SELECTs are performed so that
751
 
                                                we do not look at a possible
752
 
                                                earlier version of a record;
753
 
                                                thus they are not 'consistent'
754
 
                                                reads under this isolation
755
 
                                                level; otherwise like level
756
 
                                                2 */
757
 
 
758
 
#define TRX_ISO_READ_COMMITTED          1       /* somewhat Oracle-like
759
 
                                                isolation, except that in
760
 
                                                range UPDATE and DELETE we
761
 
                                                must block phantom rows
762
 
                                                with next-key locks;
763
 
                                                SELECT ... FOR UPDATE and ...
764
 
                                                LOCK IN SHARE MODE only lock
765
 
                                                the index records, NOT the
766
 
                                                gaps before them, and thus
767
 
                                                allow free inserting;
768
 
                                                each consistent read reads its
769
 
                                                own snapshot */
770
 
 
771
 
#define TRX_ISO_REPEATABLE_READ         2       /* this is the default;
772
 
                                                all consistent reads in the
773
 
                                                same trx read the same
774
 
                                                snapshot;
775
 
                                                full next-key locking used
776
 
                                                in locking reads to block
777
 
                                                insertions into gaps */
778
 
 
779
 
#define TRX_ISO_SERIALIZABLE            3       /* all plain SELECTs are
780
 
                                                converted to LOCK IN SHARE
781
 
                                                MODE reads */
782
 
 
783
 
/* Treatment of duplicate values (trx->duplicates; for example, in inserts).
784
 
Multiple flags can be combined with bitwise OR. */
785
 
#define TRX_DUP_IGNORE  1       /* duplicate rows are to be updated */
786
 
#define TRX_DUP_REPLACE 2       /* duplicate rows are to be replaced */
787
 
 
788
 
 
789
 
/* Types of a trx signal */
790
 
#define TRX_SIG_NO_SIGNAL               0
791
 
#define TRX_SIG_TOTAL_ROLLBACK          1
792
 
#define TRX_SIG_ROLLBACK_TO_SAVEPT      2
793
 
#define TRX_SIG_COMMIT                  3
794
 
#define TRX_SIG_ERROR_OCCURRED          4
795
 
#define TRX_SIG_BREAK_EXECUTION         5
796
 
 
797
 
/* Sender types of a signal */
798
 
#define TRX_SIG_SELF            0       /* sent by the session itself, or
799
 
                                        by an error occurring within this
800
 
                                        session */
801
 
#define TRX_SIG_OTHER_SESS      1       /* sent by another session (which
802
 
                                        must hold rights to this) */
803
 
 
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 */
813
 
struct commit_node_struct{
814
 
        que_common_t    common; /*!< node type: QUE_NODE_COMMIT */
815
 
        enum commit_node_state
816
 
                        state;  /*!< node execution state */
817
 
};
818
 
 
819
 
 
820
 
 
821
 
#ifndef UNIV_NONINL
822
 
#include "trx0trx.ic"
823
 
#endif
824
 
#endif /* !UNIV_HOTBACKUP */
825
 
 
826
 
#endif