~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-01-07 09:27:07 UTC
  • Revision ID: brian@tangent.org-20090107092707-bn67qpdllfcyh3j9
Removing dead field translator code.

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