| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2013, 2026, Oracle and/or its affiliates. |
| 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, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/sess0sess.h |
| 29 |
InnoDB session state tracker. |
| 30 |
Multi file, shared, system tablespace implementation. |
| 31 |
|
| 32 |
Created 2014-04-30 by Krunal Bauskar |
| 33 |
*******************************************************/ |
| 34 |
|
| 35 |
#ifndef sess0sess_h |
| 36 |
#define sess0sess_h |
| 37 |
|
| 38 |
#include <sql_thd_internal_api.h> |
| 39 |
#include "dict0mem.h" |
| 40 |
#include "log0meb.h" |
| 41 |
#include "srv0tmp.h" |
| 42 |
#include "trx0trx.h" |
| 43 |
#include "univ.i" |
| 44 |
#include "ut0new.h" |
| 45 |
|
| 46 |
#include <map> |
| 47 |
|
| 48 |
class dict_intrinsic_table_t { |
| 49 |
public: |
| 50 |
/** Constructor |
| 51 |
@param[in,out] handler table handler. */ |
| 52 |
dict_intrinsic_table_t(dict_table_t *handler) : m_handler(handler) { |
| 53 |
/* Do nothing. */ |
| 54 |
} |
| 55 |
|
| 56 |
/** Destructor */ |
| 57 |
~dict_intrinsic_table_t() { m_handler = nullptr; } |
| 58 |
|
| 59 |
public: |
| 60 |
/* Table Handler holding other metadata information commonly needed |
| 61 |
for any table. */ |
| 62 |
dict_table_t *m_handler; |
| 63 |
}; |
| 64 |
|
| 65 |
/** InnoDB private data that is cached in THD */ |
| 66 |
typedef std::map< |
| 67 |
std::string, dict_intrinsic_table_t *, std::less<std::string>, |
| 68 |
ut::allocator<std::pair<const std::string, dict_intrinsic_table_t *>>> |
| 69 |
table_cache_t; |
| 70 |
|
| 71 |
class innodb_session_t { |
| 72 |
public: |
| 73 |
/** Constructor */ |
| 74 |
innodb_session_t() |
| 75 |
: m_trx(), m_open_tables(), m_usr_temp_tblsp(), m_intrinsic_temp_tblsp() { |
| 76 |
/* Do nothing. */ |
| 77 |
} |
| 78 |
|
| 79 |
/** Destructor */ |
| 80 |
~innodb_session_t() { |
| 81 |
m_trx = nullptr; |
| 82 |
|
| 83 |
for (table_cache_t::iterator it = m_open_tables.begin(); |
| 84 |
it != m_open_tables.end(); ++it) { |
| 85 |
delete (it->second); |
| 86 |
} |
| 87 |
|
| 88 |
meb::redo_log_archive_session_end(this); |
| 89 |
|
| 90 |
if (m_usr_temp_tblsp != nullptr) { |
| 91 |
ibt::free_tmp(m_usr_temp_tblsp); |
| 92 |
} |
| 93 |
|
| 94 |
if (m_intrinsic_temp_tblsp != nullptr) { |
| 95 |
ibt::free_tmp(m_intrinsic_temp_tblsp); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
/** Cache table handler. |
| 100 |
@param[in] table_name name of the table |
| 101 |
@param[in,out] table table handler to register */ |
| 102 |
void register_table_handler(const char *table_name, dict_table_t *table) { |
| 103 |
ut_ad(lookup_table_handler(table_name) == nullptr); |
| 104 |
m_open_tables.insert(table_cache_t::value_type( |
| 105 |
table_name, new dict_intrinsic_table_t(table))); |
| 106 |
} |
| 107 |
|
| 108 |
/** Lookup for table handler given table_name. |
| 109 |
@param[in] table_name name of the table to lookup */ |
| 110 |
dict_table_t *lookup_table_handler(const char *table_name) { |
| 111 |
table_cache_t::iterator it = m_open_tables.find(table_name); |
| 112 |
return ((it == m_open_tables.end()) ? nullptr : it->second->m_handler); |
| 113 |
} |
| 114 |
|
| 115 |
/** Remove table handler entry. |
| 116 |
@param[in] table_name name of the table to remove */ |
| 117 |
void unregister_table_handler(const char *table_name) { |
| 118 |
table_cache_t::iterator it = m_open_tables.find(table_name); |
| 119 |
if (it == m_open_tables.end()) { |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
delete (it->second); |
| 124 |
m_open_tables.erase(table_name); |
| 125 |
} |
| 126 |
|
| 127 |
/** Count of register table handler. |
| 128 |
@return number of register table handlers */ |
| 129 |
uint count_register_table_handler() const { |
| 130 |
return (static_cast<uint>(m_open_tables.size())); |
| 131 |
} |
| 132 |
|
| 133 |
ibt::Tablespace *get_usr_temp_tblsp() { |
| 134 |
if (m_usr_temp_tblsp == nullptr) { |
| 135 |
my_thread_id id = thd_thread_id(m_trx->mysql_thd); |
| 136 |
m_usr_temp_tblsp = ibt::tbsp_pool->get(id, ibt::TBSP_USER); |
| 137 |
} |
| 138 |
|
| 139 |
return (m_usr_temp_tblsp); |
| 140 |
} |
| 141 |
|
| 142 |
ibt::Tablespace *get_instrinsic_temp_tblsp() { |
| 143 |
if (m_intrinsic_temp_tblsp == nullptr) { |
| 144 |
my_thread_id id = thd_thread_id(m_trx->mysql_thd); |
| 145 |
m_intrinsic_temp_tblsp = ibt::tbsp_pool->get(id, ibt::TBSP_INTRINSIC); |
| 146 |
} |
| 147 |
|
| 148 |
return (m_intrinsic_temp_tblsp); |
| 149 |
} |
| 150 |
|
| 151 |
public: |
| 152 |
/** transaction handler. */ |
| 153 |
trx_t *m_trx; |
| 154 |
|
| 155 |
/** Handler of tables that are created or open but not added |
| 156 |
to InnoDB dictionary as they are session specific. |
| 157 |
Currently, limited to intrinsic temporary tables only. */ |
| 158 |
table_cache_t m_open_tables; |
| 159 |
|
| 160 |
private: |
| 161 |
/** Current session's user temp tablespace */ |
| 162 |
ibt::Tablespace *m_usr_temp_tblsp; |
| 163 |
|
| 164 |
/** Current session's optimizer temp tablespace */ |
| 165 |
ibt::Tablespace *m_intrinsic_temp_tblsp; |
| 166 |
}; |
| 167 |
|
| 168 |
#endif /* sess0sess_h */ |