Browse Source
MDEV-4702 - Reduce usage of LOCK_open
MDEV-4702 - Reduce usage of LOCK_open
Following variables do not require LOCK_open protection anymore: - table_def_cache (renamed to tdc_hash) is protected by rw-lock LOCK_tdc_hash; - table_def_shutdown_in_progress doesn't need LOCK_open protection; - last_table_id use atomics; - TABLE_SHARE::ref_count (renamed to TABLE_SHARE::tdc.ref_count) is protected by TABLE_SHARE::tdc.LOCK_table_share; - TABLE_SHARE::next, ::prev (renamed to tdc.next and tdc.prev), oldest_unused_share, end_of_unused_share are protected by LOCK_unused_shares; - TABLE_SHARE::m_flush_tickets (renamed to tdc.m_flush_tickets) is protected by TABLE_SHARE::tdc.LOCK_table_share; - refresh_version (renamed to tdc_version) use atomics.pull/3/head
25 changed files with 1651 additions and 1247 deletions
-
1libmysqld/CMakeLists.txt
-
4mysql-test/r/mysqld--help.result
-
4mysql-test/suite/perfschema/r/dml_setup_instruments.result
-
3mysql-test/suite/sys_vars/r/table_open_cache_instances_basic.result
-
1mysql-test/suite/sys_vars/t/table_open_cache_instances_basic.test
-
1sql/CMakeLists.txt
-
4sql/ha_ndbcluster_binlog.cc
-
20sql/handler.cc
-
59sql/mysqld.cc
-
3sql/mysqld.h
-
10sql/sql_admin.cc
-
1078sql/sql_base.cc
-
91sql/sql_base.h
-
2sql/sql_manager.cc
-
4sql/sql_parse.cc
-
6sql/sql_show.cc
-
2sql/sql_table.cc
-
30sql/sql_test.cc
-
13sql/sys_vars.cc
-
99sql/table.cc
-
36sql/table.h
-
1280sql/table_cache.cc
-
134sql/table_cache.h
-
2storage/connect/ha_connect.cc
-
11storage/innobase/handler/ha_innodb.cc
@ -0,0 +1,3 @@ |
|||
select @@table_open_cache_instances; |
|||
@@table_open_cache_instances |
|||
1 |
@ -0,0 +1 @@ |
|||
select @@table_open_cache_instances; |
1078
sql/sql_base.cc
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
1280
sql/table_cache.cc
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,134 @@ |
|||
/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. |
|||
Copyright (c) 2010, 2011 Monty Program Ab |
|||
Copyright (C) 2013 Sergey Vojtovich and MariaDB Foundation |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; version 2 of the License. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
|||
|
|||
|
|||
enum enum_tdc_remove_table_type |
|||
{ |
|||
TDC_RT_REMOVE_ALL, |
|||
TDC_RT_REMOVE_NOT_OWN, |
|||
TDC_RT_REMOVE_UNUSED, |
|||
TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE |
|||
}; |
|||
|
|||
extern ulong tdc_size; |
|||
extern ulong tc_size; |
|||
extern TABLE *unused_tables; /* FIXME: make private */ |
|||
extern mysql_mutex_t LOCK_open; /* FIXME: make private */ |
|||
|
|||
extern int tdc_init(void); |
|||
extern void tdc_start_shutdown(void); |
|||
extern void tdc_deinit(void); |
|||
extern ulong tdc_records(void); |
|||
extern void tdc_purge(bool all); |
|||
extern void tdc_init_share(TABLE_SHARE *share); |
|||
extern void tdc_deinit_share(TABLE_SHARE *share); |
|||
extern TABLE_SHARE *tdc_lock_share(const char *db, const char *table_name); |
|||
extern void tdc_unlock_share(TABLE_SHARE *share); |
|||
extern TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, |
|||
const char *table_name, |
|||
const char *key, uint key_length, |
|||
uint flags, TABLE **out_table); |
|||
extern void tdc_release_share(TABLE_SHARE *share); |
|||
extern bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type, |
|||
const char *db, const char *table_name, |
|||
bool kill_delayed_threads); |
|||
extern int tdc_wait_for_old_version(THD *thd, const char *db, |
|||
const char *table_name, |
|||
ulong wait_timeout, uint deadlock_weight); |
|||
extern ulong tdc_refresh_version(void); |
|||
extern void tdc_increment_refresh_version(void); |
|||
extern void tdc_assign_new_table_id(TABLE_SHARE *share); |
|||
|
|||
extern uint tc_records(void); |
|||
extern void tc_purge(void); |
|||
extern void tc_add_table(THD *thd, TABLE *table); |
|||
extern bool tc_release_table(TABLE *table); |
|||
|
|||
/** |
|||
Create a table cache key for non-temporary table. |
|||
|
|||
@param key Buffer for key (must be at least NAME_LEN*2+2 bytes). |
|||
@param db Database name. |
|||
@param table_name Table name. |
|||
|
|||
@return Length of key. |
|||
*/ |
|||
|
|||
inline uint tdc_create_key(char *key, const char *db, const char *table_name) |
|||
{ |
|||
/* |
|||
In theory caller should ensure that both db and table_name are |
|||
not longer than NAME_LEN bytes. In practice we play safe to avoid |
|||
buffer overruns. |
|||
*/ |
|||
return (uint) (strmake(strmake(key, db, NAME_LEN) + 1, table_name, |
|||
NAME_LEN) - key + 1); |
|||
} |
|||
|
|||
/** |
|||
Convenience helper: call tdc_acquire_share() without out_table. |
|||
*/ |
|||
|
|||
static inline TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, |
|||
const char *table_name, |
|||
const char *key, |
|||
uint key_length, uint flags) |
|||
{ |
|||
return tdc_acquire_share(thd, db, table_name, key, key_length, flags, 0); |
|||
} |
|||
|
|||
|
|||
/** |
|||
Convenience helper: call tdc_acquire_share() without precomputed cache key. |
|||
*/ |
|||
|
|||
static inline TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, |
|||
const char *table_name, uint flags) |
|||
{ |
|||
char key[MAX_DBKEY_LENGTH]; |
|||
uint key_length; |
|||
key_length= tdc_create_key(key, db, table_name); |
|||
return tdc_acquire_share(thd, db, table_name, key, key_length, flags); |
|||
} |
|||
|
|||
|
|||
/** |
|||
Convenience helper: call tdc_acquire_share() reusing the MDL cache key. |
|||
|
|||
@note lifetime of the returned TABLE_SHARE is limited by the |
|||
lifetime of the TABLE_LIST object!!! |
|||
*/ |
|||
|
|||
uint get_table_def_key(const TABLE_LIST *table_list, const char **key); |
|||
|
|||
static inline TABLE_SHARE *tdc_acquire_share_shortlived(THD *thd, TABLE_LIST *tl, |
|||
uint flags) |
|||
{ |
|||
const char *key; |
|||
uint key_length= get_table_def_key(tl, &key); |
|||
return tdc_acquire_share(thd, tl->db, tl->table_name, key, key_length, flags); |
|||
} |
|||
|
|||
|
|||
class TDC_iterator |
|||
{ |
|||
ulong idx; |
|||
public: |
|||
void init(void); |
|||
void deinit(void); |
|||
TABLE_SHARE *next(void); |
|||
}; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue