summaryrefslogtreecommitdiff
path: root/sql/table_cache.cc
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2018-10-31 22:52:29 +0200
committerMonty <monty@mariadb.org>2018-12-09 22:12:26 +0200
commit7fb9d64989ad8bb86ee47ded88dc5e2493aca4b8 (patch)
treea965ed7e10fc1bf4f0c1b052d3a653a6ec33ae47 /sql/table_cache.cc
parent7bb3a5220e9960c5b3c0fd44d656d26d45b3cdef (diff)
downloadmariadb-git-7fb9d64989ad8bb86ee47ded88dc5e2493aca4b8.tar.gz
Changed FLUSH TABLES to not change share version
Part of MDEV-5336 Implement LOCK FOR BACKUP Originally both table metadata lock and global read lock protection were acquired before getting TABLE from table cache. This will be reordered in a future commit with MDL_BACKUP_XXX locks so that we first take table metadata lock, then get TABLE from table cache, then acquire analogue of global read lock. This patch both simplifies FLUSH TABLES code, makes FLUSH TABLES to lock less and also enables FLUSH TABLES code to be used with backup locks. The usage of FLUSH TABLES changes slightly: - FLUSH TABLES without any arguments will now only close not used tables and tables locked by the FLUSH TABLES connection. All not used table shares will be closed. Tables locked by the FLUSH TABLES connection will be reopened and re-locked after all others has stoped using the table (as before). If there was no locked tables, then FLUSH TABLES is instant and will not cause any waits. FLUSH TABLES will not wait for any in use table. - FLUSH TABLES with a table list, will ensure that the tables are closed before statement returns. The code is now only using MDL locks and not table share versions, which simplices the code greatly. One visible change is that the server will wait for the end of the transaction that are using the tables. Before FLUSH TABLES only waited for the statements to end. Signed-off-by: Monty <monty@mariadb.org>
Diffstat (limited to 'sql/table_cache.cc')
-rw-r--r--sql/table_cache.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/sql/table_cache.cc b/sql/table_cache.cc
index d997aeff9f8..c23bb53b9a9 100644
--- a/sql/table_cache.cc
+++ b/sql/table_cache.cc
@@ -1094,6 +1094,7 @@ bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
TABLE *table;
TDC_element *element;
uint my_refs= 1;
+ bool res= false;
DBUG_ENTER("tdc_remove_table");
DBUG_PRINT("enter",("name: %s remove_type: %d", table_name, remove_type));
@@ -1101,7 +1102,6 @@ bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
thd->mdl_context.is_lock_owner(MDL_key::TABLE, db, table_name,
MDL_EXCLUSIVE));
-
mysql_mutex_lock(&LOCK_unused_shares);
if (!(element= tdc_lock_share(thd, db, table_name)))
{
@@ -1123,7 +1123,7 @@ bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
mysql_mutex_unlock(&LOCK_unused_shares);
tdc_delete_share_from_hash(element);
- DBUG_RETURN(true);
+ DBUG_RETURN(false);
}
mysql_mutex_unlock(&LOCK_unused_shares);
@@ -1189,10 +1189,16 @@ bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
#endif
mysql_mutex_unlock(&element->LOCK_table_share);
}
+ else
+ {
+ mysql_mutex_lock(&element->LOCK_table_share);
+ res= element->ref_count > 1;
+ mysql_mutex_unlock(&element->LOCK_table_share);
+ }
tdc_release_share(element->share);
- DBUG_RETURN(true);
+ DBUG_RETURN(res);
}