mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Merge weblab.(none):/home/marcsql/TREE/mysql-5.1-base
into weblab.(none):/home/marcsql/TREE/mysql-5.1-merge mysql-test/r/sp.result: Auto merged server-tools/instance-manager/commands.cc: Auto merged server-tools/instance-manager/commands.h: Auto merged server-tools/instance-manager/guardian.cc: Auto merged server-tools/instance-manager/guardian.h: Auto merged server-tools/instance-manager/instance.cc: Auto merged server-tools/instance-manager/instance.h: Auto merged server-tools/instance-manager/instance_map.cc: Auto merged server-tools/instance-manager/instance_map.h: Auto merged server-tools/instance-manager/instance_options.h: Auto merged server-tools/instance-manager/listener.cc: Auto merged server-tools/instance-manager/manager.cc: Auto merged server-tools/instance-manager/manager.h: Auto merged server-tools/instance-manager/user_map.cc: Auto merged sql/event_data_objects.cc: Auto merged sql/event_queue.cc: Auto merged sql/handler.cc: Auto merged sql/lock.cc: Auto merged sql/set_var.cc: Auto merged sql/set_var.h: Auto merged sql/sp_head.cc: Auto merged sql/sp_head.h: Auto merged sql/sql_class.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_prepare.cc: Auto merged sql/sql_yacc.yy: Auto merged storage/csv/ha_tina.cc: Auto merged tests/mysql_client_test.c: Auto merged
This commit is contained in:
@ -16,10 +16,12 @@
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
|
||||
#include "thread_registry.h"
|
||||
#include <my_global.h>
|
||||
#include <my_sys.h>
|
||||
#include <my_list.h>
|
||||
|
||||
#include "thread_registry.h"
|
||||
|
||||
#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE)
|
||||
#pragma interface
|
||||
#endif
|
||||
@ -27,7 +29,6 @@
|
||||
class Instance;
|
||||
class Instance_map;
|
||||
class Thread_registry;
|
||||
struct GUARD_NODE;
|
||||
|
||||
/**
|
||||
The guardian thread is responsible for monitoring and restarting of guarded
|
||||
@ -37,97 +38,73 @@ struct GUARD_NODE;
|
||||
class Guardian: public Thread
|
||||
{
|
||||
public:
|
||||
/* states of an instance */
|
||||
enum enum_instance_state { NOT_STARTED= 1, STARTING, STARTED, JUST_CRASHED,
|
||||
CRASHED, CRASHED_AND_ABANDONED, STOPPING };
|
||||
|
||||
/*
|
||||
The Guardian list node structure. Guardian utilizes it to store
|
||||
guarded instances plus some additional info.
|
||||
*/
|
||||
|
||||
struct GUARD_NODE
|
||||
{
|
||||
Instance *instance;
|
||||
/* state of an instance (i.e. STARTED, CRASHED, etc.) */
|
||||
enum_instance_state state;
|
||||
/* the amount of attemts to restart instance (cleaned up at success) */
|
||||
int restart_counter;
|
||||
/* triggered at a crash */
|
||||
time_t crash_moment;
|
||||
/* General time field. Used to provide timeouts (at shutdown and restart) */
|
||||
time_t last_checked;
|
||||
};
|
||||
|
||||
/* Return client state name. */
|
||||
static const char *get_instance_state_name(enum_instance_state state);
|
||||
|
||||
Guardian(Thread_registry *thread_registry_arg,
|
||||
Instance_map *instance_map_arg,
|
||||
uint monitoring_interval_arg);
|
||||
virtual ~Guardian();
|
||||
/* Initialize or refresh the list of guarded instances */
|
||||
int init();
|
||||
/* Request guardian shutdown. Stop instances if needed */
|
||||
Instance_map *instance_map_arg);
|
||||
~Guardian();
|
||||
|
||||
void init();
|
||||
|
||||
public:
|
||||
void request_shutdown();
|
||||
/* Start instance protection */
|
||||
int guard(Instance *instance, bool nolock= FALSE);
|
||||
/* Stop instance protection */
|
||||
int stop_guard(Instance *instance);
|
||||
/* Returns TRUE if guardian thread is stopped */
|
||||
int is_stopped();
|
||||
|
||||
bool is_stopped();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
/*
|
||||
Return an internal list node for the given instance if the instance is
|
||||
managed by Guardian. Otherwise, return NULL.
|
||||
void ping();
|
||||
|
||||
MT-NOTE: must be called under acquired lock.
|
||||
*/
|
||||
LIST *find_instance_node(Instance *instance);
|
||||
|
||||
/* The operation is used to check if the instance is active or not. */
|
||||
bool is_active(Instance *instance);
|
||||
|
||||
/*
|
||||
Return state of the given instance list node. The pointer must specify
|
||||
a valid list node.
|
||||
*/
|
||||
inline enum_instance_state get_instance_state(LIST *instance_node);
|
||||
protected:
|
||||
/* Main funtion of the thread */
|
||||
virtual void run();
|
||||
|
||||
public:
|
||||
private:
|
||||
void stop_instances();
|
||||
|
||||
void process_instance(Instance *instance);
|
||||
|
||||
private:
|
||||
/*
|
||||
LOCK_guardian protectes the members in this section:
|
||||
- shutdown_requested;
|
||||
- stopped;
|
||||
|
||||
Also, it is used for COND_guardian.
|
||||
*/
|
||||
pthread_mutex_t LOCK_guardian;
|
||||
|
||||
/*
|
||||
Guardian's main loop waits on this condition. So, it should be signalled
|
||||
each time, when instance state has been changed and we want Guardian to
|
||||
wake up.
|
||||
|
||||
TODO: Change this to having data-scoped conditions, i.e. conditions,
|
||||
which indicate that some data has been changed.
|
||||
*/
|
||||
pthread_cond_t COND_guardian;
|
||||
|
||||
private:
|
||||
/* Prepares Guardian shutdown. Stops instances is needed */
|
||||
int stop_instances();
|
||||
/* check instance state and act accordingly */
|
||||
void process_instance(Instance *instance, GUARD_NODE *current_node,
|
||||
LIST **guarded_instances, LIST *elem);
|
||||
/*
|
||||
This variable is set to TRUE, when Manager thread is shutting down.
|
||||
The flag is used by Guardian thread to understand that it's time to
|
||||
finish.
|
||||
*/
|
||||
bool shutdown_requested;
|
||||
|
||||
int stopped;
|
||||
/*
|
||||
This flag is set to TRUE on shutdown by Guardian thread, when all guarded
|
||||
mysqlds are stopped.
|
||||
|
||||
The flag is used in the Manager thread to wait for Guardian to stop all
|
||||
mysqlds.
|
||||
*/
|
||||
bool stopped;
|
||||
|
||||
private:
|
||||
pthread_mutex_t LOCK_guardian;
|
||||
Thread_info thread_info;
|
||||
int monitoring_interval;
|
||||
Thread_registry *thread_registry;
|
||||
Instance_map *instance_map;
|
||||
LIST *guarded_instances;
|
||||
MEM_ROOT alloc;
|
||||
/* this variable is set to TRUE when we want to stop Guardian thread */
|
||||
bool shutdown_requested;
|
||||
|
||||
private:
|
||||
Guardian(const Guardian &);
|
||||
Guardian&operator =(const Guardian &);
|
||||
};
|
||||
|
||||
|
||||
inline Guardian::enum_instance_state
|
||||
Guardian::get_instance_state(LIST *instance_node)
|
||||
{
|
||||
return ((GUARD_NODE *) instance_node->data)->state;
|
||||
}
|
||||
|
||||
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_GUARDIAN_H */
|
||||
|
Reference in New Issue
Block a user