1
/*****************************************************************************
3
Copyright (C) 2007, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/trx0i_s.h
21
INFORMATION SCHEMA innodb_trx, innodb_locks and
22
innodb_lock_waits tables cache structures and public
25
Created July 17, 2007 Vasil Dimov
26
*******************************************************/
32
#include "trx0types.h"
33
#include "dict0types.h"
36
/** The maximum amount of memory that can be consumed by innodb_trx,
37
innodb_locks and innodb_lock_waits information schema tables. */
38
#define TRX_I_S_MEM_LIMIT 16777216 /* 16 MiB */
40
/** The maximum length of a string that can be stored in
41
i_s_locks_row_t::lock_data */
42
#define TRX_I_S_LOCK_DATA_MAX_LEN 8192
44
/** The maximum length of a string that can be stored in
45
i_s_trx_row_t::trx_query */
46
#define TRX_I_S_TRX_QUERY_MAX_LEN 1024
48
/** The maximum length of a string that can be stored in
49
i_s_trx_row_t::trx_operation_state */
50
#define TRX_I_S_TRX_OP_STATE_MAX_LEN 64
52
/** The maximum length of a string that can be stored in
53
i_s_trx_row_t::trx_foreign_key_error */
54
#define TRX_I_S_TRX_FK_ERROR_MAX_LEN 256
56
/** The maximum length of a string that can be stored in
57
i_s_trx_row_t::trx_isolation_level */
58
#define TRX_I_S_TRX_ISOLATION_LEVEL_MAX_LEN 16
60
/** Safely copy strings in to the INNODB_TRX table's
61
string based columns */
62
#define TRX_I_S_STRING_COPY(data, field, constraint, tcache) \
64
if (strlen(data) > constraint) { \
65
char buff[constraint + 1]; \
66
strncpy(buff, data, constraint); \
67
buff[constraint] = '\0'; \
69
field = static_cast<const char *>(ha_storage_put_memlim( \
70
(tcache)->storage, buff, constraint + 1,\
71
MAX_ALLOWED_FOR_STORAGE(tcache))); \
73
field = static_cast<const char *>(ha_storage_put_str_memlim( \
74
(tcache)->storage, data, \
75
MAX_ALLOWED_FOR_STORAGE(tcache))); \
79
/** A row of INFORMATION_SCHEMA.innodb_locks */
80
typedef struct i_s_locks_row_struct i_s_locks_row_t;
81
/** A row of INFORMATION_SCHEMA.innodb_trx */
82
typedef struct i_s_trx_row_struct i_s_trx_row_t;
83
/** A row of INFORMATION_SCHEMA.innodb_lock_waits */
84
typedef struct i_s_lock_waits_row_struct i_s_lock_waits_row_t;
86
/** Objects of trx_i_s_cache_t::locks_hash */
87
typedef struct i_s_hash_chain_struct i_s_hash_chain_t;
89
/** Objects of this type are added to the hash table
90
trx_i_s_cache_t::locks_hash */
91
struct i_s_hash_chain_struct {
92
i_s_locks_row_t* value; /*!< row of
93
INFORMATION_SCHEMA.innodb_locks*/
94
i_s_hash_chain_t* next; /*!< next item in the hash chain */
97
/** This structure represents INFORMATION_SCHEMA.innodb_locks row */
98
struct i_s_locks_row_struct {
99
trx_id_t lock_trx_id; /*!< transaction identifier */
100
const char* lock_mode; /*!< lock mode from
101
lock_get_mode_str() */
102
const char* lock_type; /*!< lock type from
103
lock_get_type_str() */
104
const char* lock_table; /*!< table name from
105
lock_get_table_name() */
106
const char* lock_index; /*!< index name from
107
lock_rec_get_index_name() */
108
/** Information for record locks. All these are
109
ULINT_UNDEFINED for table locks. */
111
ulint lock_space; /*!< tablespace identifier */
112
ulint lock_page; /*!< page number within the_space */
113
ulint lock_rec; /*!< heap number of the record
115
const char* lock_data; /*!< (some) content of the record */
118
/** The following are auxiliary and not included in the table */
120
table_id_t lock_table_id;
121
/*!< table identifier from
123
i_s_hash_chain_t hash_chain; /*!< hash table chain node for
124
trx_i_s_cache_t::locks_hash */
128
/** This structure represents INFORMATION_SCHEMA.innodb_trx row */
129
struct i_s_trx_row_struct {
130
trx_id_t trx_id; /*!< transaction identifier */
131
const char* trx_state; /*!< transaction state from
132
trx_get_que_state_str() */
133
ib_time_t trx_started; /*!< trx_struct::start_time */
134
const i_s_locks_row_t* requested_lock_row;
135
/*!< pointer to a row
136
in innodb_locks if trx
137
is waiting, or NULL */
138
ib_time_t trx_wait_started; /*!< trx_struct::wait_started */
139
ullint trx_weight; /*!< TRX_WEIGHT() */
140
ulint trx_mysql_thread_id; /*!< thd_get_thread_id() */
141
const char* trx_query; /*!< MySQL statement being
142
executed in the transaction */
143
const char* trx_operation_state; /*!< trx_struct::op_info */
144
ulint trx_tables_in_use;/*!< n_mysql_tables_in_use in
146
ulint trx_tables_locked;
147
/*!< mysql_n_tables_locked in
149
ulint trx_lock_structs;/*!< list len of trx_locks in
151
ulint trx_lock_memory_bytes;
152
/*!< mem_heap_get_size(
154
ulint trx_rows_locked;/*!< lock_number_of_rows_locked() */
155
ullint trx_rows_modified;/*!< trx_struct::undo_no */
156
ulint trx_concurrency_tickets;
157
/*!< n_tickets_to_enter_innodb in
159
const char* trx_isolation_level;
160
/*!< isolation_level in trx_struct*/
161
ibool trx_unique_checks;
162
/*!< check_unique_secondary in
164
ibool trx_foreign_key_checks;
165
/*!< check_foreigns in trx_struct */
166
const char* trx_foreign_key_error;
167
/*!< detailed_error in trx_struct */
168
ibool trx_has_search_latch;
169
/*!< has_search_latch in trx_struct */
170
ulint trx_search_latch_timeout;
171
/*!< search_latch_timeout in
175
/** This structure represents INFORMATION_SCHEMA.innodb_lock_waits row */
176
struct i_s_lock_waits_row_struct {
177
const i_s_locks_row_t* requested_lock_row; /*!< requested lock */
178
const i_s_locks_row_t* blocking_lock_row; /*!< blocking lock */
181
/** Cache of INFORMATION_SCHEMA table data */
182
typedef struct trx_i_s_cache_struct trx_i_s_cache_t;
184
/** Auxiliary enum used by functions that need to select one of the
185
INFORMATION_SCHEMA tables */
187
I_S_INNODB_TRX, /*!< INFORMATION_SCHEMA.innodb_trx */
188
I_S_INNODB_LOCKS, /*!< INFORMATION_SCHEMA.innodb_locks */
189
I_S_INNODB_LOCK_WAITS /*!< INFORMATION_SCHEMA.innodb_lock_waits */
192
/** This is the intermediate buffer where data needed to fill the
193
INFORMATION SCHEMA tables is fetched and later retrieved by the C++
194
code in handler/i_s.cc. */
195
extern trx_i_s_cache_t* trx_i_s_cache;
197
/*******************************************************************//**
198
Initialize INFORMATION SCHEMA trx related cache. */
203
trx_i_s_cache_t* cache); /*!< out: cache to init */
204
/*******************************************************************//**
205
Free the INFORMATION SCHEMA trx related cache. */
210
trx_i_s_cache_t* cache); /*!< in/out: cache to free */
212
/*******************************************************************//**
213
Issue a shared/read lock on the tables cache. */
216
trx_i_s_cache_start_read(
217
/*=====================*/
218
trx_i_s_cache_t* cache); /*!< in: cache */
220
/*******************************************************************//**
221
Release a shared/read lock on the tables cache. */
224
trx_i_s_cache_end_read(
225
/*===================*/
226
trx_i_s_cache_t* cache); /*!< in: cache */
228
/*******************************************************************//**
229
Issue an exclusive/write lock on the tables cache. */
232
trx_i_s_cache_start_write(
233
/*======================*/
234
trx_i_s_cache_t* cache); /*!< in: cache */
236
/*******************************************************************//**
237
Release an exclusive/write lock on the tables cache. */
240
trx_i_s_cache_end_write(
241
/*====================*/
242
trx_i_s_cache_t* cache); /*!< in: cache */
245
/*******************************************************************//**
246
Retrieves the number of used rows in the cache for a given
247
INFORMATION SCHEMA table.
248
@return number of rows */
251
trx_i_s_cache_get_rows_used(
252
/*========================*/
253
trx_i_s_cache_t* cache, /*!< in: cache */
254
enum i_s_table table); /*!< in: which table */
256
/*******************************************************************//**
257
Retrieves the nth row in the cache for a given INFORMATION SCHEMA
262
trx_i_s_cache_get_nth_row(
263
/*======================*/
264
trx_i_s_cache_t* cache, /*!< in: cache */
265
enum i_s_table table, /*!< in: which table */
266
ulint n); /*!< in: row number */
268
/*******************************************************************//**
269
Update the transactions cache if it has not been read for some time.
270
@return 0 - fetched, 1 - not */
273
trx_i_s_possibly_fetch_data_into_cache(
274
/*===================================*/
275
trx_i_s_cache_t* cache); /*!< in/out: cache */
277
/*******************************************************************//**
278
Returns TRUE if the data in the cache is truncated due to the memory
279
limit posed by TRX_I_S_MEM_LIMIT.
280
@return TRUE if truncated */
283
trx_i_s_cache_is_truncated(
284
/*=======================*/
285
trx_i_s_cache_t* cache); /*!< in: cache */
287
/** The maximum length of a resulting lock_id_size in
288
trx_i_s_create_lock_id(), not including the terminating NUL.
289
":%lu:%lu:%lu" -> 63 chars */
290
#define TRX_I_S_LOCK_ID_MAX_LEN (TRX_ID_MAX_LEN + 63)
292
/*******************************************************************//**
293
Crafts a lock id string from a i_s_locks_row_t object. Returns its
294
second argument. This function aborts if there is not enough space in
295
lock_id. Be sure to provide at least TRX_I_S_LOCK_ID_MAX_LEN + 1 if you
296
want to be 100% sure that it will not abort.
297
@return resulting lock id */
300
trx_i_s_create_lock_id(
301
/*===================*/
302
const i_s_locks_row_t* row, /*!< in: innodb_locks row */
303
char* lock_id,/*!< out: resulting lock_id */
304
ulint lock_id_size);/*!< in: size of the lock id
307
#endif /* trx0i_s_h */