~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-10-30 19:42:06 UTC
  • mto: (520.4.38 devel)
  • mto: This revision was merged to the branch mainline in revision 572.
  • Revision ID: monty@inaugust.com-20081030194206-fzus6yqlw1ekru65
Removed handler from common_includes.

Show diffs side-by-side

added added

removed removed

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