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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 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"
35
/** The maximum amount of memory that can be consumed by innodb_trx,
36
innodb_locks and innodb_lock_waits information schema tables. */
37
#define TRX_I_S_MEM_LIMIT 16777216 /* 16 MiB */
39
/** The maximum length of a string that can be stored in
40
i_s_locks_row_t::lock_data */
41
#define TRX_I_S_LOCK_DATA_MAX_LEN 8192
43
/** The maximum length of a string that can be stored in
44
i_s_trx_row_t::trx_query */
45
#define TRX_I_S_TRX_QUERY_MAX_LEN 1024
47
/** A row of INFORMATION_SCHEMA.innodb_locks */
48
typedef struct i_s_locks_row_struct i_s_locks_row_t;
49
/** A row of INFORMATION_SCHEMA.innodb_trx */
50
typedef struct i_s_trx_row_struct i_s_trx_row_t;
51
/** A row of INFORMATION_SCHEMA.innodb_lock_waits */
52
typedef struct i_s_lock_waits_row_struct i_s_lock_waits_row_t;
54
/** Objects of trx_i_s_cache_t::locks_hash */
55
typedef struct i_s_hash_chain_struct i_s_hash_chain_t;
57
/** Objects of this type are added to the hash table
58
trx_i_s_cache_t::locks_hash */
59
struct i_s_hash_chain_struct {
60
i_s_locks_row_t* value; /*!< row of
61
INFORMATION_SCHEMA.innodb_locks*/
62
i_s_hash_chain_t* next; /*!< next item in the hash chain */
65
/** This structure represents INFORMATION_SCHEMA.innodb_locks row */
66
struct i_s_locks_row_struct {
67
ullint lock_trx_id; /*!< transaction identifier */
68
const char* lock_mode; /*!< lock mode from
69
lock_get_mode_str() */
70
const char* lock_type; /*!< lock type from
71
lock_get_type_str() */
72
const char* lock_table; /*!< table name from
73
lock_get_table_name() */
74
const char* lock_index; /*!< index name from
75
lock_rec_get_index_name() */
76
/** Information for record locks. All these are
77
ULINT_UNDEFINED for table locks. */
79
ulint lock_space; /*!< tablespace identifier */
80
ulint lock_page; /*!< page number within the_space */
81
ulint lock_rec; /*!< heap number of the record
83
const char* lock_data; /*!< (some) content of the record */
86
/** The following are auxiliary and not included in the table */
89
/*!< table identifier from
91
i_s_hash_chain_t hash_chain; /*!< hash table chain node for
92
trx_i_s_cache_t::locks_hash */
96
/** This structure represents INFORMATION_SCHEMA.innodb_trx row */
97
struct i_s_trx_row_struct {
98
ullint trx_id; /*!< transaction identifier */
99
const char* trx_state; /*!< transaction state from
100
trx_get_que_state_str() */
101
ib_time_t trx_started; /*!< trx_struct::start_time */
102
const i_s_locks_row_t* requested_lock_row;
103
/*!< pointer to a row
104
in innodb_locks if trx
105
is waiting, or NULL */
106
ib_time_t trx_wait_started;
107
/*!< trx_struct::wait_started */
108
ullint trx_weight; /*!< TRX_WEIGHT() */
109
ulint trx_mysql_thread_id;
110
/*!< thd_get_thread_id() */
111
const char* trx_query; /*!< MySQL statement being
112
executed in the transaction */
115
/** This structure represents INFORMATION_SCHEMA.innodb_lock_waits row */
116
struct i_s_lock_waits_row_struct {
117
const i_s_locks_row_t* requested_lock_row; /*!< requested lock */
118
const i_s_locks_row_t* blocking_lock_row; /*!< blocking lock */
121
/** Cache of INFORMATION_SCHEMA table data */
122
typedef struct trx_i_s_cache_struct trx_i_s_cache_t;
124
/** Auxiliary enum used by functions that need to select one of the
125
INFORMATION_SCHEMA tables */
127
I_S_INNODB_TRX, /*!< INFORMATION_SCHEMA.innodb_trx */
128
I_S_INNODB_LOCKS, /*!< INFORMATION_SCHEMA.innodb_locks */
129
I_S_INNODB_LOCK_WAITS /*!< INFORMATION_SCHEMA.innodb_lock_waits */
132
/** This is the intermediate buffer where data needed to fill the
133
INFORMATION SCHEMA tables is fetched and later retrieved by the C++
134
code in handler/i_s.cc. */
135
extern trx_i_s_cache_t* trx_i_s_cache;
137
/*******************************************************************//**
138
Initialize INFORMATION SCHEMA trx related cache. */
143
trx_i_s_cache_t* cache); /*!< out: cache to init */
145
/*******************************************************************//**
146
Issue a shared/read lock on the tables cache. */
149
trx_i_s_cache_start_read(
150
/*=====================*/
151
trx_i_s_cache_t* cache); /*!< in: cache */
153
/*******************************************************************//**
154
Release a shared/read lock on the tables cache. */
157
trx_i_s_cache_end_read(
158
/*===================*/
159
trx_i_s_cache_t* cache); /*!< in: cache */
161
/*******************************************************************//**
162
Issue an exclusive/write lock on the tables cache. */
165
trx_i_s_cache_start_write(
166
/*======================*/
167
trx_i_s_cache_t* cache); /*!< in: cache */
169
/*******************************************************************//**
170
Release an exclusive/write lock on the tables cache. */
173
trx_i_s_cache_end_write(
174
/*====================*/
175
trx_i_s_cache_t* cache); /*!< in: cache */
178
/*******************************************************************//**
179
Retrieves the number of used rows in the cache for a given
180
INFORMATION SCHEMA table.
181
@return number of rows */
184
trx_i_s_cache_get_rows_used(
185
/*========================*/
186
trx_i_s_cache_t* cache, /*!< in: cache */
187
enum i_s_table table); /*!< in: which table */
189
/*******************************************************************//**
190
Retrieves the nth row in the cache for a given INFORMATION SCHEMA
195
trx_i_s_cache_get_nth_row(
196
/*======================*/
197
trx_i_s_cache_t* cache, /*!< in: cache */
198
enum i_s_table table, /*!< in: which table */
199
ulint n); /*!< in: row number */
201
/*******************************************************************//**
202
Update the transactions cache if it has not been read for some time.
203
@return 0 - fetched, 1 - not */
206
trx_i_s_possibly_fetch_data_into_cache(
207
/*===================================*/
208
trx_i_s_cache_t* cache); /*!< in/out: cache */
210
/*******************************************************************//**
211
Returns TRUE if the data in the cache is truncated due to the memory
212
limit posed by TRX_I_S_MEM_LIMIT.
213
@return TRUE if truncated */
216
trx_i_s_cache_is_truncated(
217
/*=======================*/
218
trx_i_s_cache_t* cache); /*!< in: cache */
220
/** The maximum length of a resulting lock_id_size in
221
trx_i_s_create_lock_id(), not including the terminating NUL.
222
":%lu:%lu:%lu" -> 63 chars */
223
#define TRX_I_S_LOCK_ID_MAX_LEN (TRX_ID_MAX_LEN + 63)
225
/*******************************************************************//**
226
Crafts a lock id string from a i_s_locks_row_t object. Returns its
227
second argument. This function aborts if there is not enough space in
228
lock_id. Be sure to provide at least TRX_I_S_LOCK_ID_MAX_LEN + 1 if you
229
want to be 100% sure that it will not abort.
230
@return resulting lock id */
233
trx_i_s_create_lock_id(
234
/*===================*/
235
const i_s_locks_row_t* row, /*!< in: innodb_locks row */
236
char* lock_id,/*!< out: resulting lock_id */
237
ulint lock_id_size);/*!< in: size of the lock id
240
#endif /* trx0i_s_h */