Commit 06115abd authored by Guilhem Bichot's avatar Guilhem Bichot

merge from latest 5.1

parents 12c42b98 733893ba
...@@ -51,6 +51,23 @@ extern "C" void unireg_clear(int exit_code) ...@@ -51,6 +51,23 @@ extern "C" void unireg_clear(int exit_code)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/*
Wrapper error handler for embedded server to call client/server error
handler based on whether thread is in client/server context
*/
static int embedded_error_handler(uint error, const char *str, myf MyFlags)
{
DBUG_ENTER("embedded_error_handler");
/*
If current_thd is NULL, it means restore_global has been called and
thread is in client context, then call client error handler else call
server error handler.
*/
DBUG_RETURN(current_thd ? my_message_sql(error, str, MyFlags):
my_message_no_curses(error, str, MyFlags));
}
/* /*
Reads error information from the MYSQL_DATA and puts Reads error information from the MYSQL_DATA and puts
...@@ -107,7 +124,8 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, ...@@ -107,7 +124,8 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command,
if (mysql->status != MYSQL_STATUS_READY) if (mysql->status != MYSQL_STATUS_READY)
{ {
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
return 1; result= 1;
goto end;
} }
/* Clear result variables */ /* Clear result variables */
...@@ -147,6 +165,9 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, ...@@ -147,6 +165,9 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command,
#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER) #if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
thd->profiling.finish_current_query(); thd->profiling.finish_current_query();
#endif #endif
end:
thd->restore_globals();
return result; return result;
} }
...@@ -525,7 +546,10 @@ int init_embedded_server(int argc, char **argv, char **groups) ...@@ -525,7 +546,10 @@ int init_embedded_server(int argc, char **argv, char **groups)
return 1; return 1;
} }
error_handler_hook = my_message_sql; /*
set error_handler_hook to embedded_error_handler wrapper.
*/
error_handler_hook= embedded_error_handler;
acl_error= 0; acl_error= 0;
#ifndef NO_EMBEDDED_ACCESS_CHECKS #ifndef NO_EMBEDDED_ACCESS_CHECKS
......
...@@ -1417,4 +1417,13 @@ NULL ...@@ -1417,4 +1417,13 @@ NULL
SELECT DATE_FORMAT('0000-00-11', '%w'); SELECT DATE_FORMAT('0000-00-11', '%w');
DATE_FORMAT('0000-00-11', '%w') DATE_FORMAT('0000-00-11', '%w')
NULL NULL
#
# Bug#12403504 AFTER FIX FOR #11889186 : ASSERTION FAILED: DELSUM+(INT) Y/4-TEMP > 0
#
SELECT MAKEDATE(11111111,1);
MAKEDATE(11111111,1)
NULL
SELECT WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1);
WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1)
NULL
End of 5.1 tests End of 5.1 tests
include/master-slave.inc include/master-slave.inc
[connection master] [connection master]
stop slave; include/stop_slave.inc
create table t1 (a int); create table t1 (a int);
drop table t1; drop table t1;
create table t1 (a int); create table t1 (a int);
...@@ -8,10 +8,8 @@ drop table t1; ...@@ -8,10 +8,8 @@ drop table t1;
reset slave; reset slave;
start slave io_thread; start slave io_thread;
include/wait_for_slave_param.inc [Slave_IO_State] include/wait_for_slave_param.inc [Slave_IO_State]
stop slave io_thread; include/stop_slave_io.inc
reset slave; reset slave;
start slave; include/start_slave.inc
select master_pos_wait('master-bin.001',200,6)=-1; include/assert.inc [Assert that master_pos_wait does not timeout nor it returns NULL]
master_pos_wait('master-bin.001',200,6)=-1
0
include/rpl_end.inc include/rpl_end.inc
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
# to force the deadlock after one event. # to force the deadlock after one event.
source include/master-slave.inc; source include/master-slave.inc;
--let $master_log_file= query_get_value(SHOW MASTER STATUS, File, 1)
connection slave; connection slave;
stop slave; --source include/stop_slave.inc
connection master; connection master;
# This will generate a master's binlog > 10 bytes # This will generate a master's binlog > 10 bytes
create table t1 (a int); create table t1 (a int);
...@@ -19,20 +20,33 @@ let $slave_param_value= Waiting for the slave SQL thread to free enough relay lo ...@@ -19,20 +20,33 @@ let $slave_param_value= Waiting for the slave SQL thread to free enough relay lo
source include/wait_for_slave_param.inc; source include/wait_for_slave_param.inc;
# A bug caused the I/O thread to refuse stopping. # A bug caused the I/O thread to refuse stopping.
stop slave io_thread; --source include/stop_slave_io.inc
reset slave; reset slave;
start slave; --source include/start_slave.inc
# The I/O thread stops filling the relay log when
# it's >10b. And the SQL thread cannot purge this relay log # The I/O thread stops filling the relay log when it's >10b. And the
# as purge is done only when the SQL thread switches to another # SQL thread cannot purge this relay log as purge is done only when
# relay log, which does not exist here. # the SQL thread switches to another relay log, which does not exist
# So we should have a deadlock. # here. So we should have a deadlock. If it is not resolved
# if it is not resolved automatically we'll detect # automatically we'll detect it with master_pos_wait that waits for
# it with master_pos_wait that waits for farther than 1Ob; # farther than 1Ob; it will timeout after 300 seconds (which is inline
# it will timeout after 10 seconds; # with the default used for sync_slave_with_master and will protect us
# also the slave will probably not cooperate to shutdown # against slow test envs); also the slave will probably not cooperate
# (as 2 threads are locked) # to shutdown (as 2 threads are locked)
select master_pos_wait('master-bin.001',200,6)=-1; --let $outcome= `SELECT MASTER_POS_WAIT('$master_log_file',200,300) AS mpw;`
# master_pos_wait returns:
#
# * >= 0, the number of events the slave had to wait to advance to the
# position
#
# * -1, if there was a timeout
#
# * NULL, if an error occurred, or the SQL thread was not started,
# slave master info is not initialized, the arguments are incorrect
--let $assert_text= Assert that master_pos_wait does not timeout nor it returns NULL
--let $assert_cond= $outcome IS NOT NULL AND $outcome <> -1
--source include/assert.inc
# End of 4.1 tests # End of 4.1 tests
--source include/rpl_end.inc --source include/rpl_end.inc
...@@ -921,4 +921,11 @@ SELECT DATE_FORMAT('0000-00-11', '%W'); ...@@ -921,4 +921,11 @@ SELECT DATE_FORMAT('0000-00-11', '%W');
SELECT DATE_FORMAT('0000-00-11', '%a'); SELECT DATE_FORMAT('0000-00-11', '%a');
SELECT DATE_FORMAT('0000-00-11', '%w'); SELECT DATE_FORMAT('0000-00-11', '%w');
--echo #
--echo # Bug#12403504 AFTER FIX FOR #11889186 : ASSERTION FAILED: DELSUM+(INT) Y/4-TEMP > 0
--echo #
SELECT MAKEDATE(11111111,1);
SELECT WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1);
--echo End of 5.1 tests --echo End of 5.1 tests
...@@ -1519,6 +1519,11 @@ bool Item_func_from_days::get_date(MYSQL_TIME *ltime, uint fuzzy_date) ...@@ -1519,6 +1519,11 @@ bool Item_func_from_days::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
return 1; return 1;
bzero(ltime, sizeof(MYSQL_TIME)); bzero(ltime, sizeof(MYSQL_TIME));
get_date_from_daynr((long) value, &ltime->year, &ltime->month, &ltime->day); get_date_from_daynr((long) value, &ltime->year, &ltime->month, &ltime->day);
if ((null_value= (fuzzy_date & TIME_NO_ZERO_DATE) &&
(ltime->year == 0 || ltime->month == 0 || ltime->day == 0)))
return TRUE;
ltime->time_type= MYSQL_TIMESTAMP_DATE; ltime->time_type= MYSQL_TIMESTAMP_DATE;
return 0; return 0;
} }
...@@ -2697,7 +2702,7 @@ String *Item_func_makedate::val_str(String *str) ...@@ -2697,7 +2702,7 @@ String *Item_func_makedate::val_str(String *str)
long days; long days;
if (args[0]->null_value || args[1]->null_value || if (args[0]->null_value || args[1]->null_value ||
year < 0 || daynr <= 0) year < 0 || year > 9999 || daynr <= 0)
goto err; goto err;
if (year < 100) if (year < 100)
...@@ -2740,7 +2745,7 @@ longlong Item_func_makedate::val_int() ...@@ -2740,7 +2745,7 @@ longlong Item_func_makedate::val_int()
long days; long days;
if (args[0]->null_value || args[1]->null_value || if (args[0]->null_value || args[1]->null_value ||
year < 0 || daynr <= 0) year < 0 || year > 9999 || daynr <= 0)
goto err; goto err;
if (year < 100) if (year < 100)
......
...@@ -670,6 +670,10 @@ enum enum_check_fields ...@@ -670,6 +670,10 @@ enum enum_check_fields
extern "C" THD *_current_thd_noinline(); extern "C" THD *_current_thd_noinline();
#define _current_thd() _current_thd_noinline() #define _current_thd() _current_thd_noinline()
#else #else
/*
THR_THD is a key which will be used to set/get THD* for a thread,
using my_pthread_setspecific_ptr()/my_thread_getspecific_ptr().
*/
extern pthread_key(THD*, THR_THD); extern pthread_key(THD*, THR_THD);
inline THD *_current_thd(void) inline THD *_current_thd(void)
{ {
...@@ -2022,6 +2026,10 @@ extern TABLE_LIST general_log, slow_log; ...@@ -2022,6 +2026,10 @@ extern TABLE_LIST general_log, slow_log;
extern FILE *bootstrap_file; extern FILE *bootstrap_file;
extern int bootstrap_error; extern int bootstrap_error;
extern FILE *stderror_file; extern FILE *stderror_file;
/*
THR_MALLOC is a key which will be used to set/get MEM_ROOT** for a thread,
using my_pthread_setspecific_ptr()/my_thread_getspecific_ptr().
*/
extern pthread_key(MEM_ROOT**,THR_MALLOC); extern pthread_key(MEM_ROOT**,THR_MALLOC);
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db, extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db,
LOCK_mapped_file,LOCK_user_locks, LOCK_status, LOCK_mapped_file,LOCK_user_locks, LOCK_status,
......
...@@ -1195,6 +1195,25 @@ bool THD::store_globals() ...@@ -1195,6 +1195,25 @@ bool THD::store_globals()
return 0; return 0;
} }
/*
Remove the thread specific info (THD and mem_root pointer) stored during
store_global call for this thread.
*/
bool THD::restore_globals()
{
/*
Assert that thread_stack is initialized: it's necessary to be able
to track stack overrun.
*/
DBUG_ASSERT(thread_stack);
/* Undocking the thread specific data. */
my_pthread_setspecific_ptr(THR_THD, NULL);
my_pthread_setspecific_ptr(THR_MALLOC, NULL);
return 0;
}
/* /*
Cleanup after query. Cleanup after query.
......
...@@ -1943,6 +1943,7 @@ public: ...@@ -1943,6 +1943,7 @@ public:
void cleanup(void); void cleanup(void);
void cleanup_after_query(); void cleanup_after_query();
bool store_globals(); bool store_globals();
bool restore_globals();
#ifdef SIGNAL_WITH_VIO_CLOSE #ifdef SIGNAL_WITH_VIO_CLOSE
inline void set_active_vio(Vio* vio) inline void set_active_vio(Vio* vio)
{ {
......
This diff is collapsed.
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