Commit 7eb1507a authored by Sergey Glukhov's avatar Sergey Glukhov

Bug#36638 mysqld crashes when open file limit is passed and general query log enabled

The problem:
CSV storage engine open function returns success even
thought it failed to open the data file
The fix:
return error
Additional fixes:
added MY_WME to my_open to avoid mysterious error message
free share struct if open the file was unsuccessful
parent 5bafde31
...@@ -5388,4 +5388,10 @@ select * from t1; ...@@ -5388,4 +5388,10 @@ select * from t1;
c1 c1
That That
drop table t1; drop table t1;
create table t1 (a int not null) engine=csv;
lock tables t1 read;
select * from t1;
ERROR HY000: File './test/t1.CSV' not found (Errcode: 2)
unlock tables;
drop table t1;
End of 5.1 tests End of 5.1 tests
...@@ -1386,6 +1386,9 @@ UNLOCK TABLES; ...@@ -1386,6 +1386,9 @@ UNLOCK TABLES;
# cleanup # cleanup
DROP TABLE test_concurrent_insert; DROP TABLE test_concurrent_insert;
connection default;
--disconnect con1
--disconnect con2
# #
# Test REPAIR/CHECK TABLE (5.1) # Test REPAIR/CHECK TABLE (5.1)
...@@ -1784,4 +1787,20 @@ update t1 set c1="That" where c1="This"; ...@@ -1784,4 +1787,20 @@ update t1 set c1="That" where c1="This";
select * from t1; select * from t1;
drop table t1; drop table t1;
#
# Bug#36638 mysqld crashes when open file limit is passed and general query log enabled
#
create table t1 (a int not null) engine=csv;
lock tables t1 read;
connect (con1,localhost,root,,);
--connection con1
--remove_file $MYSQLTEST_VARDIR/master-data/test/t1.CSV
# EE_FILENOTFOUND 29
--error 29
select * from t1;
connection default;
unlock tables;
drop table t1;
--disconnect con1
--echo End of 5.1 tests --echo End of 5.1 tests
...@@ -190,17 +190,12 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table) ...@@ -190,17 +190,12 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table)
Usually this will result in auto-repair, and we will get a good Usually this will result in auto-repair, and we will get a good
meta-file in the end. meta-file in the end.
*/ */
if ((share->meta_file= my_open(meta_file_name, if (((share->meta_file= my_open(meta_file_name,
O_RDWR|O_CREAT, MYF(0))) == -1) O_RDWR|O_CREAT, MYF(MY_WME))) == -1) ||
share->crashed= TRUE; read_meta_file(share->meta_file, &share->rows_recorded))
/*
If the meta file will not open we assume it is crashed and
mark it as such.
*/
if (read_meta_file(share->meta_file, &share->rows_recorded))
share->crashed= TRUE; share->crashed= TRUE;
} }
share->use_count++; share->use_count++;
pthread_mutex_unlock(&tina_mutex); pthread_mutex_unlock(&tina_mutex);
...@@ -342,11 +337,11 @@ int ha_tina::init_tina_writer() ...@@ -342,11 +337,11 @@ int ha_tina::init_tina_writer()
(void)write_meta_file(share->meta_file, share->rows_recorded, TRUE); (void)write_meta_file(share->meta_file, share->rows_recorded, TRUE);
if ((share->tina_write_filedes= if ((share->tina_write_filedes=
my_open(share->data_file_name, O_RDWR|O_APPEND, MYF(0))) == -1) my_open(share->data_file_name, O_RDWR|O_APPEND, MYF(MY_WME))) == -1)
{ {
DBUG_PRINT("info", ("Could not open tina file writes")); DBUG_PRINT("info", ("Could not open tina file writes"));
share->crashed= TRUE; share->crashed= TRUE;
DBUG_RETURN(1); DBUG_RETURN(my_errno ? my_errno : -1);
} }
share->tina_write_opened= TRUE; share->tina_write_opened= TRUE;
...@@ -828,8 +823,12 @@ int ha_tina::open(const char *name, int mode, uint open_options) ...@@ -828,8 +823,12 @@ int ha_tina::open(const char *name, int mode, uint open_options)
} }
local_data_file_version= share->data_file_version; local_data_file_version= share->data_file_version;
if ((data_file= my_open(share->data_file_name, O_RDONLY, MYF(0))) == -1) if ((data_file= my_open(share->data_file_name,
DBUG_RETURN(0); O_RDONLY, MYF(MY_WME))) == -1)
{
free_share(share);
DBUG_RETURN(my_errno ? my_errno : -1);
}
/* /*
Init locking. Pass handler object to the locking routines, Init locking. Pass handler object to the locking routines,
...@@ -1021,8 +1020,8 @@ int ha_tina::init_data_file() ...@@ -1021,8 +1020,8 @@ int ha_tina::init_data_file()
{ {
local_data_file_version= share->data_file_version; local_data_file_version= share->data_file_version;
if (my_close(data_file, MYF(0)) || if (my_close(data_file, MYF(0)) ||
(data_file= my_open(share->data_file_name, O_RDONLY, MYF(0))) == -1) (data_file= my_open(share->data_file_name, O_RDONLY, MYF(MY_WME))) == -1)
return 1; return my_errno ? my_errno : -1;
} }
file_buff->init_buff(data_file); file_buff->init_buff(data_file);
return 0; return 0;
...@@ -1290,8 +1289,9 @@ int ha_tina::rnd_end() ...@@ -1290,8 +1289,9 @@ int ha_tina::rnd_end()
DBUG_RETURN(-1); DBUG_RETURN(-1);
/* Open the file again */ /* Open the file again */
if (((data_file= my_open(share->data_file_name, O_RDONLY, MYF(0))) == -1)) if (((data_file= my_open(share->data_file_name,
DBUG_RETURN(-1); O_RDONLY, MYF(MY_WME))) == -1))
DBUG_RETURN(my_errno ? my_errno : -1);
/* /*
As we reopened the data file, increase share->data_file_version As we reopened the data file, increase share->data_file_version
in order to force other threads waiting on a table lock and in order to force other threads waiting on a table lock and
...@@ -1445,8 +1445,8 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -1445,8 +1445,8 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
/* Open the file again, it should now be repaired */ /* Open the file again, it should now be repaired */
if ((data_file= my_open(share->data_file_name, O_RDWR|O_APPEND, if ((data_file= my_open(share->data_file_name, O_RDWR|O_APPEND,
MYF(0))) == -1) MYF(MY_WME))) == -1)
DBUG_RETURN(-1); DBUG_RETURN(my_errno ? my_errno : -1);
/* Set new file size. The file size will be updated by ::update_status() */ /* Set new file size. The file size will be updated by ::update_status() */
local_saved_data_file_length= (size_t) current_position; local_saved_data_file_length= (size_t) current_position;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment