=== modified file 'sql/ha_ndbcluster_binlog.cc' --- sql/ha_ndbcluster_binlog.cc 2010-03-24 10:28:13 +0000 +++ sql/ha_ndbcluster_binlog.cc 2010-03-24 12:13:25 +0000 @@ -563,12 +563,52 @@ static int ndbcluster_reset_logs(THD *th static int ndbcluster_binlog_index_purge_file(THD *thd, const char *file) { - if (!ndb_binlog_running || thd->slave_thread) - return 0; - + THD * save_thd= thd; DBUG_ENTER("ndbcluster_binlog_index_purge_file"); DBUG_PRINT("enter", ("file: %s", file)); + if (!ndb_binlog_running || (thd && thd->slave_thread)) + DBUG_RETURN(0); + + /** + * This function really really needs a THD object, + * new/delete one if not available...yuck! + */ + if (thd == 0) + { + thd= new THD; /* note that contructor of THD uses DBUG_ */ + THD_CHECK_SENTRY(thd); + + thd->thread_id= 0; + thd->thread_stack= (char*) &save_thd; /* remember where our stack is */ + if (thd->store_globals()) + { + thd->cleanup(); + delete thd; + DBUG_RETURN(0); + } + + lex_start(thd); + + thd->init_for_queries(); + thd->command= COM_DAEMON; + thd->system_thread= SYSTEM_THREAD_NDBCLUSTER_BINLOG; + thd->version= refresh_version; + thd->main_security_ctx.host_or_ip= ""; + thd->client_capabilities= 0; + thd->main_security_ctx.master_access= ~0; + thd->main_security_ctx.priv_user= 0; + thd->lex->start_transaction_opt= 0; + + CHARSET_INFO *charset_connection= get_charset_by_csname("utf8", + MY_CS_PRIMARY, + MYF(MY_WME)); + thd->variables.character_set_client= charset_connection; + thd->variables.character_set_results= charset_connection; + thd->variables.collation_connection= charset_connection; + thd->update_charset(); + } + char buf[1024]; char *end= strmov(strmov(strmov(buf, "DELETE FROM " @@ -586,6 +626,12 @@ ndbcluster_binlog_index_purge_file(THD * thd->main_da.reset_diagnostics_area(); } + if (save_thd == 0) + { + thd->cleanup(); + delete thd; + } + DBUG_RETURN(0); } @@ -941,10 +987,11 @@ static int ndbcluster_binlog_func(handle void *arg) { DBUG_ENTER("ndbcluster_binlog_func"); + int res= 0; switch(fn) { case BFN_RESET_LOGS: - DBUG_RETURN(ndbcluster_reset_logs(thd)); + res= ndbcluster_reset_logs(thd); case BFN_RESET_SLAVE: ndbcluster_reset_slave(thd); break; @@ -952,19 +999,19 @@ static int ndbcluster_binlog_func(handle ndbcluster_binlog_wait(thd); break; case BFN_BINLOG_END: - ndbcluster_binlog_end(thd); + res= ndbcluster_binlog_end(thd); break; case BFN_BINLOG_PURGE_FILE: - ndbcluster_binlog_index_purge_file(thd, (const char *)arg); + res= ndbcluster_binlog_index_purge_file(thd, (const char *)arg); break; case BFN_GLOBAL_SCHEMA_LOCK: - DBUG_RETURN(ndbcluster_global_schema_lock(thd, *(int*)arg, 1)); + res= ndbcluster_global_schema_lock(thd, *(int*)arg, 1); break; case BFN_GLOBAL_SCHEMA_UNLOCK: - ndbcluster_global_schema_unlock(thd); + res= ndbcluster_global_schema_unlock(thd); break; } - DBUG_RETURN(0); + DBUG_RETURN(res); } Ndbcluster_global_schema_lock_guard::Ndbcluster_global_schema_lock_guard(THD *thd) : m_thd(thd), m_lock(0) === modified file 'sql/handler.cc' --- sql/handler.cc 2010-03-12 10:36:52 +0000 +++ sql/handler.cc 2010-03-24 12:08:20 +0000 @@ -4030,8 +4030,8 @@ int ha_binlog_end(THD* thd) int ha_binlog_index_purge_file(THD *thd, const char *file) { binlog_func_st bfn= {BFN_BINLOG_PURGE_FILE, (void *)file}; - binlog_func_foreach(thd, &bfn); - if (thd->main_da.is_error()) + int res= binlog_func_foreach(thd, &bfn); + if (res || (thd && thd->main_da.is_error())) return 1; return 0; }