1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-136 Non-blocking "set read_only".

Handle the 'set read_only=1' in lighter way, than the FLUSH TABLES READ LOCK;
    For the transactional engines we don't wait for operations on that tables to finish.

per-file comments:
 mysql-test/r/read_only_innodb.result
MDEV-136 Non-blocking "set read_only".
       test result updated.
 mysql-test/t/read_only_innodb.test
MDEV-136 Non-blocking "set read_only".
       test case added.
  sql/mysql_priv.h
MDEV-136 Non-blocking "set read_only".
        The close_cached_tables_set_readonly() declared.
  sql/set_var.cc
MDEV-136 Non-blocking "set read_only".
         Call close_cached_tables_set_readonly() for the read_only::set_var.
   sql/sql_base.cc
 MDEV-136 Non-blocking "set read_only".
         Parameters added to the close_cached_tables implementation,
         close_cached_tables_set_readonly declared.
         Prevent blocking on the transactional tables if the
         set_readonly_mode is on.
This commit is contained in:
Alexey Botchkov
2012-05-21 19:37:46 +05:00
parent 7f6f53a8df
commit b87ccfdfbc
5 changed files with 85 additions and 5 deletions

View File

@ -862,8 +862,10 @@ void free_io_cache(TABLE *table)
and tables must be NULL.
*/
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
bool wait_for_refresh, bool wait_for_placeholders)
static bool int_close_cached_tables(THD *thd, TABLE_LIST *tables,
bool have_lock,
bool wait_for_refresh, bool wait_for_placeholders,
bool set_readonly_mode)
{
bool result=0;
DBUG_ENTER("close_cached_tables");
@ -873,7 +875,10 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
VOID(pthread_mutex_lock(&LOCK_open));
if (!tables)
{
refresh_version++; // Force close of open tables
/* No need to close the open tables if we just set the readonly state */
if (!set_readonly_mode)
refresh_version++; // Force close of open tables
while (unused_tables)
{
#ifdef EXTRA_DEBUG
@ -933,7 +938,16 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
for (uint idx=0 ; idx < open_cache.records ; idx++)
{
TABLE *table=(TABLE*) hash_element(&open_cache,idx);
if (table->in_use)
/*
We don't increment the refresh_version when set_readonly_mode,
but we still need non-transactional tables to be reopened.
So we set their versions as 'refresh_version - 1', which marks
them for the 'needs_reopen_or_table_lock()'
*/
if (set_readonly_mode && !table->file->has_transactions())
table->s->version= 0;
if (table->in_use &&
(!set_readonly_mode || !table->file->has_transactions()))
table->in_use->some_tables_deleted= 1;
}
}
@ -1038,6 +1052,20 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
}
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
bool wait_for_refresh, bool wait_for_placeholders)
{
return int_close_cached_tables(thd, tables, have_lock, wait_for_refresh,
wait_for_placeholders, FALSE);
}
bool close_cached_tables_set_readonly(THD *thd)
{
return int_close_cached_tables(thd, NULL, FALSE, TRUE, TRUE, TRUE);
}
/*
Close all tables which match specified connection string or
if specified string is NULL, then any table with a connection string.