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-13 10:59:58 +02:00
|
|
|
struct event_queue_param
|
|
|
|
{
|
|
|
|
THD *thd;
|
|
|
|
Event_queue *queue;
|
|
|
|
pthread_mutex_t LOCK_loaded;
|
|
|
|
pthread_cond_t COND_loaded;
|
2006-07-13 16:24:55 +02:00
|
|
|
bool loading_finished;
|
2006-07-13 10:59:58 +02:00
|
|
|
};
|
|
|
|
|
2006-07-03 11:20:08 +02:00
|
|
|
|
|
|
|
/*
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
/*
|
|
|
|
Note that no overflow is possible here because both values are
|
|
|
|
non-negative, and subtraction is done in the signed my_time_t
|
|
|
|
type.
|
|
|
|
*/
|
|
|
|
return (((Event_queue_element *)a)->execute_at
|
|
|
|
- ((Event_queue_element *)b)->execute_at);
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Constructor of class Event_queue.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::Event_queue()
|
|
|
|
*/
|
|
|
|
|
|
|
|
Event_queue::Event_queue()
|
2006-08-17 14:22:59 +02:00
|
|
|
:mutex_last_unlocked_at_line(0), mutex_last_locked_at_line(0),
|
|
|
|
mutex_last_attempted_lock_at_line(0),
|
|
|
|
mutex_queue_data_locked(FALSE), 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= "";
|
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-07-03 11:20:08 +02:00
|
|
|
}
|
|
|
|
|
2006-07-10 13:44:43 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Inits mutexes.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::init_mutexes()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
Event_queue::init_mutexes()
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Destroys mutexes.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::deinit_mutexes()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
Event_queue::deinit_mutexes()
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
sql_print_error("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
|
|
|
}
|
|
|
|
|
|
|
|
if (sizeof(my_time_t) != sizeof(time_t))
|
|
|
|
{
|
|
|
|
sql_print_error("SCHEDULER: sizeof(my_time_t) != sizeof(time_t) ."
|
2006-08-17 14:22:59 +02:00
|
|
|
"The scheduler may not work correctly. Stopping");
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-03 11:20:08 +02:00
|
|
|
/*
|
2006-07-11 18:28:15 +02:00
|
|
|
Adds an event to the queue.
|
2006-07-03 11:20:08 +02:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Event_queue::create_event()
|
2006-07-11 18:28:15 +02:00
|
|
|
dbname The schema of the new event
|
|
|
|
name The name of the new event
|
2006-07-03 11:20:08 +02:00
|
|
|
*/
|
|
|
|
|
2007-01-29 18:46:29 +01:00
|
|
|
void
|
|
|
|
Event_queue::create_event(THD *thd, Event_queue_element *new_element)
|
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
|
|
|
|
2007-01-29 18:46:29 +01:00
|
|
|
if (new_element->status == Event_queue_element::DISABLED)
|
2006-07-11 18:28:15 +02:00
|
|
|
delete new_element;
|
2006-07-10 13:44:43 +02:00
|
|
|
else
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2006-07-11 18:28:15 +02:00
|
|
|
new_element->compute_next_execution_time();
|
2007-03-02 00:39:00 +01:00
|
|
|
DBUG_PRINT("info", ("new event in the queue: 0x%lx", (long) new_element));
|
2006-07-10 13:44:43 +02:00
|
|
|
|
|
|
|
LOCK_QUEUE_DATA();
|
2006-07-11 18:28:15 +02:00
|
|
|
queue_insert_safe(&queue, (byte *) new_element);
|
2006-07-17 16:52:45 +02:00
|
|
|
dbug_dump_queue(thd->query_start());
|
2006-08-31 17:18:39 +02:00
|
|
|
pthread_cond_broadcast(&COND_queue_state);
|
2006-07-10 13:44:43 +02:00
|
|
|
UNLOCK_QUEUE_DATA();
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
2007-01-29 18:46:29 +01:00
|
|
|
DBUG_VOID_RETURN;
|
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-01-29 18:46:29 +01:00
|
|
|
if (new_element->status == Event_queue_element::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);
|
2006-08-31 17:18:39 +02: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();
|
2006-07-10 13:44:43 +02: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
|
|
|
|
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
/*
|
2006-08-31 17:18:39 +02:00
|
|
|
We don't call pthread_cond_broadcast(&COND_queue_state);
|
|
|
|
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));
|
2006-07-13 10:59:58 +02:00
|
|
|
sql_print_information("SCHEDULER: Purging 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;
|
|
|
|
top_time.tv_sec= next_activation_at;
|
|
|
|
top_time.tv_nsec= 0;
|
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"));
|
2006-07-17 16:52:45 +02:00
|
|
|
sql_print_information("SCHEDULER: Last execution of %s.%s. %s",
|
|
|
|
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
|
|
|
|
|
|
|
TIME time;
|
|
|
|
my_tz_UTC->gmt_sec_to_TIME(&time, next_activation_at);
|
2006-09-12 12:26:12 +02:00
|
|
|
printf("Next activation : %04d-%02d-%02d %02d:%02d:%02d\n",
|
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
|
|
|
time.year, time.month, time.day, time.hour, time.minute, time.second);
|
2006-09-12 12:26:12 +02:00
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
2006-07-10 13:44:43 +02:00
|
|
|
}
|