diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2013-08-14 12:48:50 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2013-08-14 12:48:50 +0400 |
commit | b7f9c894236c38cb40b5ca70e36d23497fcc01be (patch) | |
tree | 26b3f7e1e848893059f66e7e6bc7cc5a8c56c036 /sql/table_cache.h | |
parent | b882a3e83eba1be324f4f898ae24e78244e2378d (diff) | |
download | mariadb-git-b7f9c894236c38cb40b5ca70e36d23497fcc01be.tar.gz |
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.
Diffstat (limited to 'sql/table_cache.h')
-rw-r--r-- | sql/table_cache.h | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/sql/table_cache.h b/sql/table_cache.h new file mode 100644 index 00000000000..91fa650d3b9 --- /dev/null +++ b/sql/table_cache.h @@ -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); +}; |