From a5dfeb02e991e6e5e9e332443522de1bb4592df8 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 4 Jul 2006 18:44:35 +0200 Subject: WL #3337 (Event scheduler new architecture) Cut Nr. 8. All tests pass. Separated Event_scheduler into Event_queue and Event_scheduler. Added new Event_scheduler_ng which is the new scheduler and is used system-wide. Will be moved to the event_scheduler.cc in the future. Using Event_timed in Event_queue as well as cloned during execution. Next step is to have Event_worker_data which will be used during execution and will take ::compile()/::execute() out of Event_timed. mysql-test/r/events.result: update result mysql-test/r/events_bugs.result: update result mysql-test/r/ps_1general.result: update result mysql-test/r/skip_name_resolve.result: update result mysql-test/r/sp-threads.result: update result mysql-test/r/sp_notembedded.result: update result mysql-test/r/status.result: update result mysql-test/t/events_stress.test: Make event_stress a bit longer sql/Makefile.am: Add new event_scheduler_ng.h/cc . These are only to be in the experimental clone. Later their content will be moved to event_scheduler.h/cc sql/event_data_objects.cc: Allocate strings memory on own memory root, instead on the schedulers. Thus don't "leak" memory. This should fix bug#18683 memory leak in event scheduler sql/event_data_objects.h: add mem_root add THD - this is only temporal, will be moved to class Event_job_data once Event_job_data is responsible for the execution. sql/event_db_repository.cc: Remove unused code. Cosmetic changes sql/event_queue.cc: Now use the Event_scheduler_ng (NextGen) sql/event_queue.h: Now use the Event_scheduler_ng (NextGen) sql/event_scheduler.cc: This file is no more used, but will be soon. sql/event_scheduler.h: This file is no more used but will be soon sql/events.cc: Now use the Event_scheduler_ng (NextGen) sql/events.h: Now use the Event_scheduler_ng (NextGen) sql/mysqld.cc: Make it again possible to kill the scheduler thread sql/set_var.cc: Now use the Event_scheduler_ng (NextGen) sql/share/errmsg.txt: Shorten the message. sql/sql_show.cc: Loading is on a own root, then don't use thd->mem_root --- sql/event_data_objects.cc | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'sql/event_data_objects.cc') diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index f4147d72c3d..97db443e08d 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -556,6 +556,7 @@ Event_timed::Event_timed():in_spawned_thread(0),locked_by_thread_id(0), Event_timed::~Event_timed() { deinit_mutexes(); + free_root(&mem_root, MYF(0)); if (free_sphead_on_delete) free_sp(); @@ -622,6 +623,8 @@ Event_timed::init() definer_user.length= definer_host.length= 0; sql_mode= 0; + /* init memory root */ + init_alloc_root(&mem_root, 256, 512); DBUG_VOID_RETURN; } @@ -644,7 +647,7 @@ Event_timed::init() */ int -Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) +Event_timed::load_from_row(TABLE *table) { char *ptr; Event_timed *et; @@ -661,22 +664,22 @@ Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) if (table->s->fields != ET_FIELD_COUNT) goto error; - if ((et->dbname.str= get_field(mem_root, table->field[ET_FIELD_DB])) == NULL) + if ((et->dbname.str= get_field(&mem_root, table->field[ET_FIELD_DB])) == NULL) goto error; et->dbname.length= strlen(et->dbname.str); - if ((et->name.str= get_field(mem_root, table->field[ET_FIELD_NAME])) == NULL) + if ((et->name.str= get_field(&mem_root, table->field[ET_FIELD_NAME])) == NULL) goto error; et->name.length= strlen(et->name.str); - if ((et->body.str= get_field(mem_root, table->field[ET_FIELD_BODY])) == NULL) + if ((et->body.str= get_field(&mem_root, table->field[ET_FIELD_BODY])) == NULL) goto error; et->body.length= strlen(et->body.str); - if ((et->definer.str= get_field(mem_root, + if ((et->definer.str= get_field(&mem_root, table->field[ET_FIELD_DEFINER])) == NullS) goto error; et->definer.length= strlen(et->definer.str); @@ -688,10 +691,10 @@ Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) len= ptr - et->definer.str; - et->definer_user.str= strmake_root(mem_root, et->definer.str, len); + et->definer_user.str= strmake_root(&mem_root, et->definer.str, len); et->definer_user.length= len; len= et->definer.length - len - 1; //1 is because of @ - et->definer_host.str= strmake_root(mem_root, ptr + 1, len);/* 1:because of @*/ + et->definer_host.str= strmake_root(&mem_root, ptr + 1, len);/* 1:because of @*/ et->definer_host.length= len; et->starts_null= table->field[ET_FIELD_STARTS]->is_null(); @@ -737,21 +740,21 @@ Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table) last_executed_changed= false; /* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */ - if ((ptr= get_field(mem_root, table->field[ET_FIELD_STATUS])) == NullS) + if ((ptr= get_field(&mem_root, table->field[ET_FIELD_STATUS])) == NullS) goto error; DBUG_PRINT("load_from_row", ("Event [%s] is [%s]", et->name.str, ptr)); et->status= (ptr[0]=='E'? Event_timed::ENABLED:Event_timed::DISABLED); /* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */ - if ((ptr= get_field(mem_root, + if ((ptr= get_field(&mem_root, table->field[ET_FIELD_ON_COMPLETION])) == NullS) goto error; et->on_completion= (ptr[0]=='D'? Event_timed::ON_COMPLETION_DROP: Event_timed::ON_COMPLETION_PRESERVE); - et->comment.str= get_field(mem_root, table->field[ET_FIELD_COMMENT]); + et->comment.str= get_field(&mem_root, table->field[ET_FIELD_COMMENT]); if (et->comment.str != NullS) et->comment.length= strlen(et->comment.str); else @@ -953,10 +956,10 @@ Event_timed::compute_next_execution_time() int tmp; DBUG_ENTER("Event_timed::compute_next_execution_time"); - DBUG_PRINT("enter", ("starts=%llu ends=%llu last_executed=%llu", + DBUG_PRINT("enter", ("starts=%llu ends=%llu last_executed=%llu this=%p", TIME_to_ulonglong_datetime(&starts), TIME_to_ulonglong_datetime(&ends), - TIME_to_ulonglong_datetime(&last_executed))); + TIME_to_ulonglong_datetime(&last_executed), this)); if (status == Event_timed::DISABLED) { @@ -1168,7 +1171,8 @@ Event_timed::compute_next_execution_time() goto ret; } ret: - DBUG_PRINT("info", ("ret=0")); + DBUG_PRINT("info", ("ret=0 execute_at=%llu", + TIME_to_ulonglong_datetime(&execute_at))); DBUG_RETURN(false); err: DBUG_PRINT("info", ("ret=1")); @@ -1392,6 +1396,7 @@ Event_timed::get_create_event(THD *thd, String *buf) int Event_timed::execute(THD *thd, MEM_ROOT *mem_root) { + Security_context *save_ctx; /* this one is local and not needed after exec */ Security_context security_ctx; int ret= 0; @@ -1400,14 +1405,8 @@ Event_timed::execute(THD *thd, MEM_ROOT *mem_root) DBUG_PRINT("info", (" EVEX EXECUTING event %s.%s [EXPR:%d]", dbname.str, name.str, (int) expression)); - VOID(pthread_mutex_lock(&this->LOCK_running)); - if (running) - { - VOID(pthread_mutex_unlock(&this->LOCK_running)); - DBUG_RETURN(-100); - } - running= true; - VOID(pthread_mutex_unlock(&this->LOCK_running)); + thd->change_security_context(definer_user, definer_host, dbname, + &security_ctx, &save_ctx); if (!sphead && (ret= compile(thd, mem_root))) goto done; @@ -1434,14 +1433,11 @@ Event_timed::execute(THD *thd, MEM_ROOT *mem_root) definer_host.str, dbname.str)); ret= -99; } - - VOID(pthread_mutex_lock(&this->LOCK_running)); - running= false; /* Will compile every time a new sp_head on different root */ free_sp(); - VOID(pthread_mutex_unlock(&this->LOCK_running)); done: + thd->restore_security_context(save_ctx); /* 1. Don't cache sphead if allocated on another mem_root 2. Don't call security_ctx.destroy() because this will free our dbname.str @@ -1807,3 +1803,4 @@ event_timed_identifier_equal(LEX_STRING db, LEX_STRING name, Event_timed *b) return !sortcmp_lex_string(name, b->name, system_charset_info) && !sortcmp_lex_string(db, b->dbname, system_charset_info); } + -- cgit v1.2.1