~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/trx0i_s.h

  • Committer: Lee
  • Date: 2008-10-30 22:02:01 UTC
  • mto: (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 573.
  • Revision ID: lbieber@lbieber-desktop-20081030220201-elb6qprbzpn7c5a4
add my name to the AUTHORS file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 2007, 2009, 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/trx0i_s.h
21
 
INFORMATION SCHEMA innodb_trx, innodb_locks and
22
 
innodb_lock_waits tables cache structures and public
23
 
functions.
24
 
 
25
 
Created July 17, 2007 Vasil Dimov
26
 
*******************************************************/
27
 
 
28
 
#ifndef trx0i_s_h
29
 
#define trx0i_s_h
30
 
 
31
 
#include "univ.i"
32
 
#include "trx0types.h"
33
 
#include "dict0types.h"
34
 
#include "ut0ut.h"
35
 
 
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 */
39
 
 
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
43
 
 
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
47
 
 
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
51
 
 
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
55
 
 
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
59
 
 
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)    \
63
 
do {                                                            \
64
 
        if (strlen(data) > constraint) {                        \
65
 
                char    buff[constraint + 1];                   \
66
 
                strncpy(buff, data, constraint);                \
67
 
                buff[constraint] = '\0';                        \
68
 
                                                                \
69
 
                field = static_cast<const char *>(ha_storage_put_memlim(                        \
70
 
                        (tcache)->storage, buff, constraint + 1,\
71
 
                        MAX_ALLOWED_FOR_STORAGE(tcache)));      \
72
 
        } else {                                                \
73
 
                field = static_cast<const char *>(ha_storage_put_str_memlim(            \
74
 
                        (tcache)->storage, data,                \
75
 
                        MAX_ALLOWED_FOR_STORAGE(tcache)));      \
76
 
        }                                                       \
77
 
} while (0)
78
 
 
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;
85
 
 
86
 
/** Objects of trx_i_s_cache_t::locks_hash */
87
 
typedef struct i_s_hash_chain_struct    i_s_hash_chain_t;
88
 
 
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 */
95
 
};
96
 
 
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. */
110
 
        /* @{ */
111
 
        ulint           lock_space;     /*!< tablespace identifier */
112
 
        ulint           lock_page;      /*!< page number within the_space */
113
 
        ulint           lock_rec;       /*!< heap number of the record
114
 
                                        on the page */
115
 
        const char*     lock_data;      /*!< (some) content of the record */
116
 
        /* @} */
117
 
 
118
 
        /** The following are auxiliary and not included in the table */
119
 
        /* @{ */
120
 
        table_id_t      lock_table_id;
121
 
                                        /*!< table identifier from
122
 
                                        lock_get_table_id */
123
 
        i_s_hash_chain_t hash_chain;    /*!< hash table chain node for
124
 
                                        trx_i_s_cache_t::locks_hash */
125
 
        /* @} */
126
 
};
127
 
 
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
145
 
                                         trx_struct */
146
 
        ulint           trx_tables_locked;
147
 
                                        /*!< mysql_n_tables_locked in
148
 
                                        trx_struct */
149
 
        ulint           trx_lock_structs;/*!< list len of trx_locks in
150
 
                                        trx_struct */
151
 
        ulint           trx_lock_memory_bytes;
152
 
                                        /*!< mem_heap_get_size(
153
 
                                        trx->lock_heap) */
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
158
 
                                        trx_struct */
159
 
        const char*     trx_isolation_level;
160
 
                                        /*!< isolation_level in trx_struct*/
161
 
        ibool           trx_unique_checks;
162
 
                                        /*!< check_unique_secondary in
163
 
                                        trx_struct*/
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
172
 
                                        trx_struct */
173
 
};
174
 
 
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 */
179
 
};
180
 
 
181
 
/** Cache of INFORMATION_SCHEMA table data */
182
 
typedef struct trx_i_s_cache_struct     trx_i_s_cache_t;
183
 
 
184
 
/** Auxiliary enum used by functions that need to select one of the
185
 
INFORMATION_SCHEMA tables */
186
 
enum i_s_table {
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 */
190
 
};
191
 
 
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;
196
 
 
197
 
/*******************************************************************//**
198
 
Initialize INFORMATION SCHEMA trx related cache. */
199
 
UNIV_INTERN
200
 
void
201
 
trx_i_s_cache_init(
202
 
/*===============*/
203
 
        trx_i_s_cache_t*        cache); /*!< out: cache to init */
204
 
/*******************************************************************//**
205
 
Free the INFORMATION SCHEMA trx related cache. */
206
 
UNIV_INTERN
207
 
void
208
 
trx_i_s_cache_free(
209
 
/*===============*/
210
 
        trx_i_s_cache_t*        cache); /*!< in/out: cache to free */
211
 
 
212
 
/*******************************************************************//**
213
 
Issue a shared/read lock on the tables cache. */
214
 
UNIV_INTERN
215
 
void
216
 
trx_i_s_cache_start_read(
217
 
/*=====================*/
218
 
        trx_i_s_cache_t*        cache); /*!< in: cache */
219
 
 
220
 
/*******************************************************************//**
221
 
Release a shared/read lock on the tables cache. */
222
 
UNIV_INTERN
223
 
void
224
 
trx_i_s_cache_end_read(
225
 
/*===================*/
226
 
        trx_i_s_cache_t*        cache); /*!< in: cache */
227
 
 
228
 
/*******************************************************************//**
229
 
Issue an exclusive/write lock on the tables cache. */
230
 
UNIV_INTERN
231
 
void
232
 
trx_i_s_cache_start_write(
233
 
/*======================*/
234
 
        trx_i_s_cache_t*        cache); /*!< in: cache */
235
 
 
236
 
/*******************************************************************//**
237
 
Release an exclusive/write lock on the tables cache. */
238
 
UNIV_INTERN
239
 
void
240
 
trx_i_s_cache_end_write(
241
 
/*====================*/
242
 
        trx_i_s_cache_t*        cache); /*!< in: cache */
243
 
 
244
 
 
245
 
/*******************************************************************//**
246
 
Retrieves the number of used rows in the cache for a given
247
 
INFORMATION SCHEMA table.
248
 
@return number of rows */
249
 
UNIV_INTERN
250
 
ulint
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 */
255
 
 
256
 
/*******************************************************************//**
257
 
Retrieves the nth row in the cache for a given INFORMATION SCHEMA
258
 
table.
259
 
@return row */
260
 
UNIV_INTERN
261
 
void*
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 */
267
 
 
268
 
/*******************************************************************//**
269
 
Update the transactions cache if it has not been read for some time.
270
 
@return 0 - fetched, 1 - not */
271
 
UNIV_INTERN
272
 
int
273
 
trx_i_s_possibly_fetch_data_into_cache(
274
 
/*===================================*/
275
 
        trx_i_s_cache_t*        cache); /*!< in/out: cache */
276
 
 
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 */
281
 
UNIV_INTERN
282
 
ibool
283
 
trx_i_s_cache_is_truncated(
284
 
/*=======================*/
285
 
        trx_i_s_cache_t*        cache); /*!< in: cache */
286
 
 
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)
291
 
 
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 */
298
 
UNIV_INTERN
299
 
char*
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
305
 
                                        buffer */
306
 
 
307
 
#endif /* trx0i_s_h */