~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

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