~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to server-tools/instance-manager/instance.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_H
 
2
#define INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_H
 
3
/* Copyright (C) 2004 MySQL AB
 
4
 
 
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.
 
8
 
 
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.
 
13
 
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
17
 
 
18
#include <my_global.h>
 
19
#include <m_string.h>
 
20
 
 
21
#include "instance_options.h"
 
22
#include "priv.h"
 
23
 
 
24
#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE)
 
25
#pragma interface
 
26
#endif
 
27
 
 
28
class Instance_map;
 
29
class Thread_registry;
 
30
 
 
31
 
 
32
/**
 
33
  Instance_name -- the class represents instance name -- a string of length
 
34
  less than MAX_INSTANCE_NAME_SIZE.
 
35
 
 
36
  Generally, this is just a string with self-memory-management and should be
 
37
  eliminated in the future.
 
38
*/
 
39
 
 
40
class Instance_name
 
41
{
 
42
public:
 
43
  Instance_name(const LEX_STRING *name);
 
44
 
 
45
public:
 
46
  inline const LEX_STRING *get_str() const
 
47
  {
 
48
    return &str;
 
49
  }
 
50
 
 
51
  inline const char *get_c_str() const
 
52
  {
 
53
    return str.str;
 
54
  }
 
55
 
 
56
  inline uint get_length() const
 
57
  {
 
58
    return str.length;
 
59
  }
 
60
 
 
61
private:
 
62
  LEX_STRING str;
 
63
  char str_buffer[MAX_INSTANCE_NAME_SIZE];
 
64
};
 
65
 
 
66
 
 
67
class Instance
 
68
{
 
69
public:
 
70
  /* States of an instance. */
 
71
  enum enum_instance_state
 
72
  {
 
73
    STOPPED,
 
74
    NOT_STARTED,
 
75
    STARTING,
 
76
    STARTED,
 
77
    JUST_CRASHED,
 
78
    CRASHED,
 
79
    CRASHED_AND_ABANDONED,
 
80
    STOPPING
 
81
  };
 
82
 
 
83
public:
 
84
  /**
 
85
    The constant defines name of the default mysqld-instance ("mysqld").
 
86
  */
 
87
  static const LEX_STRING DFLT_INSTANCE_NAME;
 
88
 
 
89
public:
 
90
  static bool is_name_valid(const LEX_STRING *name);
 
91
  static bool is_mysqld_compatible_name(const LEX_STRING *name);
 
92
 
 
93
public:
 
94
  Instance();
 
95
  ~Instance();
 
96
 
 
97
  bool init(const LEX_STRING *name_arg);
 
98
  bool complete_initialization();
 
99
 
 
100
public:
 
101
  bool is_active();
 
102
 
 
103
  bool is_mysqld_running();
 
104
 
 
105
  bool start_mysqld();
 
106
  bool stop_mysqld();
 
107
  bool kill_mysqld(int signo);
 
108
 
 
109
  void lock();
 
110
  void unlock();
 
111
 
 
112
  const char *get_state_name();
 
113
 
 
114
  void reset_stat();
 
115
 
 
116
public:
 
117
  /**
 
118
    The operation is intended to check if the instance is mysqld-compatible
 
119
    or not.
 
120
  */
 
121
  inline bool is_mysqld_compatible() const;
 
122
 
 
123
  /**
 
124
    The operation is intended to check if the instance is configured properly
 
125
    or not. Misconfigured instances are not managed.
 
126
  */
 
127
  inline bool is_configured() const;
 
128
 
 
129
  /**
 
130
    The operation returns TRUE if the instance is guarded and FALSE otherwise.
 
131
  */
 
132
  inline bool is_guarded() const;
 
133
 
 
134
  /**
 
135
    The operation returns name of the instance.
 
136
  */
 
137
  inline const LEX_STRING *get_name() const;
 
138
 
 
139
  /**
 
140
    The operation returns the current state of the instance.
 
141
 
 
142
    NOTE: At the moment should be used only for guarded instances.
 
143
  */
 
144
  inline enum_instance_state get_state() const;
 
145
 
 
146
  /**
 
147
    The operation changes the state of the instance.
 
148
 
 
149
    NOTE: At the moment should be used only for guarded instances.
 
150
    TODO: Make private.
 
151
  */
 
152
  inline void set_state(enum_instance_state new_state);
 
153
 
 
154
  /**
 
155
    The operation returns crashed flag.
 
156
  */
 
157
  inline bool is_crashed();
 
158
 
 
159
public:
 
160
  /**
 
161
    This attributes contains instance options.
 
162
 
 
163
    TODO: Make private.
 
164
  */
 
165
  Instance_options options;
 
166
 
 
167
private:
 
168
  /**
 
169
    monitoring_thread_active is TRUE if there is a thread that monitors the
 
170
    corresponding mysqld-process.
 
171
  */
 
172
  bool monitoring_thread_active;
 
173
 
 
174
  /**
 
175
    crashed is TRUE when corresponding mysqld-process has been died after
 
176
    start.
 
177
  */
 
178
  bool crashed;
 
179
 
 
180
  /**
 
181
    configured is TRUE when the instance is configured and FALSE otherwise.
 
182
    Misconfigured instances are not managed.
 
183
  */
 
184
  bool configured;
 
185
 
 
186
  /*
 
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".
 
191
 
 
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.
 
195
  */
 
196
  bool mysqld_compatible;
 
197
 
 
198
  /*
 
199
    Mutex protecting the instance.
 
200
  */
 
201
  pthread_mutex_t LOCK_instance;
 
202
 
 
203
private:
 
204
  /* Guarded-instance attributes. */
 
205
 
 
206
  /* state of an instance (i.e. STARTED, CRASHED, etc.) */
 
207
  enum_instance_state state;
 
208
 
 
209
public:
 
210
  /* the amount of attemts to restart instance (cleaned up at success) */
 
211
  int restart_counter;
 
212
 
 
213
  /* triggered at a crash */
 
214
  time_t crash_moment;
 
215
 
 
216
  /* General time field. Used to provide timeouts (at shutdown and restart) */
 
217
  time_t last_checked;
 
218
 
 
219
private:
 
220
  static const char *get_instance_state_name(enum_instance_state state);
 
221
 
 
222
private:
 
223
  void remove_pid();
 
224
 
 
225
  bool wait_for_stop();
 
226
 
 
227
private:
 
228
  friend class Instance_monitor;
 
229
};
 
230
 
 
231
 
 
232
inline bool Instance::is_mysqld_compatible() const
 
233
{
 
234
  return mysqld_compatible;
 
235
}
 
236
 
 
237
 
 
238
inline bool Instance::is_configured() const
 
239
{
 
240
  return configured;
 
241
}
 
242
 
 
243
 
 
244
inline bool Instance::is_guarded() const
 
245
{
 
246
  return !options.nonguarded;
 
247
}
 
248
 
 
249
 
 
250
inline const LEX_STRING *Instance::get_name() const
 
251
{
 
252
  return &options.instance_name;
 
253
}
 
254
 
 
255
 
 
256
inline Instance::enum_instance_state Instance::get_state() const
 
257
{
 
258
  return state;
 
259
}
 
260
 
 
261
 
 
262
inline void Instance::set_state(enum_instance_state new_state)
 
263
{
 
264
  state= new_state;
 
265
}
 
266
 
 
267
 
 
268
inline bool Instance::is_crashed()
 
269
{
 
270
  return crashed;
 
271
}
 
272
 
 
273
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_H */