| 1 | /***************************************************************************** |
| 2 | |
| 3 | Copyright (c) 2007, 2015, Oracle and/or its affiliates. All Rights Reserved. |
| 4 | Copyright (c) 2017, 2021, MariaDB Corporation. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it under |
| 7 | the terms of the GNU General Public License as published by the Free Software |
| 8 | Foundation; version 2 of the License. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License along with |
| 15 | this program; if not, write to the Free Software Foundation, Inc., |
| 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA |
| 17 | |
| 18 | *****************************************************************************/ |
| 19 | |
| 20 | /**************************************************//** |
| 21 | @file include/trx0i_s.h |
| 22 | INFORMATION SCHEMA innodb_trx, innodb_locks and |
| 23 | innodb_lock_waits tables cache structures and public |
| 24 | functions. |
| 25 | |
| 26 | Created July 17, 2007 Vasil Dimov |
| 27 | *******************************************************/ |
| 28 | |
| 29 | #ifndef trx0i_s_h |
| 30 | #define trx0i_s_hcxx . . $ `storage/innobase/include/trx0i_s.h:30:9`! |
| 31 | |
| 32 | #include "trx0types.h"cxx . . $ `<file>/storage/innobase/include/trx0types.h`/ |
| 33 | #include "dict0types.h"cxx . . $ `<file>/storage/innobase/include/dict0types.h`/ |
| 34 | #include "buf0types.h"cxx . . $ `<file>/storage/innobase/include/buf0types.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_LIMITcxx . . $ `storage/innobase/include/trx0i_s.h:38:9`! 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_LENcxx . . $ `storage/innobase/include/trx0i_s.h:42:9`! 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_LENcxx . . $ `storage/innobase/include/trx0i_s.h:46:9`! 1024 |
| 47 | |
| 48 | /** The maximum length of a string that can be stored in |
| 49 | i_s_trx_row_t::trx_foreign_key_error */ |
| 50 | #define TRX_I_S_TRX_FK_ERROR_MAX_LENcxx . . $ `storage/innobase/include/trx0i_s.h:50:9`! 256 |
| 51 | |
| 52 | /** Safely copy strings in to the INNODB_TRX table's |
| 53 | string based columns */ |
| 54 | #define TRX_I_S_STRING_COPYcxx . . $ `storage/innobase/include/trx0i_s.h:54:9`!(data, field, constraint, tcache) \ |
| 55 | do { \ |
| 56 | if (strlen(data) > constraint) { \ |
| 57 | char buff[constraint + 1]; \ |
| 58 | strncpy(buff, data, constraint); \ |
| 59 | buff[constraint] = '\0'; \ |
| 60 | \ |
| 61 | field = static_cast<const char*>( \ |
| 62 | ha_storage_put_memlim( \ |
| 63 | (tcache)->storage, buff, constraint + 1,\ |
| 64 | MAX_ALLOWED_FOR_STORAGEcxx . . $ `storage/innobase/trx/trx0i_s.cc:66:9`!(tcache))); \ |
| 65 | } else { \ |
| 66 | field = static_cast<const char*>( \ |
| 67 | ha_storage_put_str_memlimcxx . . $ `storage/innobase/include/ha0storage.h:102:9`!( \ |
| 68 | (tcache)->storage, data, \ |
| 69 | MAX_ALLOWED_FOR_STORAGEcxx . . $ `storage/innobase/trx/trx0i_s.cc:66:9`!(tcache))); \ |
| 70 | } \ |
| 71 | } while (0) |
| 72 | |
| 73 | /** This structure represents INFORMATION_SCHEMA.innodb_locks row */ |
| 74 | struct i_s_locks_row_tcxx . . $ i_s_locks_row_t# { |
| 75 | trx_id_tcxx . . $ trx_id_t# lock_trx_idcxx . . $ i_s_locks_row_t#lock_trx_id.; /*!< transaction identifier */ |
| 76 | const char* lock_tablecxx . . $ i_s_locks_row_t#lock_table.; /*!< table name from |
| 77 | lock_get_table_name() */ |
| 78 | /** index name of a record lock; NULL for table locks */ |
| 79 | const char* lock_indexcxx . . $ i_s_locks_row_t#lock_index.; |
| 80 | /** page identifier of the record; (0,0) if !lock_index */ |
| 81 | page_id_tcxx . . $ page_id_t# lock_pagecxx . . $ i_s_locks_row_t#lock_page.; |
| 82 | /** heap number of the record; 0 if !lock_index */ |
| 83 | uint16_tcxx . . $ uint16_t# lock_reccxx . . $ i_s_locks_row_t#lock_rec.; |
| 84 | /** lock mode corresponding to lock_mode_values_typelib */ |
| 85 | uint8_tcxx . . $ uint8_t# lock_modecxx . . $ i_s_locks_row_t#lock_mode.; |
| 86 | /** (some) content of the record, if available in the buffer pool; |
| 87 | NULL if !lock_index */ |
| 88 | const char* lock_datacxx . . $ i_s_locks_row_t#lock_data.; |
| 89 | |
| 90 | /** The following are auxiliary and not included in the table */ |
| 91 | /* @{ */ |
| 92 | table_id_tcxx . . $ table_id_t# lock_table_idcxx . . $ i_s_locks_row_t#lock_table_id.; |
| 93 | /*!< table identifier from |
| 94 | lock_get_table_id */ |
| 95 | i_s_locks_row_tcxx . . $ i_s_locks_row_t# *nextcxx . . $ i_s_locks_row_t#next.; /*!< hash table chain node for |
| 96 | trx_i_s_cache_t::locks_hash */ |
| 97 | /* @} */ |
| 98 | }; |
| 99 | |
| 100 | /** This structure represents INFORMATION_SCHEMA.innodb_trx row */ |
| 101 | struct i_s_trx_row_tcxx . . $ i_s_trx_row_t# { |
| 102 | trx_id_tcxx . . $ trx_id_t# trx_idcxx . . $ i_s_trx_row_t#trx_id.; /*!< transaction identifier */ |
| 103 | const char* trx_statecxx . . $ i_s_trx_row_t#trx_state.; |
| 104 | time_tcxx . . $ time_t# trx_startedcxx . . $ i_s_trx_row_t#trx_started.; /*!< trx_t::start_time */ |
| 105 | const i_s_locks_row_tcxx . . $ i_s_locks_row_t#* requested_lock_rowcxx . . $ i_s_trx_row_t#requested_lock_row.; |
| 106 | /*!< pointer to a row |
| 107 | in innodb_locks if trx |
| 108 | is waiting, or NULL */ |
| 109 | time_tcxx . . $ time_t# trx_wait_startedcxx . . $ i_s_trx_row_t#trx_wait_started.; /*!< trx_t->lock.wait_started */ |
| 110 | uintmax_tcxx . . $ uintmax_t# trx_weightcxx . . $ i_s_trx_row_t#trx_weight.; /*!< TRX_WEIGHT() */ |
| 111 | my_thread_id trx_mysql_thread_idcxx . . $ i_s_trx_row_t#trx_mysql_thread_id.; /*!< thd_get_thread_id() */ |
| 112 | const char* trx_querycxx . . $ i_s_trx_row_t#trx_query.; /*!< MySQL statement being |
| 113 | executed in the transaction */ |
| 114 | CHARSET_INFOcxx . . $ CHARSET_INFO#* trx_query_cscxx . . $ i_s_trx_row_t#trx_query_cs.; /*!< the charset of trx_query */ |
| 115 | const char* trx_operation_statecxx . . $ i_s_trx_row_t#trx_operation_state.; /*!< trx_t::op_info */ |
| 116 | ulintcxx . . $ ulint# trx_tables_in_usecxx . . $ i_s_trx_row_t#trx_tables_in_use.;/*!< n_mysql_tables_in_use in |
| 117 | trx_t */ |
| 118 | ulintcxx . . $ ulint# trx_tables_lockedcxx . . $ i_s_trx_row_t#trx_tables_locked.; |
| 119 | /*!< mysql_n_tables_locked in |
| 120 | trx_t */ |
| 121 | ulintcxx . . $ ulint# trx_lock_structscxx . . $ i_s_trx_row_t#trx_lock_structs.;/*!< list len of trx_locks in |
| 122 | trx_t */ |
| 123 | ulintcxx . . $ ulint# trx_lock_memory_bytescxx . . $ i_s_trx_row_t#trx_lock_memory_bytes.; |
| 124 | /*!< mem_heap_get_size( |
| 125 | trx->lock_heap) */ |
| 126 | ulintcxx . . $ ulint# trx_rows_lockedcxx . . $ i_s_trx_row_t#trx_rows_locked.;/*!< trx_lock_t::n_rec_locks */ |
| 127 | uintmax_tcxx . . $ uintmax_t# trx_rows_modifiedcxx . . $ i_s_trx_row_t#trx_rows_modified.;/*!< trx_t::undo_no */ |
| 128 | uint trx_isolation_levelcxx . . $ i_s_trx_row_t#trx_isolation_level.; |
| 129 | /*!< trx_t::isolation_level */ |
| 130 | bool trx_unique_checkscxx . . $ i_s_trx_row_t#trx_unique_checks.; |
| 131 | /*!< check_unique_secondary in trx_t*/ |
| 132 | bool trx_foreign_key_checkscxx . . $ i_s_trx_row_t#trx_foreign_key_checks.; |
| 133 | /*!< check_foreigns in trx_t */ |
| 134 | const char* trx_foreign_key_errorcxx . . $ i_s_trx_row_t#trx_foreign_key_error.; |
| 135 | /*!< detailed_error in trx_t */ |
| 136 | bool trx_is_read_onlycxx . . $ i_s_trx_row_t#trx_is_read_only.; |
| 137 | /*!< trx_t::read_only */ |
| 138 | bool trx_is_autocommit_non_lockingcxx . . $ i_s_trx_row_t#trx_is_autocommit_non_locking.; |
| 139 | /*!< trx:t::is_autocommit_non_locking() |
| 140 | */ |
| 141 | }; |
| 142 | |
| 143 | /** This structure represents INFORMATION_SCHEMA.innodb_lock_waits row */ |
| 144 | struct i_s_lock_waits_row_tcxx . . $ i_s_lock_waits_row_t# { |
| 145 | const i_s_locks_row_tcxx . . $ i_s_locks_row_t#* requested_lock_rowcxx . . $ i_s_lock_waits_row_t#requested_lock_row.; /*!< requested lock */ |
| 146 | const i_s_locks_row_tcxx . . $ i_s_locks_row_t#* blocking_lock_rowcxx . . $ i_s_lock_waits_row_t#blocking_lock_row.; /*!< blocking lock */ |
| 147 | }; |
| 148 | |
| 149 | /** Cache of INFORMATION_SCHEMA table data */ |
| 150 | struct trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#; |
| 151 | |
| 152 | /** Auxiliary enum used by functions that need to select one of the |
| 153 | INFORMATION_SCHEMA tables */ |
| 154 | enum i_s_tablecxx . . $ i_s_table# { |
| 155 | I_S_INNODB_TRXcxx . . $ I_S_INNODB_TRX., /*!< INFORMATION_SCHEMA.innodb_trx */ |
| 156 | I_S_INNODB_LOCKScxx . . $ I_S_INNODB_LOCKS., /*!< INFORMATION_SCHEMA.innodb_locks */ |
| 157 | I_S_INNODB_LOCK_WAITScxx . . $ I_S_INNODB_LOCK_WAITS. /*!< INFORMATION_SCHEMA.innodb_lock_waits */ |
| 158 | }; |
| 159 | |
| 160 | /** This is the intermediate buffer where data needed to fill the |
| 161 | INFORMATION SCHEMA tables is fetched and later retrieved by the C++ |
| 162 | code in handler/i_s.cc. */ |
| 163 | extern trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* trx_i_s_cachecxx . . $ trx_i_s_cache.; |
| 164 | |
| 165 | /*******************************************************************//** |
| 166 | Initialize INFORMATION SCHEMA trx related cache. */ |
| 167 | void |
| 168 | trx_i_s_cache_initcxx . . $ trx_i_s_cache_init(36a48191b4ff9b77).( |
| 169 | /*===============*/ |
| 170 | trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* cache); /*!< out: cache to init */ |
| 171 | /*******************************************************************//** |
| 172 | Free the INFORMATION SCHEMA trx related cache. */ |
| 173 | void |
| 174 | trx_i_s_cache_freecxx . . $ trx_i_s_cache_free(36a48191b4ff9b77).( |
| 175 | /*===============*/ |
| 176 | trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* cache); /*!< in/out: cache to free */ |
| 177 | |
| 178 | /*******************************************************************//** |
| 179 | Issue a shared/read lock on the tables cache. */ |
| 180 | void |
| 181 | trx_i_s_cache_start_readcxx . . $ trx_i_s_cache_start_read(36a48191b4ff9b77).( |
| 182 | /*=====================*/ |
| 183 | trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* cache); /*!< in: cache */ |
| 184 | |
| 185 | /*******************************************************************//** |
| 186 | Release a shared/read lock on the tables cache. */ |
| 187 | void |
| 188 | trx_i_s_cache_end_readcxx . . $ trx_i_s_cache_end_read(36a48191b4ff9b77).( |
| 189 | /*===================*/ |
| 190 | trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* cache); /*!< in: cache */ |
| 191 | |
| 192 | /*******************************************************************//** |
| 193 | Issue an exclusive/write lock on the tables cache. */ |
| 194 | void |
| 195 | trx_i_s_cache_start_writecxx . . $ trx_i_s_cache_start_write(36a48191b4ff9b77).( |
| 196 | /*======================*/ |
| 197 | trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* cache); /*!< in: cache */ |
| 198 | |
| 199 | /*******************************************************************//** |
| 200 | Release an exclusive/write lock on the tables cache. */ |
| 201 | void |
| 202 | trx_i_s_cache_end_writecxx . . $ trx_i_s_cache_end_write(36a48191b4ff9b77).( |
| 203 | /*====================*/ |
| 204 | trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* cache); /*!< in: cache */ |
| 205 | |
| 206 | |
| 207 | /*******************************************************************//** |
| 208 | Retrieves the number of used rows in the cache for a given |
| 209 | INFORMATION SCHEMA table. |
| 210 | @return number of rows */ |
| 211 | ulintcxx . . $ ulint# |
| 212 | trx_i_s_cache_get_rows_usedcxx . . $ trx_i_s_cache_get_rows_used(dd502e55fd1e3425).( |
| 213 | /*========================*/ |
| 214 | trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* cache, /*!< in: cache */ |
| 215 | enum i_s_tablecxx . . $ i_s_table# table); /*!< in: which table */ |
| 216 | |
| 217 | /*******************************************************************//** |
| 218 | Retrieves the nth row in the cache for a given INFORMATION SCHEMA |
| 219 | table. |
| 220 | @return row */ |
| 221 | void* |
| 222 | trx_i_s_cache_get_nth_rowcxx . . $ trx_i_s_cache_get_nth_row(b80cabb39f7f1876).( |
| 223 | /*======================*/ |
| 224 | trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* cache, /*!< in: cache */ |
| 225 | enum i_s_tablecxx . . $ i_s_table# table, /*!< in: which table */ |
| 226 | ulintcxx . . $ ulint# n); /*!< in: row number */ |
| 227 | |
| 228 | /*******************************************************************//** |
| 229 | Update the transactions cache if it has not been read for some time. |
| 230 | @return 0 - fetched, 1 - not */ |
| 231 | int |
| 232 | trx_i_s_possibly_fetch_data_into_cachecxx . . $ trx_i_s_possibly_fetch_data_into_cache(29b05f0e639bac79).( |
| 233 | /*===================================*/ |
| 234 | trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* cache); /*!< in/out: cache */ |
| 235 | |
| 236 | /*******************************************************************//** |
| 237 | Returns true, if the data in the cache is truncated due to the memory |
| 238 | limit posed by TRX_I_S_MEM_LIMIT. |
| 239 | @return TRUE if truncated */ |
| 240 | bool |
| 241 | trx_i_s_cache_is_truncatedcxx . . $ trx_i_s_cache_is_truncated(8a839af7d03b030c).( |
| 242 | /*=======================*/ |
| 243 | trx_i_s_cache_tcxx . . $ trx_i_s_cache_t#* cache); /*!< in: cache */ |
| 244 | /** The maximum length of a resulting lock_id_size in |
| 245 | trx_i_s_create_lock_id(), not including the terminating NUL. |
| 246 | ":%lu:%lu:%lu" -> 63 chars */ |
| 247 | #define TRX_I_S_LOCK_ID_MAX_LENcxx . . $ `storage/innobase/include/trx0i_s.h:247:9`! (TRX_ID_MAX_LEN + 63) |
| 248 | |
| 249 | /*******************************************************************//** |
| 250 | Crafts a lock id string from a i_s_locks_row_t object. Returns its |
| 251 | second argument. This function aborts if there is not enough space in |
| 252 | lock_id. Be sure to provide at least TRX_I_S_LOCK_ID_MAX_LEN + 1 if you |
| 253 | want to be 100% sure that it will not abort. |
| 254 | @return resulting lock id */ |
| 255 | char* |
| 256 | trx_i_s_create_lock_idcxx . . $ trx_i_s_create_lock_id(7edf36efee6e265c).( |
| 257 | /*===================*/ |
| 258 | const i_s_locks_row_tcxx . . $ i_s_locks_row_t#* row, /*!< in: innodb_locks row */ |
| 259 | char* lock_id,/*!< out: resulting lock_id */ |
| 260 | ulintcxx . . $ ulint# lock_id_size);/*!< in: size of the lock id |
| 261 | buffer */ |
| 262 | |
| 263 | #endif /* trx0i_s_h */ |