2004-10-23 11:32:52 +04:00
|
|
|
#ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_H
|
|
|
|
#define INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_H
|
|
|
|
/* Copyright (C) 2004 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
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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 <my_global.h>
|
2006-05-18 18:57:50 +04:00
|
|
|
#include <m_string.h>
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
#include "instance_options.h"
|
2006-05-18 18:57:50 +04:00
|
|
|
#include "priv.h"
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2005-09-23 21:28:56 +03:00
|
|
|
#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE)
|
2004-10-23 11:32:52 +04:00
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
2005-01-25 13:54:56 +03:00
|
|
|
class Instance_map;
|
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Instance_name -- the class represents instance name -- a string of length
|
|
|
|
less than MAX_INSTANCE_NAME_SIZE.
|
|
|
|
|
|
|
|
Generally, this is just a string with self-memory-management and should be
|
|
|
|
eliminated in the future.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Instance_name
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Instance_name(const LEX_STRING *name);
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline const LEX_STRING *get_str() const
|
|
|
|
{
|
|
|
|
return &str;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const char *get_c_str() const
|
|
|
|
{
|
|
|
|
return str.str;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint get_length() const
|
|
|
|
{
|
|
|
|
return str.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
LEX_STRING str;
|
|
|
|
char str_buffer[MAX_INSTANCE_NAME_SIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
class Instance
|
|
|
|
{
|
2006-05-18 18:57:50 +04:00
|
|
|
public:
|
|
|
|
/*
|
|
|
|
The following two constants defines name of the default mysqld-instance
|
|
|
|
("mysqld").
|
|
|
|
*/
|
|
|
|
static const LEX_STRING DFLT_INSTANCE_NAME;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/*
|
|
|
|
The operation is intended to check whether string is a well-formed
|
|
|
|
instance name or not.
|
|
|
|
*/
|
|
|
|
static bool is_name_valid(const LEX_STRING *name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
The operation is intended to check if the given instance name is
|
|
|
|
mysqld-compatible or not.
|
|
|
|
*/
|
|
|
|
static bool is_mysqld_compatible_name(const LEX_STRING *name);
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
public:
|
2005-02-11 14:21:59 +03:00
|
|
|
Instance();
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
~Instance();
|
2006-05-18 18:57:50 +04:00
|
|
|
int init(const LEX_STRING *name_arg);
|
2005-02-15 04:38:33 +03:00
|
|
|
int complete_initialization(Instance_map *instance_map_arg,
|
2006-05-18 18:57:50 +04:00
|
|
|
const char *mysqld_path);
|
2004-10-23 11:32:52 +04:00
|
|
|
|
|
|
|
bool is_running();
|
|
|
|
int start();
|
|
|
|
int stop();
|
2005-02-11 14:21:59 +03:00
|
|
|
/* send a signal to the instance */
|
|
|
|
void kill_instance(int signo);
|
2006-05-18 18:57:50 +04:00
|
|
|
bool is_crashed();
|
2005-08-19 17:19:12 +04:00
|
|
|
void set_crash_flag_n_wake_all();
|
2005-08-22 18:59:47 +04:00
|
|
|
Instance_map *get_map();
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
/*
|
|
|
|
The operation is intended to check if the instance is mysqld-compatible
|
|
|
|
or not.
|
|
|
|
*/
|
|
|
|
inline bool is_mysqld_compatible() const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
The operation is intended to check if the instance is configured properly
|
|
|
|
or not. Misconfigured instances are not managed.
|
|
|
|
*/
|
|
|
|
inline bool is_configured() const;
|
|
|
|
|
|
|
|
inline const LEX_STRING *get_name() const;
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
public:
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
enum { DEFAULT_SHUTDOWN_DELAY= 35 };
|
2004-10-23 11:32:52 +04:00
|
|
|
Instance_options options;
|
|
|
|
|
|
|
|
private:
|
2006-05-18 18:57:50 +04:00
|
|
|
/* This attributes is a flag, specifies if the instance has been crashed. */
|
|
|
|
bool crashed;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This attribute specifies if the instance is configured properly or not.
|
|
|
|
Misconfigured instances are not managed.
|
|
|
|
*/
|
|
|
|
bool configured;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This attribute specifies whether the instance is mysqld-compatible or not.
|
|
|
|
Mysqld-compatible instances can contain only mysqld-specific options.
|
|
|
|
At the moment an instance is mysqld-compatible if its name is "mysqld".
|
|
|
|
|
|
|
|
The idea is that [mysqld] section should contain only mysqld-specific
|
|
|
|
options (no Instance Manager-specific options) to be readable by mysqld
|
|
|
|
program.
|
|
|
|
*/
|
|
|
|
bool mysqld_compatible;
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
/*
|
|
|
|
Mutex protecting the instance. Currently we use it to avoid the
|
|
|
|
double start of the instance. This happens when the instance is starting
|
|
|
|
and we issue the start command once more.
|
|
|
|
*/
|
|
|
|
pthread_mutex_t LOCK_instance;
|
2005-02-27 18:41:34 +03:00
|
|
|
/*
|
|
|
|
This condition variable is used to wake threads waiting for instance to
|
|
|
|
stop in Instance::stop()
|
|
|
|
*/
|
|
|
|
pthread_cond_t COND_instance_stopped;
|
2005-01-25 13:54:56 +03:00
|
|
|
Instance_map *instance_map;
|
2005-07-20 10:55:40 -05:00
|
|
|
|
|
|
|
void remove_pid();
|
2004-10-23 11:32:52 +04:00
|
|
|
};
|
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
|
|
|
|
inline bool Instance::is_mysqld_compatible() const
|
|
|
|
{
|
|
|
|
return mysqld_compatible;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Instance::is_configured() const
|
|
|
|
{
|
|
|
|
return configured;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline const LEX_STRING *Instance::get_name() const
|
|
|
|
{
|
|
|
|
return &options.instance_name;
|
|
|
|
}
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_H */
|