~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 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 "ut0ut.h"
 
34
 
 
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 */
 
38
 
 
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
 
42
 
 
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
 
46
 
 
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;
 
53
 
 
54
/** Objects of trx_i_s_cache_t::locks_hash */
 
55
typedef struct i_s_hash_chain_struct    i_s_hash_chain_t;
 
56
 
 
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 */
 
63
};
 
64
 
 
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. */
 
78
        /* @{ */
 
79
        ulint           lock_space;     /*!< tablespace identifier */
 
80
        ulint           lock_page;      /*!< page number within the_space */
 
81
        ulint           lock_rec;       /*!< heap number of the record
 
82
                                        on the page */
 
83
        const char*     lock_data;      /*!< (some) content of the record */
 
84
        /* @} */
 
85
 
 
86
        /** The following are auxiliary and not included in the table */
 
87
        /* @{ */
 
88
        ullint          lock_table_id;
 
89
                                        /*!< table identifier from
 
90
                                        lock_get_table_id */
 
91
        i_s_hash_chain_t hash_chain;    /*!< hash table chain node for
 
92
                                        trx_i_s_cache_t::locks_hash */
 
93
        /* @} */
 
94
};
 
95
 
 
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 */
 
113
};
 
114
 
 
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 */
 
119
};
 
120
 
 
121
/** Cache of INFORMATION_SCHEMA table data */
 
122
typedef struct trx_i_s_cache_struct     trx_i_s_cache_t;
 
123
 
 
124
/** Auxiliary enum used by functions that need to select one of the
 
125
INFORMATION_SCHEMA tables */
 
126
enum i_s_table {
 
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 */
 
130
};
 
131
 
 
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;
 
136
 
 
137
/*******************************************************************//**
 
138
Initialize INFORMATION SCHEMA trx related cache. */
 
139
UNIV_INTERN
 
140
void
 
141
trx_i_s_cache_init(
 
142
/*===============*/
 
143
        trx_i_s_cache_t*        cache); /*!< out: cache to init */
 
144
 
 
145
/*******************************************************************//**
 
146
Issue a shared/read lock on the tables cache. */
 
147
UNIV_INTERN
 
148
void
 
149
trx_i_s_cache_start_read(
 
150
/*=====================*/
 
151
        trx_i_s_cache_t*        cache); /*!< in: cache */
 
152
 
 
153
/*******************************************************************//**
 
154
Release a shared/read lock on the tables cache. */
 
155
UNIV_INTERN
 
156
void
 
157
trx_i_s_cache_end_read(
 
158
/*===================*/
 
159
        trx_i_s_cache_t*        cache); /*!< in: cache */
 
160
 
 
161
/*******************************************************************//**
 
162
Issue an exclusive/write lock on the tables cache. */
 
163
UNIV_INTERN
 
164
void
 
165
trx_i_s_cache_start_write(
 
166
/*======================*/
 
167
        trx_i_s_cache_t*        cache); /*!< in: cache */
 
168
 
 
169
/*******************************************************************//**
 
170
Release an exclusive/write lock on the tables cache. */
 
171
UNIV_INTERN
 
172
void
 
173
trx_i_s_cache_end_write(
 
174
/*====================*/
 
175
        trx_i_s_cache_t*        cache); /*!< in: cache */
 
176
 
 
177
 
 
178
/*******************************************************************//**
 
179
Retrieves the number of used rows in the cache for a given
 
180
INFORMATION SCHEMA table.
 
181
@return number of rows */
 
182
UNIV_INTERN
 
183
ulint
 
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 */
 
188
 
 
189
/*******************************************************************//**
 
190
Retrieves the nth row in the cache for a given INFORMATION SCHEMA
 
191
table.
 
192
@return row */
 
193
UNIV_INTERN
 
194
void*
 
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 */
 
200
 
 
201
/*******************************************************************//**
 
202
Update the transactions cache if it has not been read for some time.
 
203
@return 0 - fetched, 1 - not */
 
204
UNIV_INTERN
 
205
int
 
206
trx_i_s_possibly_fetch_data_into_cache(
 
207
/*===================================*/
 
208
        trx_i_s_cache_t*        cache); /*!< in/out: cache */
 
209
 
 
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 */
 
214
UNIV_INTERN
 
215
ibool
 
216
trx_i_s_cache_is_truncated(
 
217
/*=======================*/
 
218
        trx_i_s_cache_t*        cache); /*!< in: cache */
 
219
 
 
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)
 
224
 
 
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 */
 
231
UNIV_INTERN
 
232
char*
 
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
 
238
                                        buffer */
 
239
 
 
240
#endif /* trx0i_s_h */