71
if (session->wait_if_global_read_lock(false, true))
71
if (wait_if_global_read_lock(session, 0, 1))
75
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* Rename table lock for exclusive access */
77
if (not session->lock_table_names_exclusively(table_list))
80
ren_table= renameTablesInList(table_list, false);
84
/* Rename didn't succeed; rename back the tables in reverse order */
87
/* Reverse the table list */
88
table_list= reverseTableList(table_list);
90
/* Find the last renamed table */
91
for (table= table_list;
92
table->next_local != ren_table;
93
table= table->next_local->next_local)
96
table= table->next_local->next_local; // Skip error table
98
/* Revert to old names */
99
renameTablesInList(table, true);
103
table_list->unlock_table_names();
74
LOCK_open.lock(); /* Rename table lock for exclusive access */
75
if (lock_table_names_exclusively(session, table_list))
82
ren_table= renameTablesInList(table_list, 0);
85
/* Rename didn't succeed; rename back the tables in reverse order */
88
/* Reverse the table list */
89
table_list= reverseTableList(table_list);
91
/* Find the last renamed table */
92
for (table= table_list;
93
table->next_local != ren_table;
94
table= table->next_local->next_local)
96
table= table->next_local->next_local; // Skip error table
97
/* Revert to old names */
98
renameTablesInList(table, 1);
102
An exclusive lock on table names is satisfactory to ensure
103
no other thread accesses this table.
104
We still should unlock LOCK_open as early as possible, to provide
105
higher concurrency - query_cache_invalidate can take minutes to
107
110
/* Lets hope this doesn't fail as the result will be messy */
110
write_bin_log(session, *session->getQueryString());
113
write_bin_log(session, session->query.c_str());
111
114
session->my_ok();
114
session->startWaitingGlobalReadLock();
117
LOCK_open.lock(); /* unlock all tables held */
118
unlock_table_names(table_list, NULL);
122
start_waiting_global_read_lock(session);
139
147
const char *new_alias, *old_alias;
142
old_alias= ren_table->getTableName();
150
old_alias= ren_table->table_name;
143
151
new_alias= new_table_name;
146
154
plugin::StorageEngine *engine= NULL;
147
message::table::shared_ptr table_proto;
155
message::Table table_proto;
149
TableIdentifier old_identifier(ren_table->getSchemaName(), old_alias, message::Table::STANDARD);
157
TableIdentifier old_identifier(ren_table->db, old_alias, message::Table::STANDARD);
151
159
if (plugin::StorageEngine::getTableDefinition(*session, old_identifier, table_proto) != EEXIST)
153
my_error(ER_NO_SUCH_TABLE, MYF(0), ren_table->getSchemaName(), old_alias);
161
my_error(ER_NO_SUCH_TABLE, MYF(0), ren_table->db, old_alias);
157
engine= plugin::StorageEngine::findByName(*session, table_proto->engine().name());
165
engine= plugin::StorageEngine::findByName(*session, table_proto.engine().name());
159
167
TableIdentifier new_identifier(new_db, new_alias, message::Table::STANDARD);
160
168
if (plugin::StorageEngine::doesTableExist(*session, new_identifier))
178
186
for (ren_table= table_list; ren_table; ren_table= new_table->next_local)
180
188
new_table= ren_table->next_local;
181
if (rename(ren_table, new_table->getSchemaName(), new_table->getTableName(), skip_error))
189
if (rename(ren_table, new_table->db, new_table->table_name, skip_error))
182
190
return ren_table;