#At file:///home/dlenev/src/bzr/mysql-6.0-3726-w2/
2657 Dmitry Lenev 2008-06-03 [merge]
WL#3726 "DDL locking for all metadata objects".
Merging one branch with after review changes with another.
modified:
sql/backup/backup_progress.cc
sql/event_db_repository.cc
sql/mysql_priv.h
sql/sql_base.cc
sql/sql_table.cc
sql/table.h
storage/csv/ha_tina.cc
storage/csv/ha_tina.h
=== modified file 'sql/backup/backup_progress.cc'
--- a/sql/backup/backup_progress.cc 2008-05-23 13:54:03 +0000
+++ b/sql/backup/backup_progress.cc 2008-06-02 14:30:18 +0000
@@ -54,7 +54,7 @@ my_bool check_ob_progress_tables(THD *th
DBUG_ENTER("check_ob_progress_tables");
/* Check mysql.online_backup */
- tables.init_one_table("mysql", "online_backup", TL_READ);
+ tables.init_one_table("mysql", "online_backup", "online_backup", TL_READ);
alloc_mdl_locks(&tables, thd->mem_root);
if (simple_open_n_lock_tables(thd, &tables))
{
@@ -65,7 +65,8 @@ my_bool check_ob_progress_tables(THD *th
close_thread_tables(thd);
/* Check mysql.online_backup_progress */
- tables.init_one_table("mysql", "online_backup_progress", TL_READ);
+ tables.init_one_table("mysql", "online_backup_progress",
+ "online_backup_progress", TL_READ);
alloc_mdl_locks(&tables, thd->mem_root);
if (simple_open_n_lock_tables(thd, &tables))
{
=== modified file 'sql/event_db_repository.cc'
--- a/sql/event_db_repository.cc 2008-05-23 13:54:03 +0000
+++ b/sql/event_db_repository.cc 2008-06-02 14:30:18 +0000
@@ -552,7 +552,7 @@ Event_db_repository::open_event_table(TH
TABLE_LIST tables;
DBUG_ENTER("Event_db_repository::open_event_table");
- tables.init_one_table("mysql", "event", lock_type);
+ tables.init_one_table("mysql", "event", "event", lock_type);
alloc_mdl_locks(&tables, thd->mem_root);
if (simple_open_n_lock_tables(thd, &tables))
@@ -1095,7 +1095,7 @@ Event_db_repository::check_system_tables
/* Check mysql.db */
- tables.init_one_table("mysql", "db", TL_READ);
+ tables.init_one_table("mysql", "db", "db", TL_READ);
alloc_mdl_locks(&tables, thd->mem_root);
if (simple_open_n_lock_tables(thd, &tables))
@@ -1113,7 +1113,7 @@ Event_db_repository::check_system_tables
close_thread_tables(thd);
}
/* Check mysql.user */
- tables.init_one_table("mysql", "user", TL_READ);
+ tables.init_one_table("mysql", "user", "user", TL_READ);
alloc_mdl_locks(&tables, thd->mem_root);
if (simple_open_n_lock_tables(thd, &tables))
@@ -1134,7 +1134,7 @@ Event_db_repository::check_system_tables
close_thread_tables(thd);
}
/* Check mysql.event */
- tables.init_one_table("mysql", "event", TL_READ);
+ tables.init_one_table("mysql", "event", "event", TL_READ);
alloc_mdl_locks(&tables, thd->mem_root);
if (simple_open_n_lock_tables(thd, &tables))
=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h 2008-05-29 05:45:02 +0000
+++ b/sql/mysql_priv.h 2008-06-02 14:30:18 +0000
@@ -1135,8 +1135,6 @@ bool check_dup(const char *db, const cha
bool compare_record(TABLE *table);
bool append_file_to_dir(THD *thd, const char **filename_ptr,
const char *table_name);
-bool wait_while_table_is_used(THD *thd, TABLE *table,
- enum ha_extra_function function);
bool table_def_init(void);
void table_def_free(void);
void assign_new_table_id(TABLE_SHARE *share);
@@ -1507,6 +1505,9 @@ void add_join_on(TABLE_LIST *b,Item *exp
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
SELECT_LEX *lex);
bool add_proc_to_list(THD *thd, Item *item);
+bool close_cached_table(THD *thd, TABLE *table);
+bool wait_while_table_is_used(THD *thd, TABLE *table,
+ enum ha_extra_function function);
void unlink_open_table(THD *thd, TABLE *find, bool unlock);
void drop_open_table(THD *thd, TABLE *table, const char *db_name,
const char *table_name);
=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc 2008-06-03 17:07:58 +0000
+++ b/sql/sql_base.cc 2008-06-03 17:41:59 +0000
@@ -2142,6 +2142,84 @@ static void unlink_open_merge(THD *thd,
/**
+ Force all other threads to stop using the table by upgrading
+ metadata lock on it and remove unused TABLE instances from cache.
+
+ @param thd Thread handler
+ @param table Table to remove from cache
+ @param function HA_EXTRA_PREPARE_FOR_DROP if table is to be deleted
+ HA_EXTRA_FORCE_REOPEN if table is not be used
+ HA_EXTRA_PREPARE_FOR_RENAME if table is to be renamed
+
+ @note When returning, the table will be unusable for other threads
+ until metadata lock is downgraded.
+
+ @retval FALSE Success.
+ @retval TRUE Failure (e.g. because thread was killed).
+*/
+
+bool wait_while_table_is_used(THD *thd, TABLE *table,
+ enum ha_extra_function function)
+{
+ enum thr_lock_type old_lock_type;
+
+ DBUG_ENTER("wait_while_table_is_used");
+ DBUG_PRINT("enter", ("table: '%s' share: %p db_stat: %u version: %lu",
+ table->s->table_name.str, table->s,
+ table->db_stat, table->s->version));
+
+ (void) table->file->extra(function);
+
+ old_lock_type= table->reginfo.lock_type;
+ mysql_lock_abort(thd, table, TRUE); /* end threads waiting on lock */
+
+ if (mdl_upgrade_shared_lock_to_exclusive(&thd->mdl_context,
+ table->mdl_lock_data))
+ {
+ mysql_lock_downgrade_write(thd, table, old_lock_type);
+ DBUG_RETURN(TRUE);
+ }
+
+ pthread_mutex_lock(&LOCK_open);
+ expel_table_from_cache(thd, table->s->db.str, table->s->table_name.str);
+ pthread_mutex_unlock(&LOCK_open);
+ DBUG_RETURN(FALSE);
+}
+
+
+/**
+ Upgrade metadata lock on the table and close all its instances.
+
+ @param thd Thread handler
+ @param table Table to remove from cache
+
+ @retval FALSE Success.
+ @retval TRUE Failure (e.g. because thread was killed).
+*/
+
+bool close_cached_table(THD *thd, TABLE *table)
+{
+ DBUG_ENTER("close_cached_table");
+
+ /* FIXME: check if we pass proper parameters everywhere. */
+ if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN))
+ DBUG_RETURN(TRUE);
+
+ /* Close lock if this is not got with LOCK TABLES */
+ if (thd->lock)
+ {
+ mysql_unlock_tables(thd, thd->lock);
+ thd->lock=0; // Start locked threads
+ }
+
+ pthread_mutex_lock(&LOCK_open);
+ /* Close all copies of 'table'. This also frees all LOCK TABLES lock */
+ unlink_open_table(thd, table, TRUE);
+ pthread_mutex_unlock(&LOCK_open);
+ DBUG_RETURN(FALSE);
+}
+
+/**
Remove all instances of table from thread's open list and
table cache.
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2008-06-03 17:07:58 +0000
+++ b/sql/sql_table.cc 2008-06-03 17:41:59 +0000
@@ -53,7 +53,6 @@ static bool
mysql_prepare_alter_table(THD *thd, TABLE *table,
HA_CREATE_INFO *create_info,
Alter_info *alter_info);
-static bool close_cached_table(THD *thd, TABLE *table);
#ifndef DBUG_OFF
@@ -3904,84 +3903,6 @@ mysql_rename_table(handlerton *base, con
}
-/**
- Force all other threads to stop using the table by upgrading
- metadata lock on it and remove unused TABLE instances from cache.
-
- @param thd Thread handler
- @param table Table to remove from cache
- @param function HA_EXTRA_PREPARE_FOR_DROP if table is to be deleted
- HA_EXTRA_FORCE_REOPEN if table is not be used
- HA_EXTRA_PREPARE_FOR_RENAME if table is to be renamed
-
- @note When returning, the table will be unusable for other threads
- until metadata lock is downgraded.
-
- @retval FALSE Success.
- @retval TRUE Failure (e.g. because thread was killed).
-*/
-
-bool wait_while_table_is_used(THD *thd, TABLE *table,
- enum ha_extra_function function)
-{
- enum thr_lock_type old_lock_type;
-
- DBUG_ENTER("wait_while_table_is_used");
- DBUG_PRINT("enter", ("table: '%s' share: %p db_stat: %u version: %lu",
- table->s->table_name.str, table->s,
- table->db_stat, table->s->version));
-
- (void) table->file->extra(function);
-
- old_lock_type= table->reginfo.lock_type;
- mysql_lock_abort(thd, table, TRUE); /* end threads waiting on lock */
-
- if (mdl_upgrade_shared_lock_to_exclusive(&thd->mdl_context,
- table->mdl_lock_data))
- {
- mysql_lock_downgrade_write(thd, table, old_lock_type);
- DBUG_RETURN(TRUE);
- }
-
- pthread_mutex_lock(&LOCK_open);
- expel_table_from_cache(thd, table->s->db.str, table->s->table_name.str);
- pthread_mutex_unlock(&LOCK_open);
- DBUG_RETURN(FALSE);
-}
-
-
-/**
- Upgrade metadata lock on the table and close all its instances.
-
- @param thd Thread handler
- @param table Table to remove from cache
-
- @retval FALSE Success.
- @retval TRUE Failure (e.g. because thread was killed).
-*/
-
-static bool close_cached_table(THD *thd, TABLE *table)
-{
- DBUG_ENTER("close_cached_table");
-
- /* FIXME: check if we pass proper parameters everywhere. */
- if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN))
- DBUG_RETURN(TRUE);
-
- /* Close lock if this is not got with LOCK TABLES */
- if (thd->lock)
- {
- mysql_unlock_tables(thd, thd->lock);
- thd->lock=0; // Start locked threads
- }
-
- pthread_mutex_lock(&LOCK_open);
- /* Close all copies of 'table'. This also frees all LOCK TABLES lock */
- unlink_open_table(thd, table, TRUE);
- pthread_mutex_unlock(&LOCK_open);
- DBUG_RETURN(FALSE);
-}
-
static int send_check_errmsg(THD *thd, TABLE_LIST* table,
const char* operator_name, const char* errmsg)
@@ -6641,8 +6562,8 @@ view_err:
{
error= 0;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
- ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
- table->alias);
+ ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
+ table->alias);
}
if (!error && (new_name != table_name || new_db != db))
@@ -6668,41 +6589,41 @@ view_err:
*/
if (!access(new_name_buff,F_OK))
{
- my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name);
- error= -1;
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name);
+ error= -1;
}
else
{
- *fn_ext(new_name)=0;
+ *fn_ext(new_name)=0;
pthread_mutex_lock(&LOCK_open);
- if (mysql_rename_table(old_db_type,db,table_name,new_db,new_alias, 0))
- error= -1;
+ if (mysql_rename_table(old_db_type,db,table_name,new_db,new_alias, 0))
+ error= -1;
else if (Table_triggers_list::change_table_name(thd, db, table_name,
new_db, new_alias))
{
(void) mysql_rename_table(old_db_type, new_db, new_alias, db,
- table_name, 0);
+ table_name, 0);
error= -1;
}
pthread_mutex_unlock(&LOCK_open);
+ }
}
- }
if (error == HA_ERR_WRONG_COMMAND)
- {
+ {
error= 0;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
- ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
- table->alias);
- }
+ ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
+ table->alias);
+ }
if (!error)
{
write_bin_log(thd, TRUE, thd->query, thd->query_length);
my_ok(thd);
- }
+ }
else if (error > 0)
- {
+ {
table->file->print_error(error, MYF(0));
error= -1;
}
@@ -6717,7 +6638,7 @@ view_err:
them.
TODO: Investigate what should be done with upgraded table-level
- lock here...
+ lock here...
*/
if (new_name != table_name || new_db != db)
{
@@ -6739,7 +6660,7 @@ view_err:
goto err;
}
#endif
- /*
+ /*
If the old table had partitions and we are doing ALTER TABLE ...
engine= <new_engine>, the new table must preserve the original
partitioning. That means that the new engine is still the
@@ -6753,7 +6674,7 @@ view_err:
new_db_type= create_info->db_type;
if (mysql_prepare_alter_table(thd, table, create_info, alter_info))
- goto err;
+ goto err;
set_table_default_charset(thd, create_info, db);
=== modified file 'sql/table.h'
--- a/sql/table.h 2008-05-29 12:52:56 +0000
+++ b/sql/table.h 2008-06-02 14:30:18 +0000
@@ -1052,11 +1052,13 @@ struct TABLE_LIST
*/
inline void init_one_table(const char *db_name_arg,
const char *table_name_arg,
+ const char *alias_arg,
enum thr_lock_type lock_type_arg)
{
bzero((char*) this, sizeof(*this));
db= (char*) db_name_arg;
- table_name= alias= (char*) table_name_arg;
+ table_name= (char*) table_name_arg;
+ alias= (char*) alias_arg;
lock_type= lock_type_arg;
}
=== modified file 'storage/csv/ha_tina.cc'
--- a/storage/csv/ha_tina.cc 2008-05-08 16:01:15 +0000
+++ b/storage/csv/ha_tina.cc 2008-06-02 11:14:18 +0000
@@ -452,6 +452,7 @@ ha_tina::ha_tina(handlerton *hton, TABLE
buffer.set((char*)byte_buffer, IO_SIZE, &my_charset_bin);
chain= chain_buffer;
file_buff= new Transparent_file();
+ init_alloc_root(&blobroot, BLOB_MEMROOT_ALLOC_SIZE, 0);;
}
@@ -598,7 +599,7 @@ int ha_tina::find_current_row(uchar *buf
bool read_all;
DBUG_ENTER("ha_tina::find_current_row");
- free_root(&blobroot, MYF(MY_MARK_BLOCKS_FREE));
+ free_root(&blobroot, MYF(0));
/*
We do not read further then local_saved_data_file_length in order
@@ -1073,8 +1074,6 @@ int ha_tina::rnd_init(bool scan)
records_is_known= 0;
chain_ptr= chain;
- init_alloc_root(&blobroot, BLOB_MEMROOT_ALLOC_SIZE, 0);
-
DBUG_RETURN(0);
}
@@ -1176,6 +1175,7 @@ int ha_tina::extra(enum ha_extra_functio
DBUG_RETURN(0);
}
+
/*
Set end_pos to the last valid byte of continuous area, closest
to the given "hole", stored in the buffer. "Valid" here means,
@@ -1376,8 +1376,6 @@ int ha_tina::repair(THD* thd, HA_CHECK_O
/* set current position to the beginning of the file */
current_position= next_position= 0;
- init_alloc_root(&blobroot, BLOB_MEMROOT_ALLOC_SIZE, 0);
-
/* Read the file row-by-row. If everything is ok, repair is not needed. */
while (!(rc= find_current_row(buf)))
{
@@ -1566,8 +1564,6 @@ int ha_tina::check(THD* thd, HA_CHECK_OP
/* set current position to the beginning of the file */
current_position= next_position= 0;
- init_alloc_root(&blobroot, BLOB_MEMROOT_ALLOC_SIZE, 0);
-
/* Read the file row-by-row. If everything is ok, repair is not needed. */
while (!(rc= find_current_row(buf)))
{
@@ -1575,7 +1571,7 @@ int ha_tina::check(THD* thd, HA_CHECK_OP
count--;
current_position= next_position;
}
-
+
free_root(&blobroot, MYF(0));
my_free((char*)buf, MYF(0));
=== modified file 'storage/csv/ha_tina.h'
--- a/storage/csv/ha_tina.h 2008-01-17 23:37:18 +0000
+++ b/storage/csv/ha_tina.h 2008-06-02 11:14:18 +0000
@@ -98,6 +98,7 @@ public:
my_free(chain, 0);
if (file_buff)
delete file_buff;
+ free_root(&blobroot, MYF(0));
}
const char *table_type() const { return "CSV"; }
const char *index_type(uint inx) { return "NONE"; }
| Thread |
|---|
| • bzr commit into mysql-6.0 branch (dlenev:2657) WL#3726 | Dmitry Lenev | 3 Jun |