2006-06-27 08:48:50 +02:00
|
|
|
/* Copyright (C) 2004-2006 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-27 02:23:51 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2006-06-27 08:48:50 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
#include "event_queue.h"
|
|
|
|
#include "event_data_objects.h"
|
2006-07-11 18:28:15 +02:00
|
|
|
|
2006-07-03 11:20:08 +02:00
|
|
|
|
2006-07-11 18:28:15 +02:00
|
|
|
#define EVENT_QUEUE_INITIAL_SIZE 30
|
|
|
|
#define EVENT_QUEUE_EXTENT 30
|
2006-07-03 11:20:08 +02:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#if __GNUC__ >= 2
|
|
|
|
#define SCHED_FUNC __FUNCTION__
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define SCHED_FUNC "<unknown>"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LOCK_QUEUE_DATA() lock_data(SCHED_FUNC, __LINE__)
|
|
|
|
#define UNLOCK_QUEUE_DATA() unlock_data(SCHED_FUNC, __LINE__)
|
|
|
|
|
|
|
|
/*
|
2006-07-11 18:28:15 +02:00
|
|
|
Compares the execute_at members of two Event_queue_element instances.
|
2006-07-03 11:20:08 +02:00
|
|
|
Used as callback for the prioritized queue when shifting
|
|
|
|
elements inside.
|
|
|
|
|
|
|
|
SYNOPSIS
|
2006-07-10 13:44:43 +02:00
|
|
|
event_queue_element_data_compare_q()
|
2006-07-11 18:28:15 +02:00
|
|
|
vptr Not used (set it to NULL)
|
|
|
|
a First Event_queue_element object
|
|
|
|
b Second Event_queue_element object
|
2006-07-03 11:20:08 +02:00
|
|
|
|
|
|
|
RETURN VALUE
|
2006-07-11 18:28:15 +02:00
|
|
|
-1 a->execute_at < b->execute_at
|
|
|
|
0 a->execute_at == b->execute_at
|
|
|
|
1 a->execute_at > b->execute_at
|
2006-07-10 23:54:46 +02:00
|
|
|
|
2006-07-03 11:20:08 +02:00
|
|
|
NOTES
|
|
|
|
execute_at.second_part is not considered during comparison
|
|
|
|
*/
|
|
|
|
|
2007-03-23 16:14:03 +01:00
|
|
|
static int
|
2006-07-10 13:44:43 +02:00
|
|
|
event_queue_element_compare_q(void *vptr, byte* a, byte *b)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2007-03-16 18:50:37 +01:00
|
|
|
my_time_t lhs = ((Event_queue_element *)a)->execute_at;
|
|
|
|
my_time_t rhs = ((Event_queue_element *)b)->execute_at;
|
|
|
|
|
|
|
|
return (lhs < rhs ? -1 : (lhs > rhs ? 1 : 0));
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Constructor of class Event_queue.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::Event_queue()
|
|
|
|
*/
|
|
|
|
|
|
|
|
Event_queue::Event_queue()
|
2007-05-21 10:51:11 +02:00
|
|
|
:next_activation_at(0),
|
|
|
|
mutex_last_locked_at_line(0),
|
|
|
|
mutex_last_unlocked_at_line(0),
|
|
|
|
mutex_last_locked_in_func("n/a"),
|
|
|
|
mutex_last_unlocked_in_func("n/a"),
|
|
|
|
mutex_last_attempted_lock_in_func("n/a"),
|
2006-08-17 14:22:59 +02:00
|
|
|
mutex_last_attempted_lock_at_line(0),
|
A set of changes aiming to make the Event Scheduler more user-friendly
when there are no up-to-date system tables to support it:
- initialize the scheduler before reporting "Ready for connections".
This ensures that warnings, if any, are printed before "Ready for
connections", and this message is not mangled.
- do not abort the scheduler if there are no system tables
- check the tables once at start up, remember the status and disable
the scheduler if the tables are not up to date.
If one attempts to use the scheduler with bad tables,
issue an error message.
- clean up the behaviour of the module under LOCK TABLES and pre-locking
mode
- make sure implicit commit of Events DDL works as expected.
- add more tests
Collateral clean ups in the events code.
This patch fixes Bug#23631 Events: SHOW VARIABLES doesn't work
when mysql.event is damaged
mysql-test/r/events.result:
Update results.
mysql-test/r/events_bugs.result:
Update results.
mysql-test/r/events_restart_phase1.result:
Update results.
mysql-test/r/events_restart_phase2.result:
Update results.
mysql-test/r/events_restart_phase3.result:
Update results.
mysql-test/r/events_scheduling.result:
Update results.
mysql-test/r/events_time_zone.result:
Update results.
mysql-test/t/events.test:
Add new tests for tampering with mysql.event and some more
tests for sub-statements, LOCK TABLES mode and pre-locking.
mysql-test/t/events_bugs.test:
Move the non-concurrent part of test for Bug 16420 to this file.
mysql-test/t/events_restart_phase1.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase2.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase3.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_scheduling.test:
Add more coverage for event_scheduler global variable.
mysql-test/t/events_time_zone.test:
Move the non-concurrent part of the tests for Bug 16420 to
events_bugs.test
sql/event_data_objects.cc:
Move update_timing_fields functionality to Event_db_repository.
Make loading of events from a table record more robust to tampering
with the table - now we do not check mysql.event on every table open.
sql/event_data_objects.h:
Cleanup.
sql/event_db_repository.cc:
Now Event_db_repository is responsible for table I/O only.
All the logic of events DDL is handled outside, in Events class please
refer to the added test coverage to see how this change affected
the behavior of Event Scheduler.
Dependency on sp_head.h and sp.h removed.
Make this module robust to tweaks with mysql.event table.
Move check_system_tables from events.cc to this file
sql/event_db_repository.h:
Cleanup declarations (remove unused ones, change return type to bool
from int).
sql/event_queue.cc:
Update to adapt to the new start up scheme of the Event Scheduler.
sql/event_queue.h:
Cleanup declarations.
sql/event_scheduler.cc:
Make all the error messages uniform:
[SEVERITY] Event Scheduler: [user][schema.event] message
Using append_identifier for error logging was an overkill - we may
need it only if the system character set may have NUL (null character)
as part of a valid identifier, this is currently never the case,
whereas additional quoting did not look nice in the log.
sql/event_scheduler.h:
Cleanup the headers.
sql/events.cc:
Use a different start up procedure of Event Scheduler:
- at start up, try to check the system tables first.
If they are not up-to-date, disable the scheduler.
- try to load all the active events. In case of a load error, abort
start up.
- do not parse an event on start up. Parsing only gives some information
about event validity, but far not all.
Consolidate the business logic of Events DDL in this module.
Now opt_event_scheduler may change after start up and thus is protected
by LOCK_event_metadata mutex.
sql/events.h:
Use all-static-data-members approach to implement Singleton pattern.
sql/mysqld.cc:
New invocation scheme of Events. Move some logic to events.cc.
Initialize the scheduler before reporting "Ready for connections".
sql/set_var.cc:
Clean up sys_var_thd_sql_mode::symbolic_mode_representation
to work with a LEX_STRING.
Move more logic related to @@events_scheduler global variable to Events
module.
sql/set_var.h:
Update declarations.
sql/share/errmsg.txt:
If someone tampered with mysql.event table after the server has
started we no longer give him/her a complete report what was actually
broken. Do not send the user to look at the error log in such case,
as there is nothing there (check_table_intact is not executed).
sql/sp_head.cc:
Update to a new declaration of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_db.cc:
New invocation scheme of Events module.
sql/sql_parse.cc:
Move more logic to Events module. Make sure that we are consistent
in the way access rights are checked for Events DDL: always
after committing the current transaction and checking the system tables.
sql/sql_show.cc:
Update to the new declarations of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_test.cc:
New invocation scheme of events.
sql/table.cc:
mysql.event is a system table.
Update check_table_intact to be concurrent, more verbose, and less smart.
sql/table.h:
Add a helper method.
mysql-test/r/events_trans.result:
New BitKeeper file ``mysql-test/r/events_trans.result''
mysql-test/t/events_trans.test:
New BitKeeper file ``mysql-test/t/events_trans.test'':
test cases for Event Scheduler that require a transactional
storage engine.
2007-04-05 13:24:34 +02:00
|
|
|
mutex_queue_data_locked(FALSE),
|
2007-04-16 18:16:17 +02:00
|
|
|
mutex_queue_data_attempting_lock(FALSE)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2006-07-11 18:28:15 +02:00
|
|
|
mutex_last_unlocked_in_func= mutex_last_locked_in_func=
|
|
|
|
mutex_last_attempted_lock_in_func= "";
|
2006-07-10 13:44:43 +02:00
|
|
|
|
|
|
|
pthread_mutex_init(&LOCK_event_queue, MY_MUTEX_INIT_FAST);
|
2006-09-14 23:25:59 +02:00
|
|
|
pthread_cond_init(&COND_queue_state, NULL);
|
2006-07-10 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
A set of changes aiming to make the Event Scheduler more user-friendly
when there are no up-to-date system tables to support it:
- initialize the scheduler before reporting "Ready for connections".
This ensures that warnings, if any, are printed before "Ready for
connections", and this message is not mangled.
- do not abort the scheduler if there are no system tables
- check the tables once at start up, remember the status and disable
the scheduler if the tables are not up to date.
If one attempts to use the scheduler with bad tables,
issue an error message.
- clean up the behaviour of the module under LOCK TABLES and pre-locking
mode
- make sure implicit commit of Events DDL works as expected.
- add more tests
Collateral clean ups in the events code.
This patch fixes Bug#23631 Events: SHOW VARIABLES doesn't work
when mysql.event is damaged
mysql-test/r/events.result:
Update results.
mysql-test/r/events_bugs.result:
Update results.
mysql-test/r/events_restart_phase1.result:
Update results.
mysql-test/r/events_restart_phase2.result:
Update results.
mysql-test/r/events_restart_phase3.result:
Update results.
mysql-test/r/events_scheduling.result:
Update results.
mysql-test/r/events_time_zone.result:
Update results.
mysql-test/t/events.test:
Add new tests for tampering with mysql.event and some more
tests for sub-statements, LOCK TABLES mode and pre-locking.
mysql-test/t/events_bugs.test:
Move the non-concurrent part of test for Bug 16420 to this file.
mysql-test/t/events_restart_phase1.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase2.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase3.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_scheduling.test:
Add more coverage for event_scheduler global variable.
mysql-test/t/events_time_zone.test:
Move the non-concurrent part of the tests for Bug 16420 to
events_bugs.test
sql/event_data_objects.cc:
Move update_timing_fields functionality to Event_db_repository.
Make loading of events from a table record more robust to tampering
with the table - now we do not check mysql.event on every table open.
sql/event_data_objects.h:
Cleanup.
sql/event_db_repository.cc:
Now Event_db_repository is responsible for table I/O only.
All the logic of events DDL is handled outside, in Events class please
refer to the added test coverage to see how this change affected
the behavior of Event Scheduler.
Dependency on sp_head.h and sp.h removed.
Make this module robust to tweaks with mysql.event table.
Move check_system_tables from events.cc to this file
sql/event_db_repository.h:
Cleanup declarations (remove unused ones, change return type to bool
from int).
sql/event_queue.cc:
Update to adapt to the new start up scheme of the Event Scheduler.
sql/event_queue.h:
Cleanup declarations.
sql/event_scheduler.cc:
Make all the error messages uniform:
[SEVERITY] Event Scheduler: [user][schema.event] message
Using append_identifier for error logging was an overkill - we may
need it only if the system character set may have NUL (null character)
as part of a valid identifier, this is currently never the case,
whereas additional quoting did not look nice in the log.
sql/event_scheduler.h:
Cleanup the headers.
sql/events.cc:
Use a different start up procedure of Event Scheduler:
- at start up, try to check the system tables first.
If they are not up-to-date, disable the scheduler.
- try to load all the active events. In case of a load error, abort
start up.
- do not parse an event on start up. Parsing only gives some information
about event validity, but far not all.
Consolidate the business logic of Events DDL in this module.
Now opt_event_scheduler may change after start up and thus is protected
by LOCK_event_metadata mutex.
sql/events.h:
Use all-static-data-members approach to implement Singleton pattern.
sql/mysqld.cc:
New invocation scheme of Events. Move some logic to events.cc.
Initialize the scheduler before reporting "Ready for connections".
sql/set_var.cc:
Clean up sys_var_thd_sql_mode::symbolic_mode_representation
to work with a LEX_STRING.
Move more logic related to @@events_scheduler global variable to Events
module.
sql/set_var.h:
Update declarations.
sql/share/errmsg.txt:
If someone tampered with mysql.event table after the server has
started we no longer give him/her a complete report what was actually
broken. Do not send the user to look at the error log in such case,
as there is nothing there (check_table_intact is not executed).
sql/sp_head.cc:
Update to a new declaration of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_db.cc:
New invocation scheme of Events module.
sql/sql_parse.cc:
Move more logic to Events module. Make sure that we are consistent
in the way access rights are checked for Events DDL: always
after committing the current transaction and checking the system tables.
sql/sql_show.cc:
Update to the new declarations of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_test.cc:
New invocation scheme of events.
sql/table.cc:
mysql.event is a system table.
Update check_table_intact to be concurrent, more verbose, and less smart.
sql/table.h:
Add a helper method.
mysql-test/r/events_trans.result:
New BitKeeper file ``mysql-test/r/events_trans.result''
mysql-test/t/events_trans.test:
New BitKeeper file ``mysql-test/t/events_trans.test'':
test cases for Event Scheduler that require a transactional
storage engine.
2007-04-05 13:24:34 +02:00
|
|
|
Event_queue::~Event_queue()
|
2006-07-10 13:44:43 +02:00
|
|
|
{
|
A set of changes aiming to make the Event Scheduler more user-friendly
when there are no up-to-date system tables to support it:
- initialize the scheduler before reporting "Ready for connections".
This ensures that warnings, if any, are printed before "Ready for
connections", and this message is not mangled.
- do not abort the scheduler if there are no system tables
- check the tables once at start up, remember the status and disable
the scheduler if the tables are not up to date.
If one attempts to use the scheduler with bad tables,
issue an error message.
- clean up the behaviour of the module under LOCK TABLES and pre-locking
mode
- make sure implicit commit of Events DDL works as expected.
- add more tests
Collateral clean ups in the events code.
This patch fixes Bug#23631 Events: SHOW VARIABLES doesn't work
when mysql.event is damaged
mysql-test/r/events.result:
Update results.
mysql-test/r/events_bugs.result:
Update results.
mysql-test/r/events_restart_phase1.result:
Update results.
mysql-test/r/events_restart_phase2.result:
Update results.
mysql-test/r/events_restart_phase3.result:
Update results.
mysql-test/r/events_scheduling.result:
Update results.
mysql-test/r/events_time_zone.result:
Update results.
mysql-test/t/events.test:
Add new tests for tampering with mysql.event and some more
tests for sub-statements, LOCK TABLES mode and pre-locking.
mysql-test/t/events_bugs.test:
Move the non-concurrent part of test for Bug 16420 to this file.
mysql-test/t/events_restart_phase1.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase2.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase3.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_scheduling.test:
Add more coverage for event_scheduler global variable.
mysql-test/t/events_time_zone.test:
Move the non-concurrent part of the tests for Bug 16420 to
events_bugs.test
sql/event_data_objects.cc:
Move update_timing_fields functionality to Event_db_repository.
Make loading of events from a table record more robust to tampering
with the table - now we do not check mysql.event on every table open.
sql/event_data_objects.h:
Cleanup.
sql/event_db_repository.cc:
Now Event_db_repository is responsible for table I/O only.
All the logic of events DDL is handled outside, in Events class please
refer to the added test coverage to see how this change affected
the behavior of Event Scheduler.
Dependency on sp_head.h and sp.h removed.
Make this module robust to tweaks with mysql.event table.
Move check_system_tables from events.cc to this file
sql/event_db_repository.h:
Cleanup declarations (remove unused ones, change return type to bool
from int).
sql/event_queue.cc:
Update to adapt to the new start up scheme of the Event Scheduler.
sql/event_queue.h:
Cleanup declarations.
sql/event_scheduler.cc:
Make all the error messages uniform:
[SEVERITY] Event Scheduler: [user][schema.event] message
Using append_identifier for error logging was an overkill - we may
need it only if the system character set may have NUL (null character)
as part of a valid identifier, this is currently never the case,
whereas additional quoting did not look nice in the log.
sql/event_scheduler.h:
Cleanup the headers.
sql/events.cc:
Use a different start up procedure of Event Scheduler:
- at start up, try to check the system tables first.
If they are not up-to-date, disable the scheduler.
- try to load all the active events. In case of a load error, abort
start up.
- do not parse an event on start up. Parsing only gives some information
about event validity, but far not all.
Consolidate the business logic of Events DDL in this module.
Now opt_event_scheduler may change after start up and thus is protected
by LOCK_event_metadata mutex.
sql/events.h:
Use all-static-data-members approach to implement Singleton pattern.
sql/mysqld.cc:
New invocation scheme of Events. Move some logic to events.cc.
Initialize the scheduler before reporting "Ready for connections".
sql/set_var.cc:
Clean up sys_var_thd_sql_mode::symbolic_mode_representation
to work with a LEX_STRING.
Move more logic related to @@events_scheduler global variable to Events
module.
sql/set_var.h:
Update declarations.
sql/share/errmsg.txt:
If someone tampered with mysql.event table after the server has
started we no longer give him/her a complete report what was actually
broken. Do not send the user to look at the error log in such case,
as there is nothing there (check_table_intact is not executed).
sql/sp_head.cc:
Update to a new declaration of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_db.cc:
New invocation scheme of Events module.
sql/sql_parse.cc:
Move more logic to Events module. Make sure that we are consistent
in the way access rights are checked for Events DDL: always
after committing the current transaction and checking the system tables.
sql/sql_show.cc:
Update to the new declarations of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_test.cc:
New invocation scheme of events.
sql/table.cc:
mysql.event is a system table.
Update check_table_intact to be concurrent, more verbose, and less smart.
sql/table.h:
Add a helper method.
mysql-test/r/events_trans.result:
New BitKeeper file ``mysql-test/r/events_trans.result''
mysql-test/t/events_trans.test:
New BitKeeper file ``mysql-test/t/events_trans.test'':
test cases for Event Scheduler that require a transactional
storage engine.
2007-04-05 13:24:34 +02:00
|
|
|
deinit_queue();
|
2006-07-10 13:44:43 +02:00
|
|
|
pthread_mutex_destroy(&LOCK_event_queue);
|
2006-09-14 23:25:59 +02:00
|
|
|
pthread_cond_destroy(&COND_queue_state);
|
2006-07-10 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-08-17 14:22:59 +02:00
|
|
|
This is a queue's constructor. Until this method is called, the
|
|
|
|
queue is unusable. We don't use a C++ constructor instead in
|
|
|
|
order to be able to check the return value. The queue is
|
|
|
|
initialized once at server startup. Initialization can fail in
|
|
|
|
case of a failure reading events from the database or out of
|
|
|
|
memory.
|
2006-07-10 13:44:43 +02:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::init()
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
FALSE OK
|
|
|
|
TRUE Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
2007-01-29 18:46:29 +01:00
|
|
|
Event_queue::init_queue(THD *thd)
|
2006-07-10 13:44:43 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Event_queue::init_queue");
|
2006-11-27 00:47:38 +01:00
|
|
|
DBUG_PRINT("enter", ("this: 0x%lx", (long) this));
|
2006-07-10 13:44:43 +02:00
|
|
|
|
|
|
|
LOCK_QUEUE_DATA();
|
|
|
|
|
2006-07-11 18:28:15 +02:00
|
|
|
if (init_queue_ex(&queue, EVENT_QUEUE_INITIAL_SIZE , 0 /*offset*/,
|
2006-07-17 16:52:45 +02:00
|
|
|
0 /*max_on_top*/, event_queue_element_compare_q,
|
2006-07-11 18:28:15 +02:00
|
|
|
NULL, EVENT_QUEUE_EXTENT))
|
2006-07-10 13:44:43 +02:00
|
|
|
{
|
2007-03-23 17:14:08 +01:00
|
|
|
sql_print_error("Event Scheduler: Can't initialize the execution queue");
|
2006-07-13 10:59:58 +02:00
|
|
|
goto err;
|
2006-07-10 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UNLOCK_QUEUE_DATA();
|
2007-01-29 18:46:29 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
2006-07-13 10:59:58 +02:00
|
|
|
|
|
|
|
err:
|
|
|
|
UNLOCK_QUEUE_DATA();
|
|
|
|
DBUG_RETURN(TRUE);
|
2006-07-10 13:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-07-11 18:28:15 +02:00
|
|
|
Deinits the queue. Remove all elements from it and destroys them
|
|
|
|
too.
|
2006-07-10 13:44:43 +02:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::deinit_queue()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
Event_queue::deinit_queue()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Event_queue::deinit_queue");
|
|
|
|
|
|
|
|
LOCK_QUEUE_DATA();
|
|
|
|
empty_queue();
|
|
|
|
delete_queue(&queue);
|
|
|
|
UNLOCK_QUEUE_DATA();
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-23 16:14:03 +01:00
|
|
|
/**
|
2006-07-11 18:28:15 +02:00
|
|
|
Adds an event to the queue.
|
2006-07-03 11:20:08 +02:00
|
|
|
|
A set of changes aiming to make the Event Scheduler more user-friendly
when there are no up-to-date system tables to support it:
- initialize the scheduler before reporting "Ready for connections".
This ensures that warnings, if any, are printed before "Ready for
connections", and this message is not mangled.
- do not abort the scheduler if there are no system tables
- check the tables once at start up, remember the status and disable
the scheduler if the tables are not up to date.
If one attempts to use the scheduler with bad tables,
issue an error message.
- clean up the behaviour of the module under LOCK TABLES and pre-locking
mode
- make sure implicit commit of Events DDL works as expected.
- add more tests
Collateral clean ups in the events code.
This patch fixes Bug#23631 Events: SHOW VARIABLES doesn't work
when mysql.event is damaged
mysql-test/r/events.result:
Update results.
mysql-test/r/events_bugs.result:
Update results.
mysql-test/r/events_restart_phase1.result:
Update results.
mysql-test/r/events_restart_phase2.result:
Update results.
mysql-test/r/events_restart_phase3.result:
Update results.
mysql-test/r/events_scheduling.result:
Update results.
mysql-test/r/events_time_zone.result:
Update results.
mysql-test/t/events.test:
Add new tests for tampering with mysql.event and some more
tests for sub-statements, LOCK TABLES mode and pre-locking.
mysql-test/t/events_bugs.test:
Move the non-concurrent part of test for Bug 16420 to this file.
mysql-test/t/events_restart_phase1.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase2.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase3.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_scheduling.test:
Add more coverage for event_scheduler global variable.
mysql-test/t/events_time_zone.test:
Move the non-concurrent part of the tests for Bug 16420 to
events_bugs.test
sql/event_data_objects.cc:
Move update_timing_fields functionality to Event_db_repository.
Make loading of events from a table record more robust to tampering
with the table - now we do not check mysql.event on every table open.
sql/event_data_objects.h:
Cleanup.
sql/event_db_repository.cc:
Now Event_db_repository is responsible for table I/O only.
All the logic of events DDL is handled outside, in Events class please
refer to the added test coverage to see how this change affected
the behavior of Event Scheduler.
Dependency on sp_head.h and sp.h removed.
Make this module robust to tweaks with mysql.event table.
Move check_system_tables from events.cc to this file
sql/event_db_repository.h:
Cleanup declarations (remove unused ones, change return type to bool
from int).
sql/event_queue.cc:
Update to adapt to the new start up scheme of the Event Scheduler.
sql/event_queue.h:
Cleanup declarations.
sql/event_scheduler.cc:
Make all the error messages uniform:
[SEVERITY] Event Scheduler: [user][schema.event] message
Using append_identifier for error logging was an overkill - we may
need it only if the system character set may have NUL (null character)
as part of a valid identifier, this is currently never the case,
whereas additional quoting did not look nice in the log.
sql/event_scheduler.h:
Cleanup the headers.
sql/events.cc:
Use a different start up procedure of Event Scheduler:
- at start up, try to check the system tables first.
If they are not up-to-date, disable the scheduler.
- try to load all the active events. In case of a load error, abort
start up.
- do not parse an event on start up. Parsing only gives some information
about event validity, but far not all.
Consolidate the business logic of Events DDL in this module.
Now opt_event_scheduler may change after start up and thus is protected
by LOCK_event_metadata mutex.
sql/events.h:
Use all-static-data-members approach to implement Singleton pattern.
sql/mysqld.cc:
New invocation scheme of Events. Move some logic to events.cc.
Initialize the scheduler before reporting "Ready for connections".
sql/set_var.cc:
Clean up sys_var_thd_sql_mode::symbolic_mode_representation
to work with a LEX_STRING.
Move more logic related to @@events_scheduler global variable to Events
module.
sql/set_var.h:
Update declarations.
sql/share/errmsg.txt:
If someone tampered with mysql.event table after the server has
started we no longer give him/her a complete report what was actually
broken. Do not send the user to look at the error log in such case,
as there is nothing there (check_table_intact is not executed).
sql/sp_head.cc:
Update to a new declaration of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_db.cc:
New invocation scheme of Events module.
sql/sql_parse.cc:
Move more logic to Events module. Make sure that we are consistent
in the way access rights are checked for Events DDL: always
after committing the current transaction and checking the system tables.
sql/sql_show.cc:
Update to the new declarations of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_test.cc:
New invocation scheme of events.
sql/table.cc:
mysql.event is a system table.
Update check_table_intact to be concurrent, more verbose, and less smart.
sql/table.h:
Add a helper method.
mysql-test/r/events_trans.result:
New BitKeeper file ``mysql-test/r/events_trans.result''
mysql-test/t/events_trans.test:
New BitKeeper file ``mysql-test/t/events_trans.test'':
test cases for Event Scheduler that require a transactional
storage engine.
2007-04-05 13:24:34 +02:00
|
|
|
Compute the next execution time for an event, and if it is still
|
|
|
|
active, add it to the queue. Otherwise delete it.
|
|
|
|
The object is left intact in case of an error. Otherwise
|
|
|
|
the queue container assumes ownership of it.
|
|
|
|
|
|
|
|
@param[in] thd thread handle
|
|
|
|
@param[in] new_element a new element to add to the queue
|
|
|
|
@param[out] created set to TRUE if no error and the element is
|
|
|
|
added to the queue, FALSE otherwise
|
|
|
|
|
|
|
|
@retval TRUE an error occured. The value of created is undefined,
|
|
|
|
the element was not deleted.
|
|
|
|
@retval FALSE success
|
2006-07-03 11:20:08 +02:00
|
|
|
*/
|
|
|
|
|
A set of changes aiming to make the Event Scheduler more user-friendly
when there are no up-to-date system tables to support it:
- initialize the scheduler before reporting "Ready for connections".
This ensures that warnings, if any, are printed before "Ready for
connections", and this message is not mangled.
- do not abort the scheduler if there are no system tables
- check the tables once at start up, remember the status and disable
the scheduler if the tables are not up to date.
If one attempts to use the scheduler with bad tables,
issue an error message.
- clean up the behaviour of the module under LOCK TABLES and pre-locking
mode
- make sure implicit commit of Events DDL works as expected.
- add more tests
Collateral clean ups in the events code.
This patch fixes Bug#23631 Events: SHOW VARIABLES doesn't work
when mysql.event is damaged
mysql-test/r/events.result:
Update results.
mysql-test/r/events_bugs.result:
Update results.
mysql-test/r/events_restart_phase1.result:
Update results.
mysql-test/r/events_restart_phase2.result:
Update results.
mysql-test/r/events_restart_phase3.result:
Update results.
mysql-test/r/events_scheduling.result:
Update results.
mysql-test/r/events_time_zone.result:
Update results.
mysql-test/t/events.test:
Add new tests for tampering with mysql.event and some more
tests for sub-statements, LOCK TABLES mode and pre-locking.
mysql-test/t/events_bugs.test:
Move the non-concurrent part of test for Bug 16420 to this file.
mysql-test/t/events_restart_phase1.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase2.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase3.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_scheduling.test:
Add more coverage for event_scheduler global variable.
mysql-test/t/events_time_zone.test:
Move the non-concurrent part of the tests for Bug 16420 to
events_bugs.test
sql/event_data_objects.cc:
Move update_timing_fields functionality to Event_db_repository.
Make loading of events from a table record more robust to tampering
with the table - now we do not check mysql.event on every table open.
sql/event_data_objects.h:
Cleanup.
sql/event_db_repository.cc:
Now Event_db_repository is responsible for table I/O only.
All the logic of events DDL is handled outside, in Events class please
refer to the added test coverage to see how this change affected
the behavior of Event Scheduler.
Dependency on sp_head.h and sp.h removed.
Make this module robust to tweaks with mysql.event table.
Move check_system_tables from events.cc to this file
sql/event_db_repository.h:
Cleanup declarations (remove unused ones, change return type to bool
from int).
sql/event_queue.cc:
Update to adapt to the new start up scheme of the Event Scheduler.
sql/event_queue.h:
Cleanup declarations.
sql/event_scheduler.cc:
Make all the error messages uniform:
[SEVERITY] Event Scheduler: [user][schema.event] message
Using append_identifier for error logging was an overkill - we may
need it only if the system character set may have NUL (null character)
as part of a valid identifier, this is currently never the case,
whereas additional quoting did not look nice in the log.
sql/event_scheduler.h:
Cleanup the headers.
sql/events.cc:
Use a different start up procedure of Event Scheduler:
- at start up, try to check the system tables first.
If they are not up-to-date, disable the scheduler.
- try to load all the active events. In case of a load error, abort
start up.
- do not parse an event on start up. Parsing only gives some information
about event validity, but far not all.
Consolidate the business logic of Events DDL in this module.
Now opt_event_scheduler may change after start up and thus is protected
by LOCK_event_metadata mutex.
sql/events.h:
Use all-static-data-members approach to implement Singleton pattern.
sql/mysqld.cc:
New invocation scheme of Events. Move some logic to events.cc.
Initialize the scheduler before reporting "Ready for connections".
sql/set_var.cc:
Clean up sys_var_thd_sql_mode::symbolic_mode_representation
to work with a LEX_STRING.
Move more logic related to @@events_scheduler global variable to Events
module.
sql/set_var.h:
Update declarations.
sql/share/errmsg.txt:
If someone tampered with mysql.event table after the server has
started we no longer give him/her a complete report what was actually
broken. Do not send the user to look at the error log in such case,
as there is nothing there (check_table_intact is not executed).
sql/sp_head.cc:
Update to a new declaration of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_db.cc:
New invocation scheme of Events module.
sql/sql_parse.cc:
Move more logic to Events module. Make sure that we are consistent
in the way access rights are checked for Events DDL: always
after committing the current transaction and checking the system tables.
sql/sql_show.cc:
Update to the new declarations of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_test.cc:
New invocation scheme of events.
sql/table.cc:
mysql.event is a system table.
Update check_table_intact to be concurrent, more verbose, and less smart.
sql/table.h:
Add a helper method.
mysql-test/r/events_trans.result:
New BitKeeper file ``mysql-test/r/events_trans.result''
mysql-test/t/events_trans.test:
New BitKeeper file ``mysql-test/t/events_trans.test'':
test cases for Event Scheduler that require a transactional
storage engine.
2007-04-05 13:24:34 +02:00
|
|
|
bool
|
|
|
|
Event_queue::create_event(THD *thd, Event_queue_element *new_element,
|
|
|
|
bool *created)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Event_queue::create_event");
|
2007-03-02 00:39:00 +01:00
|
|
|
DBUG_PRINT("enter", ("thd: 0x%lx et=%s.%s", (long) thd,
|
2007-01-29 18:46:29 +01:00
|
|
|
new_element->dbname.str, new_element->name.str));
|
2006-07-03 11:20:08 +02:00
|
|
|
|
A set of changes aiming to make the Event Scheduler more user-friendly
when there are no up-to-date system tables to support it:
- initialize the scheduler before reporting "Ready for connections".
This ensures that warnings, if any, are printed before "Ready for
connections", and this message is not mangled.
- do not abort the scheduler if there are no system tables
- check the tables once at start up, remember the status and disable
the scheduler if the tables are not up to date.
If one attempts to use the scheduler with bad tables,
issue an error message.
- clean up the behaviour of the module under LOCK TABLES and pre-locking
mode
- make sure implicit commit of Events DDL works as expected.
- add more tests
Collateral clean ups in the events code.
This patch fixes Bug#23631 Events: SHOW VARIABLES doesn't work
when mysql.event is damaged
mysql-test/r/events.result:
Update results.
mysql-test/r/events_bugs.result:
Update results.
mysql-test/r/events_restart_phase1.result:
Update results.
mysql-test/r/events_restart_phase2.result:
Update results.
mysql-test/r/events_restart_phase3.result:
Update results.
mysql-test/r/events_scheduling.result:
Update results.
mysql-test/r/events_time_zone.result:
Update results.
mysql-test/t/events.test:
Add new tests for tampering with mysql.event and some more
tests for sub-statements, LOCK TABLES mode and pre-locking.
mysql-test/t/events_bugs.test:
Move the non-concurrent part of test for Bug 16420 to this file.
mysql-test/t/events_restart_phase1.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase2.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase3.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_scheduling.test:
Add more coverage for event_scheduler global variable.
mysql-test/t/events_time_zone.test:
Move the non-concurrent part of the tests for Bug 16420 to
events_bugs.test
sql/event_data_objects.cc:
Move update_timing_fields functionality to Event_db_repository.
Make loading of events from a table record more robust to tampering
with the table - now we do not check mysql.event on every table open.
sql/event_data_objects.h:
Cleanup.
sql/event_db_repository.cc:
Now Event_db_repository is responsible for table I/O only.
All the logic of events DDL is handled outside, in Events class please
refer to the added test coverage to see how this change affected
the behavior of Event Scheduler.
Dependency on sp_head.h and sp.h removed.
Make this module robust to tweaks with mysql.event table.
Move check_system_tables from events.cc to this file
sql/event_db_repository.h:
Cleanup declarations (remove unused ones, change return type to bool
from int).
sql/event_queue.cc:
Update to adapt to the new start up scheme of the Event Scheduler.
sql/event_queue.h:
Cleanup declarations.
sql/event_scheduler.cc:
Make all the error messages uniform:
[SEVERITY] Event Scheduler: [user][schema.event] message
Using append_identifier for error logging was an overkill - we may
need it only if the system character set may have NUL (null character)
as part of a valid identifier, this is currently never the case,
whereas additional quoting did not look nice in the log.
sql/event_scheduler.h:
Cleanup the headers.
sql/events.cc:
Use a different start up procedure of Event Scheduler:
- at start up, try to check the system tables first.
If they are not up-to-date, disable the scheduler.
- try to load all the active events. In case of a load error, abort
start up.
- do not parse an event on start up. Parsing only gives some information
about event validity, but far not all.
Consolidate the business logic of Events DDL in this module.
Now opt_event_scheduler may change after start up and thus is protected
by LOCK_event_metadata mutex.
sql/events.h:
Use all-static-data-members approach to implement Singleton pattern.
sql/mysqld.cc:
New invocation scheme of Events. Move some logic to events.cc.
Initialize the scheduler before reporting "Ready for connections".
sql/set_var.cc:
Clean up sys_var_thd_sql_mode::symbolic_mode_representation
to work with a LEX_STRING.
Move more logic related to @@events_scheduler global variable to Events
module.
sql/set_var.h:
Update declarations.
sql/share/errmsg.txt:
If someone tampered with mysql.event table after the server has
started we no longer give him/her a complete report what was actually
broken. Do not send the user to look at the error log in such case,
as there is nothing there (check_table_intact is not executed).
sql/sp_head.cc:
Update to a new declaration of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_db.cc:
New invocation scheme of Events module.
sql/sql_parse.cc:
Move more logic to Events module. Make sure that we are consistent
in the way access rights are checked for Events DDL: always
after committing the current transaction and checking the system tables.
sql/sql_show.cc:
Update to the new declarations of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_test.cc:
New invocation scheme of events.
sql/table.cc:
mysql.event is a system table.
Update check_table_intact to be concurrent, more verbose, and less smart.
sql/table.h:
Add a helper method.
mysql-test/r/events_trans.result:
New BitKeeper file ``mysql-test/r/events_trans.result''
mysql-test/t/events_trans.test:
New BitKeeper file ``mysql-test/t/events_trans.test'':
test cases for Event Scheduler that require a transactional
storage engine.
2007-04-05 13:24:34 +02:00
|
|
|
/* Will do nothing if the event is disabled */
|
|
|
|
new_element->compute_next_execution_time();
|
2007-04-05 13:49:46 +02:00
|
|
|
if (new_element->status != Event_queue_element::ENABLED)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
A set of changes aiming to make the Event Scheduler more user-friendly
when there are no up-to-date system tables to support it:
- initialize the scheduler before reporting "Ready for connections".
This ensures that warnings, if any, are printed before "Ready for
connections", and this message is not mangled.
- do not abort the scheduler if there are no system tables
- check the tables once at start up, remember the status and disable
the scheduler if the tables are not up to date.
If one attempts to use the scheduler with bad tables,
issue an error message.
- clean up the behaviour of the module under LOCK TABLES and pre-locking
mode
- make sure implicit commit of Events DDL works as expected.
- add more tests
Collateral clean ups in the events code.
This patch fixes Bug#23631 Events: SHOW VARIABLES doesn't work
when mysql.event is damaged
mysql-test/r/events.result:
Update results.
mysql-test/r/events_bugs.result:
Update results.
mysql-test/r/events_restart_phase1.result:
Update results.
mysql-test/r/events_restart_phase2.result:
Update results.
mysql-test/r/events_restart_phase3.result:
Update results.
mysql-test/r/events_scheduling.result:
Update results.
mysql-test/r/events_time_zone.result:
Update results.
mysql-test/t/events.test:
Add new tests for tampering with mysql.event and some more
tests for sub-statements, LOCK TABLES mode and pre-locking.
mysql-test/t/events_bugs.test:
Move the non-concurrent part of test for Bug 16420 to this file.
mysql-test/t/events_restart_phase1.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase2.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase3.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_scheduling.test:
Add more coverage for event_scheduler global variable.
mysql-test/t/events_time_zone.test:
Move the non-concurrent part of the tests for Bug 16420 to
events_bugs.test
sql/event_data_objects.cc:
Move update_timing_fields functionality to Event_db_repository.
Make loading of events from a table record more robust to tampering
with the table - now we do not check mysql.event on every table open.
sql/event_data_objects.h:
Cleanup.
sql/event_db_repository.cc:
Now Event_db_repository is responsible for table I/O only.
All the logic of events DDL is handled outside, in Events class please
refer to the added test coverage to see how this change affected
the behavior of Event Scheduler.
Dependency on sp_head.h and sp.h removed.
Make this module robust to tweaks with mysql.event table.
Move check_system_tables from events.cc to this file
sql/event_db_repository.h:
Cleanup declarations (remove unused ones, change return type to bool
from int).
sql/event_queue.cc:
Update to adapt to the new start up scheme of the Event Scheduler.
sql/event_queue.h:
Cleanup declarations.
sql/event_scheduler.cc:
Make all the error messages uniform:
[SEVERITY] Event Scheduler: [user][schema.event] message
Using append_identifier for error logging was an overkill - we may
need it only if the system character set may have NUL (null character)
as part of a valid identifier, this is currently never the case,
whereas additional quoting did not look nice in the log.
sql/event_scheduler.h:
Cleanup the headers.
sql/events.cc:
Use a different start up procedure of Event Scheduler:
- at start up, try to check the system tables first.
If they are not up-to-date, disable the scheduler.
- try to load all the active events. In case of a load error, abort
start up.
- do not parse an event on start up. Parsing only gives some information
about event validity, but far not all.
Consolidate the business logic of Events DDL in this module.
Now opt_event_scheduler may change after start up and thus is protected
by LOCK_event_metadata mutex.
sql/events.h:
Use all-static-data-members approach to implement Singleton pattern.
sql/mysqld.cc:
New invocation scheme of Events. Move some logic to events.cc.
Initialize the scheduler before reporting "Ready for connections".
sql/set_var.cc:
Clean up sys_var_thd_sql_mode::symbolic_mode_representation
to work with a LEX_STRING.
Move more logic related to @@events_scheduler global variable to Events
module.
sql/set_var.h:
Update declarations.
sql/share/errmsg.txt:
If someone tampered with mysql.event table after the server has
started we no longer give him/her a complete report what was actually
broken. Do not send the user to look at the error log in such case,
as there is nothing there (check_table_intact is not executed).
sql/sp_head.cc:
Update to a new declaration of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_db.cc:
New invocation scheme of Events module.
sql/sql_parse.cc:
Move more logic to Events module. Make sure that we are consistent
in the way access rights are checked for Events DDL: always
after committing the current transaction and checking the system tables.
sql/sql_show.cc:
Update to the new declarations of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_test.cc:
New invocation scheme of events.
sql/table.cc:
mysql.event is a system table.
Update check_table_intact to be concurrent, more verbose, and less smart.
sql/table.h:
Add a helper method.
mysql-test/r/events_trans.result:
New BitKeeper file ``mysql-test/r/events_trans.result''
mysql-test/t/events_trans.test:
New BitKeeper file ``mysql-test/t/events_trans.test'':
test cases for Event Scheduler that require a transactional
storage engine.
2007-04-05 13:24:34 +02:00
|
|
|
delete new_element;
|
|
|
|
*created= FALSE;
|
|
|
|
DBUG_RETURN(FALSE);
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
A set of changes aiming to make the Event Scheduler more user-friendly
when there are no up-to-date system tables to support it:
- initialize the scheduler before reporting "Ready for connections".
This ensures that warnings, if any, are printed before "Ready for
connections", and this message is not mangled.
- do not abort the scheduler if there are no system tables
- check the tables once at start up, remember the status and disable
the scheduler if the tables are not up to date.
If one attempts to use the scheduler with bad tables,
issue an error message.
- clean up the behaviour of the module under LOCK TABLES and pre-locking
mode
- make sure implicit commit of Events DDL works as expected.
- add more tests
Collateral clean ups in the events code.
This patch fixes Bug#23631 Events: SHOW VARIABLES doesn't work
when mysql.event is damaged
mysql-test/r/events.result:
Update results.
mysql-test/r/events_bugs.result:
Update results.
mysql-test/r/events_restart_phase1.result:
Update results.
mysql-test/r/events_restart_phase2.result:
Update results.
mysql-test/r/events_restart_phase3.result:
Update results.
mysql-test/r/events_scheduling.result:
Update results.
mysql-test/r/events_time_zone.result:
Update results.
mysql-test/t/events.test:
Add new tests for tampering with mysql.event and some more
tests for sub-statements, LOCK TABLES mode and pre-locking.
mysql-test/t/events_bugs.test:
Move the non-concurrent part of test for Bug 16420 to this file.
mysql-test/t/events_restart_phase1.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase2.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase3.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_scheduling.test:
Add more coverage for event_scheduler global variable.
mysql-test/t/events_time_zone.test:
Move the non-concurrent part of the tests for Bug 16420 to
events_bugs.test
sql/event_data_objects.cc:
Move update_timing_fields functionality to Event_db_repository.
Make loading of events from a table record more robust to tampering
with the table - now we do not check mysql.event on every table open.
sql/event_data_objects.h:
Cleanup.
sql/event_db_repository.cc:
Now Event_db_repository is responsible for table I/O only.
All the logic of events DDL is handled outside, in Events class please
refer to the added test coverage to see how this change affected
the behavior of Event Scheduler.
Dependency on sp_head.h and sp.h removed.
Make this module robust to tweaks with mysql.event table.
Move check_system_tables from events.cc to this file
sql/event_db_repository.h:
Cleanup declarations (remove unused ones, change return type to bool
from int).
sql/event_queue.cc:
Update to adapt to the new start up scheme of the Event Scheduler.
sql/event_queue.h:
Cleanup declarations.
sql/event_scheduler.cc:
Make all the error messages uniform:
[SEVERITY] Event Scheduler: [user][schema.event] message
Using append_identifier for error logging was an overkill - we may
need it only if the system character set may have NUL (null character)
as part of a valid identifier, this is currently never the case,
whereas additional quoting did not look nice in the log.
sql/event_scheduler.h:
Cleanup the headers.
sql/events.cc:
Use a different start up procedure of Event Scheduler:
- at start up, try to check the system tables first.
If they are not up-to-date, disable the scheduler.
- try to load all the active events. In case of a load error, abort
start up.
- do not parse an event on start up. Parsing only gives some information
about event validity, but far not all.
Consolidate the business logic of Events DDL in this module.
Now opt_event_scheduler may change after start up and thus is protected
by LOCK_event_metadata mutex.
sql/events.h:
Use all-static-data-members approach to implement Singleton pattern.
sql/mysqld.cc:
New invocation scheme of Events. Move some logic to events.cc.
Initialize the scheduler before reporting "Ready for connections".
sql/set_var.cc:
Clean up sys_var_thd_sql_mode::symbolic_mode_representation
to work with a LEX_STRING.
Move more logic related to @@events_scheduler global variable to Events
module.
sql/set_var.h:
Update declarations.
sql/share/errmsg.txt:
If someone tampered with mysql.event table after the server has
started we no longer give him/her a complete report what was actually
broken. Do not send the user to look at the error log in such case,
as there is nothing there (check_table_intact is not executed).
sql/sp_head.cc:
Update to a new declaration of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_db.cc:
New invocation scheme of Events module.
sql/sql_parse.cc:
Move more logic to Events module. Make sure that we are consistent
in the way access rights are checked for Events DDL: always
after committing the current transaction and checking the system tables.
sql/sql_show.cc:
Update to the new declarations of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_test.cc:
New invocation scheme of events.
sql/table.cc:
mysql.event is a system table.
Update check_table_intact to be concurrent, more verbose, and less smart.
sql/table.h:
Add a helper method.
mysql-test/r/events_trans.result:
New BitKeeper file ``mysql-test/r/events_trans.result''
mysql-test/t/events_trans.test:
New BitKeeper file ``mysql-test/t/events_trans.test'':
test cases for Event Scheduler that require a transactional
storage engine.
2007-04-05 13:24:34 +02:00
|
|
|
|
|
|
|
DBUG_PRINT("info", ("new event in the queue: 0x%lx", (long) new_element));
|
|
|
|
|
|
|
|
LOCK_QUEUE_DATA();
|
|
|
|
*created= (queue_insert_safe(&queue, (byte *) new_element) == FALSE);
|
|
|
|
dbug_dump_queue(thd->query_start());
|
|
|
|
pthread_cond_broadcast(&COND_queue_state);
|
|
|
|
UNLOCK_QUEUE_DATA();
|
|
|
|
|
|
|
|
DBUG_RETURN(!*created);
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Updates an event from the scheduler queue
|
|
|
|
|
|
|
|
SYNOPSIS
|
2006-07-04 18:44:35 +02:00
|
|
|
Event_queue::update_event()
|
2006-07-03 11:20:08 +02:00
|
|
|
thd Thread
|
2006-07-10 13:44:43 +02:00
|
|
|
dbname Schema of the event
|
|
|
|
name Name of the event
|
|
|
|
new_schema New schema, in case of RENAME TO, otherwise NULL
|
|
|
|
new_name New name, in case of RENAME TO, otherwise NULL
|
2006-07-03 11:20:08 +02:00
|
|
|
*/
|
|
|
|
|
2007-01-29 18:46:29 +01:00
|
|
|
void
|
2006-07-10 13:44:43 +02:00
|
|
|
Event_queue::update_event(THD *thd, LEX_STRING dbname, LEX_STRING name,
|
2007-01-29 18:46:29 +01:00
|
|
|
Event_queue_element *new_element)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Event_queue::update_event");
|
2006-11-27 00:47:38 +01:00
|
|
|
DBUG_PRINT("enter", ("thd: 0x%lx et=[%s.%s]", (long) thd, dbname.str, name.str));
|
2006-07-03 11:20:08 +02:00
|
|
|
|
2007-03-29 14:17:19 +02:00
|
|
|
if ((new_element->status == Event_queue_element::DISABLED) ||
|
|
|
|
(new_element->status == Event_queue_element::SLAVESIDE_DISABLED))
|
2006-07-10 13:44:43 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("The event is disabled."));
|
|
|
|
/*
|
|
|
|
Destroy the object but don't skip to end: because we may have to remove
|
|
|
|
object from the cache.
|
|
|
|
*/
|
2006-07-11 18:28:15 +02:00
|
|
|
delete new_element;
|
|
|
|
new_element= NULL;
|
2006-07-10 13:44:43 +02:00
|
|
|
}
|
|
|
|
else
|
2006-07-11 18:28:15 +02:00
|
|
|
new_element->compute_next_execution_time();
|
2006-07-05 17:12:50 +02:00
|
|
|
|
2006-07-03 11:20:08 +02:00
|
|
|
LOCK_QUEUE_DATA();
|
2006-08-17 14:22:59 +02:00
|
|
|
find_n_remove_event(dbname, name);
|
|
|
|
|
2006-07-10 13:44:43 +02:00
|
|
|
/* If not disabled event */
|
2006-07-11 18:28:15 +02:00
|
|
|
if (new_element)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2006-11-27 00:47:38 +01:00
|
|
|
DBUG_PRINT("info", ("new event in the queue: 0x%lx", (long) new_element));
|
2006-07-11 18:28:15 +02:00
|
|
|
queue_insert_safe(&queue, (byte *) new_element);
|
2007-03-23 16:14:03 +01:00
|
|
|
pthread_cond_broadcast(&COND_queue_state);
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
2006-08-31 17:18:39 +02:00
|
|
|
|
2006-07-17 16:52:45 +02:00
|
|
|
dbug_dump_queue(thd->query_start());
|
2006-07-03 11:20:08 +02:00
|
|
|
UNLOCK_QUEUE_DATA();
|
|
|
|
|
2007-01-29 18:46:29 +01:00
|
|
|
DBUG_VOID_RETURN;
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-07-04 18:44:35 +02:00
|
|
|
Drops an event from the queue
|
2006-07-03 11:20:08 +02:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::drop_event()
|
2006-07-10 13:44:43 +02:00
|
|
|
thd Thread
|
|
|
|
dbname Schema of the event to drop
|
|
|
|
name Name of the event to drop
|
2006-07-03 11:20:08 +02:00
|
|
|
*/
|
|
|
|
|
2006-07-10 13:44:43 +02:00
|
|
|
void
|
|
|
|
Event_queue::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Event_queue::drop_event");
|
2006-11-27 00:47:38 +01:00
|
|
|
DBUG_PRINT("enter", ("thd: 0x%lx db :%s name: %s", (long) thd,
|
|
|
|
dbname.str, name.str));
|
2006-07-03 11:20:08 +02:00
|
|
|
|
|
|
|
LOCK_QUEUE_DATA();
|
2006-08-17 14:22:59 +02:00
|
|
|
find_n_remove_event(dbname, name);
|
2006-07-17 16:52:45 +02:00
|
|
|
dbug_dump_queue(thd->query_start());
|
2006-07-03 11:20:08 +02:00
|
|
|
UNLOCK_QUEUE_DATA();
|
2007-03-23 16:14:03 +01:00
|
|
|
|
2006-07-05 17:12:50 +02:00
|
|
|
/*
|
|
|
|
We don't signal here because the scheduler will catch the change
|
|
|
|
next time it wakes up.
|
|
|
|
*/
|
2006-07-03 11:20:08 +02:00
|
|
|
|
2006-07-10 13:44:43 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Drops all events from the in-memory queue and disk that match
|
|
|
|
certain pattern evaluated by a comparator function
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::drop_matching_events()
|
|
|
|
thd THD
|
|
|
|
pattern A pattern string
|
|
|
|
comparator The function to use for comparing
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
>=0 Number of dropped events
|
2007-03-23 16:14:03 +01:00
|
|
|
|
2006-07-03 11:20:08 +02:00
|
|
|
NOTE
|
|
|
|
Expected is the caller to acquire lock on LOCK_event_queue
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
Event_queue::drop_matching_events(THD *thd, LEX_STRING pattern,
|
2006-07-11 18:28:15 +02:00
|
|
|
bool (*comparator)(LEX_STRING, Event_basic *))
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2006-08-17 14:22:59 +02:00
|
|
|
uint i= 0;
|
2006-07-03 11:20:08 +02:00
|
|
|
DBUG_ENTER("Event_queue::drop_matching_events");
|
2006-07-17 16:52:45 +02:00
|
|
|
DBUG_PRINT("enter", ("pattern=%s", pattern.str));
|
2006-07-03 11:20:08 +02:00
|
|
|
|
|
|
|
while (i < queue.elements)
|
|
|
|
{
|
2006-07-10 13:44:43 +02:00
|
|
|
Event_queue_element *et= (Event_queue_element *) queue_element(&queue, i);
|
2006-07-03 11:20:08 +02:00
|
|
|
DBUG_PRINT("info", ("[%s.%s]?", et->dbname.str, et->name.str));
|
2006-07-11 18:28:15 +02:00
|
|
|
if (comparator(pattern, et))
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
|
|
|
/*
|
2006-08-17 14:22:59 +02:00
|
|
|
The queue is ordered. If we remove an element, then all elements
|
|
|
|
after it will shift one position to the left, if we imagine it as
|
|
|
|
an array from left to the right. In this case we should not
|
|
|
|
increment the counter and the (i < queue.elements) condition is ok.
|
2006-07-03 11:20:08 +02:00
|
|
|
*/
|
|
|
|
queue_remove(&queue, i);
|
2006-07-05 17:12:50 +02:00
|
|
|
delete et;
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
/*
|
2007-03-23 16:14:03 +01:00
|
|
|
We don't call pthread_cond_broadcast(&COND_queue_state);
|
2006-08-31 17:18:39 +02:00
|
|
|
If we remove the top event:
|
2006-08-17 14:22:59 +02:00
|
|
|
1. The queue is empty. The scheduler will wake up at some time and
|
|
|
|
realize that the queue is empty. If create_event() comes inbetween
|
|
|
|
it will signal the scheduler
|
|
|
|
2. The queue is not empty, but the next event after the previous top,
|
|
|
|
won't be executed any time sooner than the element we removed. Hence,
|
|
|
|
we may not notify the scheduler and it will realize the change when it
|
2006-07-05 17:12:50 +02:00
|
|
|
wakes up from timedwait.
|
2006-07-03 11:20:08 +02:00
|
|
|
*/
|
2006-07-10 23:54:46 +02:00
|
|
|
|
2006-07-03 11:20:08 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Drops all events from the in-memory queue and disk that are from
|
|
|
|
certain schema.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::drop_schema_events()
|
2006-08-17 14:22:59 +02:00
|
|
|
thd HD
|
|
|
|
schema The schema name
|
2006-07-03 11:20:08 +02:00
|
|
|
*/
|
|
|
|
|
2006-07-05 17:12:50 +02:00
|
|
|
void
|
2006-07-03 11:20:08 +02:00
|
|
|
Event_queue::drop_schema_events(THD *thd, LEX_STRING schema)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Event_queue::drop_schema_events");
|
|
|
|
LOCK_QUEUE_DATA();
|
2006-07-10 13:44:43 +02:00
|
|
|
drop_matching_events(thd, schema, event_basic_db_equal);
|
2006-07-03 11:20:08 +02:00
|
|
|
UNLOCK_QUEUE_DATA();
|
2006-07-05 17:12:50 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-11 18:28:15 +02:00
|
|
|
/*
|
|
|
|
Searches for an event in the queue
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::find_n_remove_event()
|
|
|
|
db The schema of the event to find
|
|
|
|
name The event to find
|
2006-07-03 11:20:08 +02:00
|
|
|
|
2006-07-11 18:28:15 +02:00
|
|
|
NOTE
|
|
|
|
The caller should do the locking also the caller is responsible for
|
|
|
|
actual signalling in case an event is removed from the queue.
|
2006-07-03 11:20:08 +02:00
|
|
|
*/
|
|
|
|
|
2006-08-17 14:22:59 +02:00
|
|
|
void
|
2006-07-11 18:28:15 +02:00
|
|
|
Event_queue::find_n_remove_event(LEX_STRING db, LEX_STRING name)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2006-07-11 18:28:15 +02:00
|
|
|
uint i;
|
|
|
|
DBUG_ENTER("Event_queue::find_n_remove_event");
|
|
|
|
|
|
|
|
for (i= 0; i < queue.elements; ++i)
|
|
|
|
{
|
|
|
|
Event_queue_element *et= (Event_queue_element *) queue_element(&queue, i);
|
|
|
|
DBUG_PRINT("info", ("[%s.%s]==[%s.%s]?", db.str, name.str,
|
|
|
|
et->dbname.str, et->name.str));
|
|
|
|
if (event_basic_identifier_equal(db, name, et))
|
|
|
|
{
|
|
|
|
queue_remove(&queue, i);
|
2006-08-17 14:22:59 +02:00
|
|
|
delete et;
|
|
|
|
break;
|
2006-07-11 18:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-17 14:22:59 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-07-10 13:44:43 +02:00
|
|
|
Recalculates activation times in the queue. There is one reason for
|
|
|
|
that. Because the values (execute_at) by which the queue is ordered are
|
|
|
|
changed by calls to compute_next_execution_time() on a request from the
|
|
|
|
scheduler thread, if it is not running then the values won't be updated.
|
|
|
|
Once the scheduler is started again the values has to be recalculated
|
|
|
|
so they are right for the current time.
|
2006-07-03 11:20:08 +02:00
|
|
|
|
|
|
|
SYNOPSIS
|
2006-07-10 13:44:43 +02:00
|
|
|
Event_queue::recalculate_activation_times()
|
|
|
|
thd Thread
|
2006-07-03 11:20:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2006-07-10 13:44:43 +02:00
|
|
|
Event_queue::recalculate_activation_times(THD *thd)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2006-07-10 13:44:43 +02:00
|
|
|
uint i;
|
|
|
|
DBUG_ENTER("Event_queue::recalculate_activation_times");
|
2006-07-03 11:20:08 +02:00
|
|
|
|
|
|
|
LOCK_QUEUE_DATA();
|
2006-07-10 13:44:43 +02:00
|
|
|
DBUG_PRINT("info", ("%u loaded events to be recalculated", queue.elements));
|
|
|
|
for (i= 0; i < queue.elements; i++)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2006-07-10 13:44:43 +02:00
|
|
|
((Event_queue_element*)queue_element(&queue, i))->compute_next_execution_time();
|
|
|
|
((Event_queue_element*)queue_element(&queue, i))->update_timing_fields(thd);
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
2006-07-10 13:44:43 +02:00
|
|
|
queue_fix(&queue);
|
2006-07-03 11:20:08 +02:00
|
|
|
UNLOCK_QUEUE_DATA();
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-10 13:44:43 +02:00
|
|
|
/*
|
|
|
|
Empties the queue and destroys the Event_queue_element objects in the
|
|
|
|
queue.
|
2006-07-03 11:20:08 +02:00
|
|
|
|
2006-07-10 13:44:43 +02:00
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::empty_queue()
|
|
|
|
|
|
|
|
NOTE
|
2006-08-17 14:22:59 +02:00
|
|
|
Should be called with LOCK_event_queue locked
|
2006-07-10 13:44:43 +02:00
|
|
|
*/
|
2006-07-03 11:20:08 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
Event_queue::empty_queue()
|
|
|
|
{
|
2006-07-04 18:44:35 +02:00
|
|
|
uint i;
|
2006-07-05 17:12:50 +02:00
|
|
|
DBUG_ENTER("Event_queue::empty_queue");
|
2007-01-29 18:46:29 +01:00
|
|
|
DBUG_PRINT("enter", ("Purging the queue. %u element(s)", queue.elements));
|
2007-03-23 17:14:08 +01:00
|
|
|
sql_print_information("Event Scheduler: Purging the queue. %u events",
|
|
|
|
queue.elements);
|
2006-07-03 11:20:08 +02:00
|
|
|
/* empty the queue */
|
2006-07-10 13:44:43 +02:00
|
|
|
for (i= 0; i < queue.elements; ++i)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2006-07-10 13:44:43 +02:00
|
|
|
Event_queue_element *et= (Event_queue_element *) queue_element(&queue, i);
|
2006-07-03 11:20:08 +02:00
|
|
|
delete et;
|
|
|
|
}
|
|
|
|
resize_queue(&queue, 0);
|
2006-07-05 17:12:50 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
2006-07-04 18:44:35 +02:00
|
|
|
|
|
|
|
|
2006-07-11 18:28:15 +02:00
|
|
|
/*
|
|
|
|
Dumps the queue to the trace log.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::dbug_dump_queue()
|
|
|
|
now Current timestamp
|
|
|
|
*/
|
|
|
|
|
2006-07-17 16:52:45 +02:00
|
|
|
void
|
2006-07-05 17:12:50 +02:00
|
|
|
Event_queue::dbug_dump_queue(time_t now)
|
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
2006-07-10 13:44:43 +02:00
|
|
|
Event_queue_element *et;
|
2006-07-05 17:12:50 +02:00
|
|
|
uint i;
|
2006-07-17 16:52:45 +02:00
|
|
|
DBUG_ENTER("Event_queue::dbug_dump_queue");
|
2006-07-05 17:12:50 +02:00
|
|
|
DBUG_PRINT("info", ("Dumping queue . Elements=%u", queue.elements));
|
|
|
|
for (i = 0; i < queue.elements; i++)
|
|
|
|
{
|
2006-07-10 13:44:43 +02:00
|
|
|
et= ((Event_queue_element*)queue_element(&queue, i));
|
2006-11-27 00:47:38 +01:00
|
|
|
DBUG_PRINT("info", ("et: 0x%lx name: %s.%s", (long) et,
|
|
|
|
et->dbname.str, et->name.str));
|
|
|
|
DBUG_PRINT("info", ("exec_at: %lu starts: %lu ends: %lu execs_so_far: %u "
|
|
|
|
"expr: %ld et.exec_at: %ld now: %ld "
|
|
|
|
"(et.exec_at - now): %d if: %d",
|
BUG#16420: Events: timestamps become UTC
BUG#26429: SHOW CREATE EVENT is incorrect for an event that
STARTS NOW()
BUG#26431: Impossible to re-create an event from backup if its
STARTS clause is in the past
WL#3698: Events: execution in local time zone
The problem was that local times specified by the user in AT, STARTS
and ENDS of CREATE EVENT/ALTER EVENT statement were converted to UTC,
and the original time zone was forgotten. This way, event scheduler
couldn't honor Daylight Saving Time shifts, and times shown to the
user were also in UTC. Additionally, CREATE EVENT didn't allow times
in the past, thus preventing straightforward event restoration from
old backups.
This patch reworks event scheduler time computations, performing them
in the time zone associated with the event. Also it allows times to
be in the past.
The patch adds time_zone column to mysql.event table.
NOTE: The patch is almost final, but the bug#9953 should be pushed
first.
client/mysqldump.c:
Before every CREATE EVENT, output its time zone.
mysql-test/include/wait_condition.inc:
Add optional $wait_timeout parameter.
mysql-test/lib/init_db.sql:
Add time_zone column.
mysql-test/r/events.result:
Update result.
mysql-test/r/events_bugs.result:
Update result.
mysql-test/r/events_grant.result:
Update result.
mysql-test/r/events_restart_phase1.result:
Update result.
mysql-test/r/events_scheduling.result:
Update result.
mysql-test/r/mysqldump.result:
Update result.
mysql-test/r/ps.result:
Update result.
mysql-test/r/system_mysql_db.result:
Update result.
mysql-test/t/events.test:
Remove STARTS from the result, as it depends on current time.
mysql-test/t/events_bugs.test:
Time in the past is no longer an error.
mysql-test/t/events_restart_phase1.test:
Fill new column 'time_zone' in mysql.event.
mysql-test/t/events_scheduling.test:
Cleanup: disable event scheduler.
scripts/mysql_create_system_tables.sh:
Add new column 'time_zone' to mysql.event.
scripts/mysql_fix_privilege_tables.sql:
Add new column 'time_zone' to mysql.event.
sql/event_data_objects.cc:
The essence of the change is the following:
- for internal times use my_time_t instead of TIME. Assignment and
comparison is done now on plain numbers.
- in init_execute_at(), init_starts(), init_ends() convert given time
to number of seconds since Epoch (aka Unix time, in UTC).
- handle time_zone field loading and storing.
- in get_next_time(), Unix time is converted back to event time zone,
interval is added, and the result is converted to UTC again.
- fix Event_timed::get_create_event() to report STARTS and ENDS.
- before executing the event body we set thread time zone to the
event time zone.
sql/event_data_objects.h:
Add time_zone member to Event_basic class.
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_db_repository.cc:
Add time_zone column handling.
Give a warning and do not create an event if its execution time is in
the past, and ON COMPLETION NOT PRESERVE is set, because such an event
should be dropped by that time. Also, do not allow ALTER EVENT to
set execution time in the past when ON COMPLETION NOT PRESERVE is set.
sql/event_db_repository.h:
Add enum member for new time zone column.
sql/event_queue.cc:
Replace handling of broken down times with simple handling of
my_time_t.
sql/event_queue.h:
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_scheduler.cc:
Add TODO comment.
sql/events.cc:
Send time_zone column for SHOW CREATE EVENT.
sql/share/errmsg.txt:
Update error message, and add two more errors.
sql/sql_show.cc:
Add TIME_ZONE column to the output of SHOW EVENTS.
mysql-test/r/events_time_zone.result:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/r/events_time_zone.result
mysql-test/t/events_time_zone.test:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/t/events_time_zone.test
2007-03-16 15:31:07 +01:00
|
|
|
(long) et->execute_at, (long) et->starts,
|
|
|
|
(long) et->ends, et->execution_count,
|
|
|
|
(long) et->expression, (long) et->execute_at,
|
|
|
|
(long) now, (int) (et->execute_at - now),
|
|
|
|
et->execute_at <= now));
|
2006-07-05 17:12:50 +02:00
|
|
|
}
|
2006-07-17 16:52:45 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2006-07-05 17:12:50 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-08-31 17:18:39 +02:00
|
|
|
static const char *queue_empty_msg= "Waiting on empty queue";
|
|
|
|
static const char *queue_wait_msg= "Waiting for next activation";
|
2006-07-11 18:28:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Checks whether the top of the queue is elligible for execution and
|
|
|
|
returns an Event_job_data instance in case it should be executed.
|
|
|
|
`now` is compared against `execute_at` of the top element in the queue.
|
|
|
|
|
|
|
|
SYNOPSIS
|
2006-07-17 16:52:45 +02:00
|
|
|
Event_queue::get_top_for_execution_if_time()
|
2007-01-29 18:46:29 +01:00
|
|
|
thd [in] Thread
|
|
|
|
event_name [out] The object to execute
|
2006-07-11 18:28:15 +02:00
|
|
|
|
|
|
|
RETURN VALUE
|
2007-01-29 18:46:29 +01:00
|
|
|
FALSE No error. event_name != NULL
|
|
|
|
TRUE Serious error
|
2006-07-11 18:28:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
2007-01-29 18:46:29 +01:00
|
|
|
Event_queue::get_top_for_execution_if_time(THD *thd,
|
|
|
|
Event_queue_element_for_exec **event_name)
|
2006-07-04 18:44:35 +02:00
|
|
|
{
|
2006-07-11 18:28:15 +02:00
|
|
|
bool ret= FALSE;
|
2007-01-29 18:46:29 +01:00
|
|
|
*event_name= NULL;
|
2006-07-04 18:44:35 +02:00
|
|
|
DBUG_ENTER("Event_queue::get_top_for_execution_if_time");
|
2006-08-31 17:18:39 +02:00
|
|
|
|
2006-07-04 18:44:35 +02:00
|
|
|
LOCK_QUEUE_DATA();
|
2006-08-31 17:18:39 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
2007-01-29 18:46:29 +01:00
|
|
|
Event_queue_element *top= NULL;
|
2006-07-05 17:12:50 +02:00
|
|
|
|
2006-12-18 12:00:35 +01:00
|
|
|
/* Break loop if thd has been killed */
|
|
|
|
if (thd->killed)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("thd->killed=%d", thd->killed));
|
|
|
|
goto end;
|
|
|
|
}
|
2006-07-04 18:44:35 +02:00
|
|
|
|
2006-12-18 12:00:35 +01:00
|
|
|
if (!queue.elements)
|
2006-08-31 17:18:39 +02:00
|
|
|
{
|
2006-12-18 12:00:35 +01:00
|
|
|
/* There are no events in the queue */
|
BUG#16420: Events: timestamps become UTC
BUG#26429: SHOW CREATE EVENT is incorrect for an event that
STARTS NOW()
BUG#26431: Impossible to re-create an event from backup if its
STARTS clause is in the past
WL#3698: Events: execution in local time zone
The problem was that local times specified by the user in AT, STARTS
and ENDS of CREATE EVENT/ALTER EVENT statement were converted to UTC,
and the original time zone was forgotten. This way, event scheduler
couldn't honor Daylight Saving Time shifts, and times shown to the
user were also in UTC. Additionally, CREATE EVENT didn't allow times
in the past, thus preventing straightforward event restoration from
old backups.
This patch reworks event scheduler time computations, performing them
in the time zone associated with the event. Also it allows times to
be in the past.
The patch adds time_zone column to mysql.event table.
NOTE: The patch is almost final, but the bug#9953 should be pushed
first.
client/mysqldump.c:
Before every CREATE EVENT, output its time zone.
mysql-test/include/wait_condition.inc:
Add optional $wait_timeout parameter.
mysql-test/lib/init_db.sql:
Add time_zone column.
mysql-test/r/events.result:
Update result.
mysql-test/r/events_bugs.result:
Update result.
mysql-test/r/events_grant.result:
Update result.
mysql-test/r/events_restart_phase1.result:
Update result.
mysql-test/r/events_scheduling.result:
Update result.
mysql-test/r/mysqldump.result:
Update result.
mysql-test/r/ps.result:
Update result.
mysql-test/r/system_mysql_db.result:
Update result.
mysql-test/t/events.test:
Remove STARTS from the result, as it depends on current time.
mysql-test/t/events_bugs.test:
Time in the past is no longer an error.
mysql-test/t/events_restart_phase1.test:
Fill new column 'time_zone' in mysql.event.
mysql-test/t/events_scheduling.test:
Cleanup: disable event scheduler.
scripts/mysql_create_system_tables.sh:
Add new column 'time_zone' to mysql.event.
scripts/mysql_fix_privilege_tables.sql:
Add new column 'time_zone' to mysql.event.
sql/event_data_objects.cc:
The essence of the change is the following:
- for internal times use my_time_t instead of TIME. Assignment and
comparison is done now on plain numbers.
- in init_execute_at(), init_starts(), init_ends() convert given time
to number of seconds since Epoch (aka Unix time, in UTC).
- handle time_zone field loading and storing.
- in get_next_time(), Unix time is converted back to event time zone,
interval is added, and the result is converted to UTC again.
- fix Event_timed::get_create_event() to report STARTS and ENDS.
- before executing the event body we set thread time zone to the
event time zone.
sql/event_data_objects.h:
Add time_zone member to Event_basic class.
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_db_repository.cc:
Add time_zone column handling.
Give a warning and do not create an event if its execution time is in
the past, and ON COMPLETION NOT PRESERVE is set, because such an event
should be dropped by that time. Also, do not allow ALTER EVENT to
set execution time in the past when ON COMPLETION NOT PRESERVE is set.
sql/event_db_repository.h:
Add enum member for new time zone column.
sql/event_queue.cc:
Replace handling of broken down times with simple handling of
my_time_t.
sql/event_queue.h:
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_scheduler.cc:
Add TODO comment.
sql/events.cc:
Send time_zone column for SHOW CREATE EVENT.
sql/share/errmsg.txt:
Update error message, and add two more errors.
sql/sql_show.cc:
Add TIME_ZONE column to the output of SHOW EVENTS.
mysql-test/r/events_time_zone.result:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/r/events_time_zone.result
mysql-test/t/events_time_zone.test:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/t/events_time_zone.test
2007-03-16 15:31:07 +01:00
|
|
|
next_activation_at= 0;
|
2006-12-18 12:00:35 +01:00
|
|
|
|
|
|
|
/* Wait on condition until signaled. Release LOCK_queue while waiting. */
|
|
|
|
cond_wait(thd, NULL, queue_empty_msg, SCHED_FUNC, __LINE__);
|
2006-07-11 18:28:15 +02:00
|
|
|
|
2006-12-18 12:00:35 +01:00
|
|
|
continue;
|
2006-08-31 17:18:39 +02:00
|
|
|
}
|
|
|
|
|
2006-12-18 12:00:35 +01:00
|
|
|
top= ((Event_queue_element*) queue_element(&queue, 0));
|
2006-08-31 17:18:39 +02:00
|
|
|
|
2006-12-18 12:00:35 +01:00
|
|
|
thd->end_time(); /* Get current time */
|
|
|
|
|
|
|
|
next_activation_at= top->execute_at;
|
BUG#16420: Events: timestamps become UTC
BUG#26429: SHOW CREATE EVENT is incorrect for an event that
STARTS NOW()
BUG#26431: Impossible to re-create an event from backup if its
STARTS clause is in the past
WL#3698: Events: execution in local time zone
The problem was that local times specified by the user in AT, STARTS
and ENDS of CREATE EVENT/ALTER EVENT statement were converted to UTC,
and the original time zone was forgotten. This way, event scheduler
couldn't honor Daylight Saving Time shifts, and times shown to the
user were also in UTC. Additionally, CREATE EVENT didn't allow times
in the past, thus preventing straightforward event restoration from
old backups.
This patch reworks event scheduler time computations, performing them
in the time zone associated with the event. Also it allows times to
be in the past.
The patch adds time_zone column to mysql.event table.
NOTE: The patch is almost final, but the bug#9953 should be pushed
first.
client/mysqldump.c:
Before every CREATE EVENT, output its time zone.
mysql-test/include/wait_condition.inc:
Add optional $wait_timeout parameter.
mysql-test/lib/init_db.sql:
Add time_zone column.
mysql-test/r/events.result:
Update result.
mysql-test/r/events_bugs.result:
Update result.
mysql-test/r/events_grant.result:
Update result.
mysql-test/r/events_restart_phase1.result:
Update result.
mysql-test/r/events_scheduling.result:
Update result.
mysql-test/r/mysqldump.result:
Update result.
mysql-test/r/ps.result:
Update result.
mysql-test/r/system_mysql_db.result:
Update result.
mysql-test/t/events.test:
Remove STARTS from the result, as it depends on current time.
mysql-test/t/events_bugs.test:
Time in the past is no longer an error.
mysql-test/t/events_restart_phase1.test:
Fill new column 'time_zone' in mysql.event.
mysql-test/t/events_scheduling.test:
Cleanup: disable event scheduler.
scripts/mysql_create_system_tables.sh:
Add new column 'time_zone' to mysql.event.
scripts/mysql_fix_privilege_tables.sql:
Add new column 'time_zone' to mysql.event.
sql/event_data_objects.cc:
The essence of the change is the following:
- for internal times use my_time_t instead of TIME. Assignment and
comparison is done now on plain numbers.
- in init_execute_at(), init_starts(), init_ends() convert given time
to number of seconds since Epoch (aka Unix time, in UTC).
- handle time_zone field loading and storing.
- in get_next_time(), Unix time is converted back to event time zone,
interval is added, and the result is converted to UTC again.
- fix Event_timed::get_create_event() to report STARTS and ENDS.
- before executing the event body we set thread time zone to the
event time zone.
sql/event_data_objects.h:
Add time_zone member to Event_basic class.
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_db_repository.cc:
Add time_zone column handling.
Give a warning and do not create an event if its execution time is in
the past, and ON COMPLETION NOT PRESERVE is set, because such an event
should be dropped by that time. Also, do not allow ALTER EVENT to
set execution time in the past when ON COMPLETION NOT PRESERVE is set.
sql/event_db_repository.h:
Add enum member for new time zone column.
sql/event_queue.cc:
Replace handling of broken down times with simple handling of
my_time_t.
sql/event_queue.h:
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_scheduler.cc:
Add TODO comment.
sql/events.cc:
Send time_zone column for SHOW CREATE EVENT.
sql/share/errmsg.txt:
Update error message, and add two more errors.
sql/sql_show.cc:
Add TIME_ZONE column to the output of SHOW EVENTS.
mysql-test/r/events_time_zone.result:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/r/events_time_zone.result
mysql-test/t/events_time_zone.test:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/t/events_time_zone.test
2007-03-16 15:31:07 +01:00
|
|
|
if (next_activation_at > thd->query_start())
|
2006-12-18 12:00:35 +01:00
|
|
|
{
|
2006-08-31 17:18:39 +02:00
|
|
|
/*
|
2006-12-18 12:00:35 +01:00
|
|
|
Not yet time for top event, wait on condition with
|
|
|
|
time or until signaled. Release LOCK_queue while waiting.
|
2006-08-31 17:18:39 +02:00
|
|
|
*/
|
BUG#16420: Events: timestamps become UTC
BUG#26429: SHOW CREATE EVENT is incorrect for an event that
STARTS NOW()
BUG#26431: Impossible to re-create an event from backup if its
STARTS clause is in the past
WL#3698: Events: execution in local time zone
The problem was that local times specified by the user in AT, STARTS
and ENDS of CREATE EVENT/ALTER EVENT statement were converted to UTC,
and the original time zone was forgotten. This way, event scheduler
couldn't honor Daylight Saving Time shifts, and times shown to the
user were also in UTC. Additionally, CREATE EVENT didn't allow times
in the past, thus preventing straightforward event restoration from
old backups.
This patch reworks event scheduler time computations, performing them
in the time zone associated with the event. Also it allows times to
be in the past.
The patch adds time_zone column to mysql.event table.
NOTE: The patch is almost final, but the bug#9953 should be pushed
first.
client/mysqldump.c:
Before every CREATE EVENT, output its time zone.
mysql-test/include/wait_condition.inc:
Add optional $wait_timeout parameter.
mysql-test/lib/init_db.sql:
Add time_zone column.
mysql-test/r/events.result:
Update result.
mysql-test/r/events_bugs.result:
Update result.
mysql-test/r/events_grant.result:
Update result.
mysql-test/r/events_restart_phase1.result:
Update result.
mysql-test/r/events_scheduling.result:
Update result.
mysql-test/r/mysqldump.result:
Update result.
mysql-test/r/ps.result:
Update result.
mysql-test/r/system_mysql_db.result:
Update result.
mysql-test/t/events.test:
Remove STARTS from the result, as it depends on current time.
mysql-test/t/events_bugs.test:
Time in the past is no longer an error.
mysql-test/t/events_restart_phase1.test:
Fill new column 'time_zone' in mysql.event.
mysql-test/t/events_scheduling.test:
Cleanup: disable event scheduler.
scripts/mysql_create_system_tables.sh:
Add new column 'time_zone' to mysql.event.
scripts/mysql_fix_privilege_tables.sql:
Add new column 'time_zone' to mysql.event.
sql/event_data_objects.cc:
The essence of the change is the following:
- for internal times use my_time_t instead of TIME. Assignment and
comparison is done now on plain numbers.
- in init_execute_at(), init_starts(), init_ends() convert given time
to number of seconds since Epoch (aka Unix time, in UTC).
- handle time_zone field loading and storing.
- in get_next_time(), Unix time is converted back to event time zone,
interval is added, and the result is converted to UTC again.
- fix Event_timed::get_create_event() to report STARTS and ENDS.
- before executing the event body we set thread time zone to the
event time zone.
sql/event_data_objects.h:
Add time_zone member to Event_basic class.
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_db_repository.cc:
Add time_zone column handling.
Give a warning and do not create an event if its execution time is in
the past, and ON COMPLETION NOT PRESERVE is set, because such an event
should be dropped by that time. Also, do not allow ALTER EVENT to
set execution time in the past when ON COMPLETION NOT PRESERVE is set.
sql/event_db_repository.h:
Add enum member for new time zone column.
sql/event_queue.cc:
Replace handling of broken down times with simple handling of
my_time_t.
sql/event_queue.h:
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_scheduler.cc:
Add TODO comment.
sql/events.cc:
Send time_zone column for SHOW CREATE EVENT.
sql/share/errmsg.txt:
Update error message, and add two more errors.
sql/sql_show.cc:
Add TIME_ZONE column to the output of SHOW EVENTS.
mysql-test/r/events_time_zone.result:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/r/events_time_zone.result
mysql-test/t/events_time_zone.test:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/t/events_time_zone.test
2007-03-16 15:31:07 +01:00
|
|
|
struct timespec top_time;
|
2007-03-16 18:50:37 +01:00
|
|
|
set_timespec(top_time, next_activation_at - thd->query_start());
|
2006-12-18 12:00:35 +01:00
|
|
|
cond_wait(thd, &top_time, queue_wait_msg, SCHED_FUNC, __LINE__);
|
|
|
|
|
2006-08-31 17:18:39 +02:00
|
|
|
continue;
|
2006-07-04 18:44:35 +02:00
|
|
|
}
|
2006-07-11 18:28:15 +02:00
|
|
|
|
2007-01-29 18:46:29 +01:00
|
|
|
if (!(*event_name= new Event_queue_element_for_exec()) ||
|
|
|
|
(*event_name)->init(top->dbname, top->name))
|
2006-07-11 18:28:15 +02:00
|
|
|
{
|
|
|
|
ret= TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-29 18:46:29 +01:00
|
|
|
DBUG_PRINT("info", ("Ready for execution"));
|
2006-07-11 18:28:15 +02:00
|
|
|
top->mark_last_executed(thd);
|
|
|
|
if (top->compute_next_execution_time())
|
|
|
|
top->status= Event_queue_element::DISABLED;
|
2006-07-17 16:52:45 +02:00
|
|
|
DBUG_PRINT("info", ("event %s status is %d", top->name.str, top->status));
|
|
|
|
|
2007-01-29 18:46:29 +01:00
|
|
|
top->execution_count++;
|
|
|
|
(*event_name)->dropped= top->dropped;
|
2006-07-11 18:28:15 +02:00
|
|
|
|
|
|
|
top->update_timing_fields(thd);
|
2007-01-29 18:46:29 +01:00
|
|
|
if (top->status == Event_queue_element::DISABLED)
|
2006-07-11 18:28:15 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("removing from the queue"));
|
2007-03-23 17:14:08 +01:00
|
|
|
sql_print_information("Event Scheduler: Last execution of %s.%s. %s",
|
2006-07-17 16:52:45 +02:00
|
|
|
top->dbname.str, top->name.str,
|
|
|
|
top->dropped? "Dropping.":"");
|
2007-01-29 18:46:29 +01:00
|
|
|
delete top;
|
2006-07-11 18:28:15 +02:00
|
|
|
queue_remove(&queue, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
queue_replaced(&queue);
|
2006-07-17 16:52:45 +02:00
|
|
|
|
2006-12-18 12:00:35 +01:00
|
|
|
dbug_dump_queue(thd->query_start());
|
2006-08-31 17:18:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
end:
|
2006-07-04 18:44:35 +02:00
|
|
|
UNLOCK_QUEUE_DATA();
|
2006-09-14 13:49:26 +02:00
|
|
|
|
2007-01-29 18:46:29 +01:00
|
|
|
DBUG_PRINT("info", ("returning %d et_new: 0x%lx ",
|
|
|
|
ret, (long) *event_name));
|
2006-07-11 18:28:15 +02:00
|
|
|
|
2007-01-29 18:46:29 +01:00
|
|
|
if (*event_name)
|
|
|
|
DBUG_PRINT("info", ("db: %s name: %s",
|
|
|
|
(*event_name)->dbname.str, (*event_name)->name.str));
|
2006-07-11 18:28:15 +02:00
|
|
|
|
|
|
|
DBUG_RETURN(ret);
|
2006-07-04 18:44:35 +02:00
|
|
|
}
|
2006-07-10 13:44:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Auxiliary function for locking LOCK_event_queue. Used by the
|
|
|
|
LOCK_QUEUE_DATA macro
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::lock_data()
|
|
|
|
func Which function is requesting mutex lock
|
|
|
|
line On which line mutex lock is requested
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
Event_queue::lock_data(const char *func, uint line)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Event_queue::lock_data");
|
|
|
|
DBUG_PRINT("enter", ("func=%s line=%u", func, line));
|
2006-07-11 18:28:15 +02:00
|
|
|
mutex_last_attempted_lock_in_func= func;
|
|
|
|
mutex_last_attempted_lock_at_line= line;
|
|
|
|
mutex_queue_data_attempting_lock= TRUE;
|
2006-07-10 13:44:43 +02:00
|
|
|
pthread_mutex_lock(&LOCK_event_queue);
|
2006-07-11 18:28:15 +02:00
|
|
|
mutex_last_attempted_lock_in_func= "";
|
|
|
|
mutex_last_attempted_lock_at_line= 0;
|
|
|
|
mutex_queue_data_attempting_lock= FALSE;
|
|
|
|
|
2006-07-10 13:44:43 +02:00
|
|
|
mutex_last_locked_in_func= func;
|
|
|
|
mutex_last_locked_at_line= line;
|
|
|
|
mutex_queue_data_locked= TRUE;
|
2006-07-11 18:28:15 +02:00
|
|
|
|
2006-07-10 13:44:43 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Auxiliary function for unlocking LOCK_event_queue. Used by the
|
|
|
|
UNLOCK_QUEUE_DATA macro
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::unlock_data()
|
|
|
|
func Which function is requesting mutex unlock
|
|
|
|
line On which line mutex unlock is requested
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
Event_queue::unlock_data(const char *func, uint line)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Event_queue::unlock_data");
|
|
|
|
DBUG_PRINT("enter", ("func=%s line=%u", func, line));
|
|
|
|
mutex_last_unlocked_at_line= line;
|
|
|
|
mutex_queue_data_locked= FALSE;
|
|
|
|
mutex_last_unlocked_in_func= func;
|
|
|
|
pthread_mutex_unlock(&LOCK_event_queue);
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-31 17:18:39 +02:00
|
|
|
/*
|
|
|
|
Wrapper for pthread_cond_wait/timedwait
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::cond_wait()
|
|
|
|
thd Thread (Could be NULL during shutdown procedure)
|
|
|
|
msg Message for thd->proc_info
|
|
|
|
abstime If not null then call pthread_cond_timedwait()
|
|
|
|
func Which function is requesting cond_wait
|
|
|
|
line On which line cond_wait is requested
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
Event_queue::cond_wait(THD *thd, struct timespec *abstime, const char* msg,
|
|
|
|
const char *func, uint line)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Event_queue::cond_wait");
|
|
|
|
waiting_on_cond= TRUE;
|
|
|
|
mutex_last_unlocked_at_line= line;
|
|
|
|
mutex_queue_data_locked= FALSE;
|
|
|
|
mutex_last_unlocked_in_func= func;
|
|
|
|
|
|
|
|
thd->enter_cond(&COND_queue_state, &LOCK_event_queue, msg);
|
|
|
|
|
|
|
|
DBUG_PRINT("info", ("pthread_cond_%swait", abstime? "timed":""));
|
|
|
|
if (!abstime)
|
|
|
|
pthread_cond_wait(&COND_queue_state, &LOCK_event_queue);
|
|
|
|
else
|
|
|
|
pthread_cond_timedwait(&COND_queue_state, &LOCK_event_queue, abstime);
|
|
|
|
|
|
|
|
mutex_last_locked_in_func= func;
|
|
|
|
mutex_last_locked_at_line= line;
|
|
|
|
mutex_queue_data_locked= TRUE;
|
|
|
|
waiting_on_cond= FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This will free the lock so we need to relock. Not the best thing to
|
|
|
|
do but we need to obey cond_wait()
|
|
|
|
*/
|
|
|
|
thd->exit_cond("");
|
2006-09-12 12:26:12 +02:00
|
|
|
lock_data(func, line);
|
2006-08-31 17:18:39 +02:00
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-10 13:44:43 +02:00
|
|
|
/*
|
|
|
|
Dumps the internal status of the queue
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::dump_internal_status()
|
|
|
|
*/
|
|
|
|
|
2006-09-12 12:26:12 +02:00
|
|
|
void
|
|
|
|
Event_queue::dump_internal_status()
|
2006-07-10 13:44:43 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Event_queue::dump_internal_status");
|
2006-08-31 17:18:39 +02:00
|
|
|
|
2006-09-12 12:26:12 +02:00
|
|
|
/* element count */
|
|
|
|
puts("");
|
|
|
|
puts("Event queue status:");
|
|
|
|
printf("Element count : %u\n", queue.elements);
|
|
|
|
printf("Data locked : %s\n", mutex_queue_data_locked? "YES":"NO");
|
|
|
|
printf("Attempting lock : %s\n", mutex_queue_data_attempting_lock? "YES":"NO");
|
|
|
|
printf("LLA : %s:%u\n", mutex_last_locked_in_func,
|
|
|
|
mutex_last_locked_at_line);
|
|
|
|
printf("LUA : %s:%u\n", mutex_last_unlocked_in_func,
|
|
|
|
mutex_last_unlocked_at_line);
|
|
|
|
if (mutex_last_attempted_lock_at_line)
|
|
|
|
printf("Last lock attempt at: %s:%u\n", mutex_last_attempted_lock_in_func,
|
|
|
|
mutex_last_attempted_lock_at_line);
|
|
|
|
printf("WOC : %s\n", waiting_on_cond? "YES":"NO");
|
BUG#16420: Events: timestamps become UTC
BUG#26429: SHOW CREATE EVENT is incorrect for an event that
STARTS NOW()
BUG#26431: Impossible to re-create an event from backup if its
STARTS clause is in the past
WL#3698: Events: execution in local time zone
The problem was that local times specified by the user in AT, STARTS
and ENDS of CREATE EVENT/ALTER EVENT statement were converted to UTC,
and the original time zone was forgotten. This way, event scheduler
couldn't honor Daylight Saving Time shifts, and times shown to the
user were also in UTC. Additionally, CREATE EVENT didn't allow times
in the past, thus preventing straightforward event restoration from
old backups.
This patch reworks event scheduler time computations, performing them
in the time zone associated with the event. Also it allows times to
be in the past.
The patch adds time_zone column to mysql.event table.
NOTE: The patch is almost final, but the bug#9953 should be pushed
first.
client/mysqldump.c:
Before every CREATE EVENT, output its time zone.
mysql-test/include/wait_condition.inc:
Add optional $wait_timeout parameter.
mysql-test/lib/init_db.sql:
Add time_zone column.
mysql-test/r/events.result:
Update result.
mysql-test/r/events_bugs.result:
Update result.
mysql-test/r/events_grant.result:
Update result.
mysql-test/r/events_restart_phase1.result:
Update result.
mysql-test/r/events_scheduling.result:
Update result.
mysql-test/r/mysqldump.result:
Update result.
mysql-test/r/ps.result:
Update result.
mysql-test/r/system_mysql_db.result:
Update result.
mysql-test/t/events.test:
Remove STARTS from the result, as it depends on current time.
mysql-test/t/events_bugs.test:
Time in the past is no longer an error.
mysql-test/t/events_restart_phase1.test:
Fill new column 'time_zone' in mysql.event.
mysql-test/t/events_scheduling.test:
Cleanup: disable event scheduler.
scripts/mysql_create_system_tables.sh:
Add new column 'time_zone' to mysql.event.
scripts/mysql_fix_privilege_tables.sql:
Add new column 'time_zone' to mysql.event.
sql/event_data_objects.cc:
The essence of the change is the following:
- for internal times use my_time_t instead of TIME. Assignment and
comparison is done now on plain numbers.
- in init_execute_at(), init_starts(), init_ends() convert given time
to number of seconds since Epoch (aka Unix time, in UTC).
- handle time_zone field loading and storing.
- in get_next_time(), Unix time is converted back to event time zone,
interval is added, and the result is converted to UTC again.
- fix Event_timed::get_create_event() to report STARTS and ENDS.
- before executing the event body we set thread time zone to the
event time zone.
sql/event_data_objects.h:
Add time_zone member to Event_basic class.
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_db_repository.cc:
Add time_zone column handling.
Give a warning and do not create an event if its execution time is in
the past, and ON COMPLETION NOT PRESERVE is set, because such an event
should be dropped by that time. Also, do not allow ALTER EVENT to
set execution time in the past when ON COMPLETION NOT PRESERVE is set.
sql/event_db_repository.h:
Add enum member for new time zone column.
sql/event_queue.cc:
Replace handling of broken down times with simple handling of
my_time_t.
sql/event_queue.h:
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_scheduler.cc:
Add TODO comment.
sql/events.cc:
Send time_zone column for SHOW CREATE EVENT.
sql/share/errmsg.txt:
Update error message, and add two more errors.
sql/sql_show.cc:
Add TIME_ZONE column to the output of SHOW EVENTS.
mysql-test/r/events_time_zone.result:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/r/events_time_zone.result
mysql-test/t/events_time_zone.test:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/t/events_time_zone.test
2007-03-16 15:31:07 +01:00
|
|
|
|
2007-03-23 21:08:31 +01:00
|
|
|
MYSQL_TIME time;
|
BUG#16420: Events: timestamps become UTC
BUG#26429: SHOW CREATE EVENT is incorrect for an event that
STARTS NOW()
BUG#26431: Impossible to re-create an event from backup if its
STARTS clause is in the past
WL#3698: Events: execution in local time zone
The problem was that local times specified by the user in AT, STARTS
and ENDS of CREATE EVENT/ALTER EVENT statement were converted to UTC,
and the original time zone was forgotten. This way, event scheduler
couldn't honor Daylight Saving Time shifts, and times shown to the
user were also in UTC. Additionally, CREATE EVENT didn't allow times
in the past, thus preventing straightforward event restoration from
old backups.
This patch reworks event scheduler time computations, performing them
in the time zone associated with the event. Also it allows times to
be in the past.
The patch adds time_zone column to mysql.event table.
NOTE: The patch is almost final, but the bug#9953 should be pushed
first.
client/mysqldump.c:
Before every CREATE EVENT, output its time zone.
mysql-test/include/wait_condition.inc:
Add optional $wait_timeout parameter.
mysql-test/lib/init_db.sql:
Add time_zone column.
mysql-test/r/events.result:
Update result.
mysql-test/r/events_bugs.result:
Update result.
mysql-test/r/events_grant.result:
Update result.
mysql-test/r/events_restart_phase1.result:
Update result.
mysql-test/r/events_scheduling.result:
Update result.
mysql-test/r/mysqldump.result:
Update result.
mysql-test/r/ps.result:
Update result.
mysql-test/r/system_mysql_db.result:
Update result.
mysql-test/t/events.test:
Remove STARTS from the result, as it depends on current time.
mysql-test/t/events_bugs.test:
Time in the past is no longer an error.
mysql-test/t/events_restart_phase1.test:
Fill new column 'time_zone' in mysql.event.
mysql-test/t/events_scheduling.test:
Cleanup: disable event scheduler.
scripts/mysql_create_system_tables.sh:
Add new column 'time_zone' to mysql.event.
scripts/mysql_fix_privilege_tables.sql:
Add new column 'time_zone' to mysql.event.
sql/event_data_objects.cc:
The essence of the change is the following:
- for internal times use my_time_t instead of TIME. Assignment and
comparison is done now on plain numbers.
- in init_execute_at(), init_starts(), init_ends() convert given time
to number of seconds since Epoch (aka Unix time, in UTC).
- handle time_zone field loading and storing.
- in get_next_time(), Unix time is converted back to event time zone,
interval is added, and the result is converted to UTC again.
- fix Event_timed::get_create_event() to report STARTS and ENDS.
- before executing the event body we set thread time zone to the
event time zone.
sql/event_data_objects.h:
Add time_zone member to Event_basic class.
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_db_repository.cc:
Add time_zone column handling.
Give a warning and do not create an event if its execution time is in
the past, and ON COMPLETION NOT PRESERVE is set, because such an event
should be dropped by that time. Also, do not allow ALTER EVENT to
set execution time in the past when ON COMPLETION NOT PRESERVE is set.
sql/event_db_repository.h:
Add enum member for new time zone column.
sql/event_queue.cc:
Replace handling of broken down times with simple handling of
my_time_t.
sql/event_queue.h:
Store internal times in my_time_t (number of seconds since Epoch),
rather than in broken down TIME structure.
sql/event_scheduler.cc:
Add TODO comment.
sql/events.cc:
Send time_zone column for SHOW CREATE EVENT.
sql/share/errmsg.txt:
Update error message, and add two more errors.
sql/sql_show.cc:
Add TIME_ZONE column to the output of SHOW EVENTS.
mysql-test/r/events_time_zone.result:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/r/events_time_zone.result
mysql-test/t/events_time_zone.test:
BitKeeper file /home/tomash/src/mysql_ab/mysql-5.1-wl3698/mysql-test/t/events_time_zone.test
2007-03-16 15:31:07 +01:00
|
|
|
my_tz_UTC->gmt_sec_to_TIME(&time, next_activation_at);
|
2007-05-21 10:51:11 +02:00
|
|
|
if (time.year != 1970)
|
|
|
|
printf("Next activation : %04d-%02d-%02d %02d:%02d:%02d\n",
|
|
|
|
time.year, time.month, time.day, time.hour, time.minute, time.second);
|
|
|
|
else
|
|
|
|
printf("Next activation : never");
|
2006-09-12 12:26:12 +02:00
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
2006-07-10 13:44:43 +02:00
|
|
|
}
|