mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / server-tools / instance-manager / instance.h
blobfef3e6918b06fec8f9ec3bd7043b70ce67d7190d
1 #ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_H
2 #define INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_H
3 /* Copyright (c) 2004-2007 MySQL AB
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
18 #include <my_global.h>
19 #include <m_string.h>
21 #include "instance_options.h"
22 #include "priv.h"
24 #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE)
25 #pragma interface
26 #endif
28 class Instance_map;
29 class Thread_registry;
32 /**
33 Instance_name -- the class represents instance name -- a string of length
34 less than MAX_INSTANCE_NAME_SIZE.
36 Generally, this is just a string with self-memory-management and should be
37 eliminated in the future.
40 class Instance_name
42 public:
43 Instance_name(const LEX_STRING *name);
45 public:
46 inline const LEX_STRING *get_str() const
48 return &str;
51 inline const char *get_c_str() const
53 return str.str;
56 inline uint get_length() const
58 return str.length;
61 private:
62 LEX_STRING str;
63 char str_buffer[MAX_INSTANCE_NAME_SIZE];
67 class Instance
69 public:
70 /* States of an instance. */
71 enum enum_instance_state
73 STOPPED,
74 NOT_STARTED,
75 STARTING,
76 STARTED,
77 JUST_CRASHED,
78 CRASHED,
79 CRASHED_AND_ABANDONED,
80 STOPPING
83 public:
84 /**
85 The constant defines name of the default mysqld-instance ("mysqld").
87 static const LEX_STRING DFLT_INSTANCE_NAME;
89 public:
90 static bool is_name_valid(const LEX_STRING *name);
91 static bool is_mysqld_compatible_name(const LEX_STRING *name);
93 public:
94 Instance();
95 ~Instance();
97 bool init(const LEX_STRING *name_arg);
98 bool complete_initialization();
100 public:
101 bool is_active();
103 bool is_mysqld_running();
105 bool start_mysqld();
106 bool stop_mysqld();
107 bool kill_mysqld(int signo);
109 void lock();
110 void unlock();
112 const char *get_state_name();
114 void reset_stat();
116 public:
118 The operation is intended to check if the instance is mysqld-compatible
119 or not.
121 inline bool is_mysqld_compatible() const;
124 The operation is intended to check if the instance is configured properly
125 or not. Misconfigured instances are not managed.
127 inline bool is_configured() const;
130 The operation returns TRUE if the instance is guarded and FALSE otherwise.
132 inline bool is_guarded() const;
135 The operation returns name of the instance.
137 inline const LEX_STRING *get_name() const;
140 The operation returns the current state of the instance.
142 NOTE: At the moment should be used only for guarded instances.
144 inline enum_instance_state get_state() const;
147 The operation changes the state of the instance.
149 NOTE: At the moment should be used only for guarded instances.
150 TODO: Make private.
152 inline void set_state(enum_instance_state new_state);
155 The operation returns crashed flag.
157 inline bool is_crashed();
159 public:
161 This attributes contains instance options.
163 TODO: Make private.
165 Instance_options options;
167 private:
169 monitoring_thread_active is TRUE if there is a thread that monitors the
170 corresponding mysqld-process.
172 bool monitoring_thread_active;
175 crashed is TRUE when corresponding mysqld-process has been died after
176 start.
178 bool crashed;
181 configured is TRUE when the instance is configured and FALSE otherwise.
182 Misconfigured instances are not managed.
184 bool configured;
187 mysqld_compatible specifies whether the instance is mysqld-compatible
188 or not. Mysqld-compatible instances can contain only mysqld-specific
189 options. At the moment an instance is mysqld-compatible if its name is
190 "mysqld".
192 The idea is that [mysqld] section should contain only mysqld-specific
193 options (no Instance Manager-specific options) to be readable by mysqld
194 program.
196 bool mysqld_compatible;
199 Mutex protecting the instance.
201 pthread_mutex_t LOCK_instance;
203 private:
204 /* Guarded-instance attributes. */
206 /* state of an instance (i.e. STARTED, CRASHED, etc.) */
207 enum_instance_state state;
209 public:
210 /* the amount of attemts to restart instance (cleaned up at success) */
211 int restart_counter;
213 /* triggered at a crash */
214 time_t crash_moment;
216 /* General time field. Used to provide timeouts (at shutdown and restart) */
217 time_t last_checked;
219 private:
220 static const char *get_instance_state_name(enum_instance_state state);
222 private:
223 void remove_pid();
225 bool wait_for_stop();
227 private:
228 friend class Instance_monitor;
232 inline bool Instance::is_mysqld_compatible() const
234 return mysqld_compatible;
238 inline bool Instance::is_configured() const
240 return configured;
244 inline bool Instance::is_guarded() const
246 return !options.nonguarded;
250 inline const LEX_STRING *Instance::get_name() const
252 return &options.instance_name;
256 inline Instance::enum_instance_state Instance::get_state() const
258 return state;
262 inline void Instance::set_state(enum_instance_state new_state)
264 state= new_state;
268 inline bool Instance::is_crashed()
270 return crashed;
273 #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_H */