mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Fix for bug #799 FLUSH TABLES WITH READ LOCK does not block CREATE TABLE
This commit is related to my previos one(ChangeSet 1.1583 03/08/27 18:03:39). Note about COMMIT&ROLLBACK: Only 'COMMIT' statement updates the binary log. 'ROLLBACK' statement doesn't update the binlog.
This commit is contained in:
@ -47,7 +47,7 @@ ERROR HY000: Can't drop database 'mysqltest'; database doesn't exist
|
|||||||
drop table t1;
|
drop table t1;
|
||||||
flush tables with read lock;
|
flush tables with read lock;
|
||||||
create table t1(n int);
|
create table t1(n int);
|
||||||
ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
|
ERROR HY000: Can't execute the query because you have a conflicting read lock
|
||||||
unlock tables;
|
unlock tables;
|
||||||
create table t1(n int);
|
create table t1(n int);
|
||||||
show tables;
|
show tables;
|
||||||
|
@ -251,6 +251,18 @@ n
|
|||||||
6
|
6
|
||||||
rollback;
|
rollback;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
create table t1 (n int not null primary key) type=innodb;
|
||||||
|
start transaction;
|
||||||
|
insert into t1 values (4);
|
||||||
|
flush tables with read lock;
|
||||||
|
commit;
|
||||||
|
ERROR HY000: Can't execute the query because you have a conflicting read lock
|
||||||
|
unlock tables;
|
||||||
|
commit;
|
||||||
|
select * from t1;
|
||||||
|
n
|
||||||
|
4
|
||||||
|
drop table t1;
|
||||||
create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) type=innodb;
|
create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) type=innodb;
|
||||||
begin;
|
begin;
|
||||||
insert into t1 values(1,'hamdouni');
|
insert into t1 values(1,'hamdouni');
|
||||||
|
@ -47,7 +47,7 @@ drop database mysqltest;
|
|||||||
# test create table and FLUSH TABLES WITH READ LOCK
|
# test create table and FLUSH TABLES WITH READ LOCK
|
||||||
drop table t1;
|
drop table t1;
|
||||||
flush tables with read lock;
|
flush tables with read lock;
|
||||||
--error 1099;
|
--error 1223;
|
||||||
create table t1(n int);
|
create table t1(n int);
|
||||||
unlock tables;
|
unlock tables;
|
||||||
create table t1(n int);
|
create table t1(n int);
|
||||||
|
@ -133,6 +133,21 @@ select n from t1;
|
|||||||
rollback;
|
rollback;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Test for commit and FLUSH TABLES WITH READ LOCK
|
||||||
|
#
|
||||||
|
|
||||||
|
create table t1 (n int not null primary key) type=innodb;
|
||||||
|
start transaction;
|
||||||
|
insert into t1 values (4);
|
||||||
|
flush tables with read lock;
|
||||||
|
--error 1223;
|
||||||
|
commit;
|
||||||
|
unlock tables;
|
||||||
|
commit;
|
||||||
|
select * from t1;
|
||||||
|
drop table t1;
|
||||||
|
|
||||||
#
|
#
|
||||||
# Testing transactions
|
# Testing transactions
|
||||||
#
|
#
|
||||||
|
@ -359,7 +359,10 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans)
|
|||||||
if (trans == &thd->transaction.all && mysql_bin_log.is_open() &&
|
if (trans == &thd->transaction.all && mysql_bin_log.is_open() &&
|
||||||
my_b_tell(&thd->transaction.trans_log))
|
my_b_tell(&thd->transaction.trans_log))
|
||||||
{
|
{
|
||||||
|
if (wait_if_global_read_lock(thd, 0))
|
||||||
|
DBUG_RETURN(1);
|
||||||
mysql_bin_log.write(thd, &thd->transaction.trans_log);
|
mysql_bin_log.write(thd, &thd->transaction.trans_log);
|
||||||
|
start_waiting_global_read_lock(thd);
|
||||||
reinit_io_cache(&thd->transaction.trans_log,
|
reinit_io_cache(&thd->transaction.trans_log,
|
||||||
WRITE_CACHE, (my_off_t) 0, 0, 1);
|
WRITE_CACHE, (my_off_t) 0, 0, 1);
|
||||||
thd->transaction.trans_log.end_of_file= max_binlog_cache_size;
|
thd->transaction.trans_log.end_of_file= max_binlog_cache_size;
|
||||||
|
@ -899,33 +899,18 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
|
|||||||
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
|
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
|
||||||
DBUG_RETURN(-1);
|
DBUG_RETURN(-1);
|
||||||
}
|
}
|
||||||
|
if (wait_if_global_read_lock(thd, 0))
|
||||||
|
DBUG_RETURN(error);
|
||||||
VOID(pthread_mutex_lock(&LOCK_open));
|
VOID(pthread_mutex_lock(&LOCK_open));
|
||||||
if (global_read_lock)
|
|
||||||
{
|
|
||||||
thd->mysys_var->current_mutex= &LOCK_open;
|
|
||||||
thd->mysys_var->current_cond= &COND_refresh;
|
|
||||||
if (thd->global_read_lock)
|
|
||||||
my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE,MYF(0),
|
|
||||||
table_name);
|
|
||||||
else
|
|
||||||
while (global_read_lock && ! thd->killed)
|
|
||||||
(void) pthread_cond_wait(&COND_refresh,&LOCK_open);
|
|
||||||
pthread_mutex_lock(&thd->mysys_var->mutex);
|
|
||||||
thd->mysys_var->current_mutex= 0;
|
|
||||||
thd->mysys_var->current_cond= 0;
|
|
||||||
pthread_mutex_unlock(&thd->mysys_var->mutex);
|
|
||||||
if (error)
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
if (!tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
|
if (!tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
|
||||||
{
|
{
|
||||||
if (!access(path,F_OK))
|
if (!access(path,F_OK))
|
||||||
{
|
{
|
||||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
|
||||||
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
|
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
|
||||||
DBUG_RETURN(0);
|
error= 0;
|
||||||
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
|
else
|
||||||
DBUG_RETURN(-1);
|
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -963,6 +948,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
|
|||||||
error=0;
|
error=0;
|
||||||
end:
|
end:
|
||||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||||
|
start_waiting_global_read_lock(thd);
|
||||||
thd->proc_info="After create";
|
thd->proc_info="After create";
|
||||||
DBUG_RETURN(error);
|
DBUG_RETURN(error);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user