Skip to content

Commit 1144acb

Browse files
committed
tokudb: create and destroy TOKUDB_SHARE::_open_tables_mutex dynamically
to guarantee that it's destroyed when plugin deinit is called, not after
1 parent 3a9276b commit 1144acb

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

storage/tokudb/ha_tokudb.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static inline uint get_ext_key_parts(const KEY *key) {
4848
#endif // defined(TOKU_INCLUDE_EXTENDED_KEYS) && TOKU_INCLUDE_EXTENDED_KEYS
4949

5050
std::unordered_map<std::string, TOKUDB_SHARE*> TOKUDB_SHARE::_open_tables;
51-
tokudb::thread::mutex_t TOKUDB_SHARE::_open_tables_mutex;
51+
tokudb::thread::mutex_t* TOKUDB_SHARE::_open_tables_mutex;
5252

5353
static const char* ha_tokudb_exts[] = {
5454
ha_tokudb_ext,
@@ -154,6 +154,7 @@ static void free_key_and_col_info (KEY_AND_COL_INFO* kc_info) {
154154

155155
void TOKUDB_SHARE::static_init() {
156156
assert_always(_open_tables.size() == 0);
157+
_open_tables_mutex = new tokudb::thread::mutex_t();
157158
}
158159
void TOKUDB_SHARE::static_destroy() {
159160
for (auto it = _open_tables.cbegin(); it != _open_tables.cend(); it++) {
@@ -164,6 +165,7 @@ void TOKUDB_SHARE::static_destroy() {
164165
}
165166
_open_tables.clear();
166167
assert_always(_open_tables.size() == 0);
168+
delete _open_tables_mutex;
167169
}
168170
const char* TOKUDB_SHARE::get_state_string(share_state_t state) {
169171
static const char* state_string[] = {
@@ -218,7 +220,7 @@ TOKUDB_SHARE* TOKUDB_SHARE::get_share(const char* table_name,
218220
THR_LOCK_DATA* data,
219221
bool create_new) {
220222
std::string find_table_name(table_name);
221-
mutex_t_lock(_open_tables_mutex);
223+
mutex_t_lock(*_open_tables_mutex);
222224
auto it = _open_tables.find(find_table_name);
223225
TOKUDB_SHARE *share = nullptr;
224226
if (it != _open_tables.end()) {
@@ -251,7 +253,7 @@ TOKUDB_SHARE* TOKUDB_SHARE::get_share(const char* table_name,
251253
thr_lock_data_init(&(share->_thr_lock), data, NULL);
252254

253255
exit:
254-
mutex_t_unlock(_open_tables_mutex);
256+
mutex_t_unlock(*_open_tables_mutex);
255257
return share;
256258
}
257259
void TOKUDB_SHARE::drop_share(TOKUDB_SHARE* share) {
@@ -262,12 +264,12 @@ void TOKUDB_SHARE::drop_share(TOKUDB_SHARE* share) {
262264
get_state_string(share->_state),
263265
share->_use_count);
264266

265-
mutex_t_lock(_open_tables_mutex);
267+
mutex_t_lock(*_open_tables_mutex);
266268
size_t n = _open_tables.erase(std::string(share->full_table_name()));
267269
assert_always(n == 1);
268270
share->destroy();
269271
delete share;
270-
mutex_t_unlock(_open_tables_mutex);
272+
mutex_t_unlock(*_open_tables_mutex);
271273
}
272274
TOKUDB_SHARE::share_state_t TOKUDB_SHARE::addref() {
273275
TOKUDB_SHARE_TRACE_FOR_FLAGS((TOKUDB_DEBUG_ENTER & TOKUDB_DEBUG_SHARE),

storage/tokudb/ha_tokudb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class TOKUDB_SHARE {
274274

275275
private:
276276
static std::unordered_map<std::string, TOKUDB_SHARE*> _open_tables;
277-
static tokudb::thread::mutex_t _open_tables_mutex;
277+
static tokudb::thread::mutex_t* _open_tables_mutex;
278278

279279
//*********************************
280280
// Spans open-close-open

0 commit comments

Comments
 (0)