List:Commits« Previous MessageNext Message »
From:Mayank Prasad Date:May 18 2011 2:41pm
Subject:bzr push into mysql-5.1 branch (mayank.prasad:3622 to 3623) Bug#11764633
View as plain text  
 3623 Mayank Prasad	2011-05-18
      Bug#11764633 : 57491: THD->MAIN_DA.IS_OK() ASSERT IN EMBEDDED
      
      Issue:
      While running embedded server, if client issues TEE command (\T foo/bar) and
      "foo/bar" directory doesn't exist, it is suppose to give error. But it was
      aborting.  This was happening because wrong error handler was being called.
      
      Solution:
      Modified calls to correct error handler. In embedded server case, there are 
      two error handler (client and server) which are supposed to be called based 
      on which context code is in. If it is in client context, client error handler
      should be called otherwise server.
      
      Test case:
      Test case automation is not possible as current (following) code doesn't 
      allow '\T' to be executed from command line (OR command read from a file):
      [client/mysql.cc]
      ...
       static int
       com_tee(String *buffer __attribute__((unused)),
               char *line __attribute__((unused)))
       {
         char file_name[FN_REFLEN], *end, *param;
      
         if (status.batch) << THIS IS TRUE WHILE EXECUTING FROM COMMAND LINE.
            return 0;
       ...
      So, not adding test case in GA. WIll add a test case in mysql-trunk after 
      removing above code so that this could be properly tested before GA.
     @ libmysqld/lib_sql.cc
        Added code to call client/server error handler based on in control is in 
        client/server code respectively.
     @ sql/mysql_priv.h
        Added comments for THR_THD, THR_MALLOC keys.
     @ sql/sql_class.cc
        Function definition of new function restore_global to removes thread specific 
        data from stack (which was stored in store global).
     @ sql/sql_class.h
        Function declaration of new function restore_global.

    modified:
      libmysqld/lib_sql.cc
      sql/mysql_priv.h
      sql/sql_class.cc
      sql/sql_class.h
 3622 Sergey Glukhov	2011-05-18
      Bug#12403504 AFTER FIX FOR #11889186 : ASSERTION FAILED: DELSUM+(INT) Y/4-TEMP > 0
      There are two problems:
      1. There is a missing check for 'year' parameter(year can not be greater than 9999) in
         makedate function. fix: added check that year can not be greater than 9999.
      2. There is a missing check for zero date in from_days() function.
         fix: added zero date check into Item_func_from_days::get_date()
         function.
     @ mysql-test/r/func_time.result
        test case
     @ mysql-test/t/func_time.test
        test case
     @ sql/item_timefunc.cc
        --added check that year can not be greater than 9999 for makedate() function
        --added zero date check into Item_func_from_days::get_date() function

    modified:
      mysql-test/r/func_time.result
      mysql-test/t/func_time.test
      sql/item_timefunc.cc
=== modified file 'libmysqld/lib_sql.cc'
--- a/libmysqld/lib_sql.cc	2009-12-18 18:44:24 +0000
+++ b/libmysqld/lib_sql.cc	2011-05-18 14:40:01 +0000
@@ -51,6 +51,23 @@ extern "C" void unireg_clear(int exit_co
   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
@@ -107,7 +124,8 @@ emb_advanced_command(MYSQL *mysql, enum 
   if (mysql->status != MYSQL_STATUS_READY)
   {
     set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
-    return 1;
+    result= 1;
+    goto end;
   }
 
   /* Clear result variables */
@@ -147,6 +165,9 @@ emb_advanced_command(MYSQL *mysql, enum 
 #if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
   thd->profiling.finish_current_query();
 #endif
+
+end:
+  thd->restore_globals();
   return result;
 }
 
@@ -525,7 +546,10 @@ int init_embedded_server(int argc, char 
     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;
 #ifndef NO_EMBEDDED_ACCESS_CHECKS

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2011-03-15 11:36:12 +0000
+++ b/sql/mysql_priv.h	2011-05-18 14:40:01 +0000
@@ -670,6 +670,10 @@ enum enum_check_fields
 extern "C" THD *_current_thd_noinline();
 #define _current_thd() _current_thd_noinline()
 #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);
 inline THD *_current_thd(void)
 {
@@ -2022,6 +2026,10 @@ extern TABLE_LIST general_log, slow_log;
 extern FILE *bootstrap_file;
 extern int bootstrap_error;
 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_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db,
        LOCK_mapped_file,LOCK_user_locks, LOCK_status,

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2011-04-07 18:12:54 +0000
+++ b/sql/sql_class.cc	2011-05-18 14:40:01 +0000
@@ -1196,6 +1196,25 @@ bool THD::store_globals()
   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.

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2011-02-22 21:03:32 +0000
+++ b/sql/sql_class.h	2011-05-18 14:40:01 +0000
@@ -1943,6 +1943,7 @@ public:
   void cleanup(void);
   void cleanup_after_query();
   bool store_globals();
+  bool restore_globals();
 #ifdef SIGNAL_WITH_VIO_CLOSE
   inline void set_active_vio(Vio* vio)
   {

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.1 branch (mayank.prasad:3622 to 3623) Bug#11764633Mayank Prasad19 May