summaryrefslogtreecommitdiff
path: root/sql/sql_handler.cc
diff options
context:
space:
mode:
authorKonstantin Osipov <kostja@sun.com>2009-12-04 02:29:40 +0300
committerKonstantin Osipov <kostja@sun.com>2009-12-04 02:29:40 +0300
commit911c673edf45616137d71f43f472be410ecb7511 (patch)
treeb92c9a920e36266d14745ea0ed62dc5e44025dd3 /sql/sql_handler.cc
parent8582b4de5d2a44f64de2f6aaa15638d288953939 (diff)
downloadmariadb-git-911c673edf45616137d71f43f472be410ecb7511.tar.gz
Backport of:
------------------------------------------------------------ revno: 2617.23.18 committer: Davi Arnaut <Davi.Arnaut@Sun.COM> branch nick: 4284-6.0 timestamp: Mon 2009-03-02 18:18:26 -0300 message: Bug#989: If DROP TABLE while there's an active transaction, wrong binlog order WL#4284: Transactional DDL locking This is a prerequisite patch: These changes are intended to split lock requests from granted locks and to allow the memory and lifetime of granted locks to be managed within the MDL subsystem. Furthermore, tickets can now be shared and therefore are used to satisfy multiple lock requests, but only shared locks can be recursive. The problem is that the MDL subsystem morphs lock requests into granted locks locks but does not manage the memory and lifetime of lock requests, and hence, does not manage the memory of granted locks either. This can be problematic because it puts the burden of tracking references on the users of the subsystem and it can't be easily done in transactional contexts where the locks have to be kept around for the duration of a transaction. Another issue is that recursive locks (when the context trying to acquire a lock already holds a lock on the same object) requires that each time the lock is granted, a unique lock request/granted lock structure structure must be kept around until the lock is released. This can lead to memory leaks in transactional contexts as locks taken during the transaction should only be released at the end of the transaction. This also leads to unnecessary wake ups (broadcasts) in the MDL subsystem if the context still holds a equivalent of the lock being released. These issues are exacerbated due to the fact that WL#4284 low-level design says that the implementation should "2) Store metadata locks in transaction memory root, rather than statement memory root" but this is not possible because a memory root, as implemented in mysys, requires all objects allocated from it to be freed all at once. This patch combines review input and significant code contributions from Konstantin Osipov (kostja) and Dmitri Lenev (dlenev).
Diffstat (limited to 'sql/sql_handler.cc')
-rw-r--r--sql/sql_handler.cc25
1 files changed, 12 insertions, 13 deletions
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index 49d6cbaa447..83c5c60dc01 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -125,7 +125,7 @@ static void mysql_ha_hash_free(TABLE_LIST *tables)
static void mysql_ha_close_table(THD *thd, TABLE_LIST *tables)
{
TABLE **table_ptr;
- MDL_LOCK_DATA *mdl_lock_data;
+ MDL_LOCK_TICKET *mdl_lock_ticket;
/*
Though we could take the table pointer from hash_tables->table,
@@ -141,7 +141,7 @@ static void mysql_ha_close_table(THD *thd, TABLE_LIST *tables)
if (*table_ptr)
{
(*table_ptr)->file->ha_index_or_rnd_end();
- mdl_lock_data= (*table_ptr)->mdl_lock_data;
+ mdl_lock_ticket= (*table_ptr)->mdl_lock_ticket;
pthread_mutex_lock(&LOCK_open);
if (close_thread_table(thd, table_ptr))
{
@@ -149,8 +149,8 @@ static void mysql_ha_close_table(THD *thd, TABLE_LIST *tables)
broadcast_refresh();
}
pthread_mutex_unlock(&LOCK_open);
- mdl_release_lock(&thd->handler_mdl_context, mdl_lock_data);
- mdl_remove_lock(&thd->handler_mdl_context, mdl_lock_data);
+ mdl_ticket_release(&thd->handler_mdl_context, mdl_lock_ticket);
+ mdl_request_remove(&thd->handler_mdl_context, tables->mdl_lock_request);
}
else if (tables->table)
{
@@ -190,12 +190,12 @@ static void mysql_ha_close_table(THD *thd, TABLE_LIST *tables)
bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
{
TABLE_LIST *hash_tables = NULL;
- MDL_LOCK_DATA *mdl_lock_data;
- char *db, *name, *alias, *mdlkey;
+ char *db, *name, *alias;
uint dblen, namelen, aliaslen, counter;
int error;
TABLE *backup_open_tables;
MDL_CONTEXT backup_mdl_context;
+ MDL_LOCK_REQUEST *mdl_lock_request;
DBUG_ENTER("mysql_ha_open");
DBUG_PRINT("enter",("'%s'.'%s' as '%s' reopen: %d",
tables->db, tables->table_name, tables->alias,
@@ -246,8 +246,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
&db, (uint) dblen,
&name, (uint) namelen,
&alias, (uint) aliaslen,
- &mdl_lock_data, sizeof(MDL_LOCK_DATA),
- &mdlkey, MAX_MDLKEY_LENGTH,
+ &mdl_lock_request, sizeof(MDL_LOCK_REQUEST),
NullS)))
{
DBUG_PRINT("exit",("ERROR"));
@@ -261,8 +260,8 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
memcpy(hash_tables->db, tables->db, dblen);
memcpy(hash_tables->table_name, tables->table_name, namelen);
memcpy(hash_tables->alias, tables->alias, aliaslen);
- mdl_init_lock(mdl_lock_data, mdlkey, 0, db, name);
- hash_tables->mdl_lock_data= mdl_lock_data;
+ mdl_request_init(mdl_lock_request, 0, db, name);
+ hash_tables->mdl_lock_request= mdl_lock_request;
/* add to hash */
if (my_hash_insert(&thd->handler_tables_hash, (uchar*) hash_tables))
@@ -801,11 +800,11 @@ void mysql_ha_flush(THD *thd)
{
hash_tables= (TABLE_LIST*) my_hash_element(&thd->handler_tables_hash, i);
/*
- TABLE::mdl_lock_data is 0 for temporary tables so we need extra check.
+ TABLE::mdl_lock_ticket is 0 for temporary tables so we need extra check.
*/
if (hash_tables->table &&
- (hash_tables->table->mdl_lock_data &&
- mdl_has_pending_conflicting_lock(hash_tables->table->mdl_lock_data) ||
+ (hash_tables->table->mdl_lock_ticket &&
+ mdl_has_pending_conflicting_lock(hash_tables->table->mdl_lock_ticket) ||
hash_tables->table->needs_reopen()))
mysql_ha_close_table(thd, hash_tables);
}