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
|
|
|
|
2007-08-15 17:08:44 +02:00
|
|
|
/**
|
|
|
|
@addtogroup Event_Scheduler
|
|
|
|
@{
|
|
|
|
*/
|
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-08-13 15:11:25 +02:00
|
|
|
extern "C" int event_queue_element_compare_q(void *, uchar *, uchar *);
|
|
|
|
|
|
|
|
int event_queue_element_compare_q(void *vptr, uchar* a, uchar *b)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2008-02-22 16:18:31 +01:00
|
|
|
Event_queue_element *left = (Event_queue_element *)a;
|
|
|
|
Event_queue_element *right = (Event_queue_element *)b;
|
|
|
|
my_time_t lhs = left->execute_at;
|
|
|
|
my_time_t rhs = right->execute_at;
|
|
|
|
|
2008-05-09 09:43:02 +02:00
|
|
|
if (left->status == Event_parse_data::DISABLED)
|
|
|
|
return right->status != Event_parse_data::DISABLED;
|
2008-02-22 16:18:31 +01:00
|
|
|
|
2008-05-09 09:43:02 +02:00
|
|
|
if (right->status == Event_parse_data::DISABLED)
|
2008-02-22 16:18:31 +01:00
|
|
|
return 1;
|
2007-03-16 18:50:37 +01:00
|
|
|
|
|
|
|
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),
|
2007-05-23 00:19:36 +02:00
|
|
|
mutex_last_attempted_lock_at_line(0),
|
2007-05-21 10:51:11 +02:00
|
|
|
mutex_last_locked_in_func("n/a"),
|
|
|
|
mutex_last_unlocked_in_func("n/a"),
|
|
|
|
mutex_last_attempted_lock_in_func("n/a"),
|
2007-04-05 13:24:34 +02:00
|
|
|
mutex_queue_data_locked(FALSE),
|
2007-05-23 00:19:36 +02:00
|
|
|
mutex_queue_data_attempting_lock(FALSE),
|
|
|
|
waiting_on_cond(FALSE)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-05 13:24:34 +02:00
|
|
|
Event_queue::~Event_queue()
|
2006-07-10 13:44:43 +02:00
|
|
|
{
|
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
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2007-04-05 13:24:34 +02:00
|
|
|
/* Will do nothing if the event is disabled */
|
|
|
|
new_element->compute_next_execution_time();
|
2008-05-09 09:43:02 +02:00
|
|
|
if (new_element->status != Event_parse_data::ENABLED)
|
2006-07-03 11:20:08 +02:00
|
|
|
{
|
2007-04-05 13:24:34 +02:00
|
|
|
delete new_element;
|
|
|
|
*created= FALSE;
|
|
|
|
DBUG_RETURN(FALSE);
|
2006-07-03 11:20:08 +02:00
|
|
|
}
|
2007-04-05 13:24:34 +02:00
|
|
|
|
|
|
|
DBUG_PRINT("info", ("new event in the queue: 0x%lx", (long) new_element));
|
|
|
|
|
|
|
|
LOCK_QUEUE_DATA();
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
*created= (queue_insert_safe(&queue, (uchar *) new_element) == FALSE);
|
2007-04-05 13:24:34 +02:00
|
|
|
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
|
|
|
|
2008-05-09 09:43:02 +02:00
|
|
|
if ((new_element->status == Event_parse_data::DISABLED) ||
|
|
|
|
(new_element->status == Event_parse_data::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));
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
queue_insert_safe(&queue, (uchar *) 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);
|
2008-02-22 16:18:31 +01:00
|
|
|
/*
|
|
|
|
The disabled elements are moved to the end during the `fix`.
|
|
|
|
Start from the end and remove all of the elements which are
|
|
|
|
disabled. When we find the first non-disabled one we break, as we
|
|
|
|
have removed all. The queue has been ordered in a way the disabled
|
|
|
|
events are at the end.
|
|
|
|
*/
|
|
|
|
for (i= queue.elements; i > 0; i--)
|
|
|
|
{
|
|
|
|
Event_queue_element *element = (Event_queue_element*)queue_element(&queue, i - 1);
|
2008-05-09 09:43:02 +02:00
|
|
|
if (element->status != Event_parse_data::DISABLED)
|
2008-02-22 16:18:31 +01:00
|
|
|
break;
|
|
|
|
/*
|
|
|
|
This won't cause queue re-order, because we remove
|
|
|
|
always the last element.
|
|
|
|
*/
|
|
|
|
queue_remove(&queue, i - 1);
|
|
|
|
delete element;
|
|
|
|
}
|
2006-07-03 11:20:08 +02:00
|
|
|
UNLOCK_QUEUE_DATA();
|
|
|
|
|
2008-02-22 16:18:31 +01:00
|
|
|
/*
|
|
|
|
XXX: The events are dropped only from memory and not from disk
|
|
|
|
even if `drop_list[j]->dropped` is TRUE. There will be still on the
|
|
|
|
disk till next server restart.
|
|
|
|
Please add code here to do it.
|
|
|
|
*/
|
|
|
|
|
2006-07-03 11:20:08 +02:00
|
|
|
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",
|
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 */
|
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
|
|
|
|
2007-07-30 10:33:50 +02:00
|
|
|
thd->set_current_time(); /* Get current time */
|
2006-12-18 12:00:35 +01:00
|
|
|
|
|
|
|
next_activation_at= top->execute_at;
|
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
|
|
|
*/
|
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())
|
2008-05-09 09:43:02 +02:00
|
|
|
top->status= Event_parse_data::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);
|
2008-05-09 09:43:02 +02:00
|
|
|
if (top->status == Event_parse_data::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");
|
2007-03-16 15:31:07 +01:00
|
|
|
|
2007-03-23 21:08:31 +01:00
|
|
|
MYSQL_TIME time;
|
2007-07-25 09:43:49 +02:00
|
|
|
my_tz_OFFSET0->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
|
|
|
}
|
2007-08-15 17:08:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
@} (End of group Event_Scheduler)
|
|
|
|
*/
|