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

« back to all changes in this revision

Viewing changes to storage/ndb/include/kernel/NodeState.hpp

  • 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
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef NODE_STATE_HPP
 
17
#define NODE_STATE_HPP
 
18
 
 
19
#include <NdbOut.hpp>
 
20
#include <NodeBitmask.hpp>
 
21
 
 
22
class NodeState {
 
23
public:
 
24
  enum StartLevel {
 
25
    /**
 
26
     * SL_NOTHING 
 
27
     *   Nothing is started
 
28
     */
 
29
    SL_NOTHING    = 0,
 
30
 
 
31
    /**
 
32
     * SL_CMVMI
 
33
     *   CMVMI is started
 
34
     *   Listening to management server
 
35
     *   Qmgr knows nothing...
 
36
     */
 
37
    SL_CMVMI = 1,
 
38
    
 
39
    /**
 
40
     * SL_STARTING
 
41
     *   All blocks are starting
 
42
     *   Initial or restart
 
43
     *   During this phase is <b>startPhase</b> valid
 
44
     */
 
45
    SL_STARTING = 2,
 
46
    
 
47
    /**
 
48
     * The database is started open for connections
 
49
     */
 
50
    SL_STARTED = 3,
 
51
 
 
52
    SL_SINGLEUSER = 4,
 
53
 
 
54
    /**
 
55
     * SL_STOPPING_1 - Inform API
 
56
     *   API is informed not to start transactions on node
 
57
     *   The database is about to close
 
58
     *
 
59
     *   New TcSeize(s) are refused (TcSeizeRef)
 
60
     */
 
61
    SL_STOPPING_1 = 5,
 
62
    
 
63
    /**
 
64
     * SL_STOPPING_2 - Close TC
 
65
     *   New transactions(TC) are refused
 
66
     */
 
67
    SL_STOPPING_2 = 6,
 
68
 
 
69
 
 
70
 
 
71
    
 
72
    /**
 
73
     * SL_STOPPING_3 - Wait for reads in LQH
 
74
     *   No transactions are running in TC
 
75
     *   New scans(s) and read(s) are refused in LQH
 
76
     *   NS: The node is not Primary for any fragment
 
77
     *   NS: No node is allow to start
 
78
     */
 
79
    SL_STOPPING_3 = 7,
 
80
    
 
81
    /**
 
82
     * SL_STOPPING_4 - Close LQH
 
83
     *   Node is out of DIGETNODES
 
84
     *   Insert/Update/Delete can still be running in LQH
 
85
     *   GCP is refused
 
86
     *   Node is not startable w.o Node Recovery
 
87
     */
 
88
    SL_STOPPING_4 = 8
 
89
  };
 
90
 
 
91
  enum StartType {
 
92
    ST_INITIAL_START = 0,
 
93
    ST_SYSTEM_RESTART = 1,
 
94
    ST_NODE_RESTART = 2,
 
95
    ST_INITIAL_NODE_RESTART = 3,
 
96
    ST_ILLEGAL_TYPE = 4
 
97
  };
 
98
  
 
99
  /**
 
100
   * Length in 32-bit words
 
101
   */
 
102
  STATIC_CONST( DataLength = 8 + NdbNodeBitmask::Size );
 
103
  
 
104
  /**
 
105
   * Constructor(s)
 
106
   */
 
107
  NodeState();
 
108
  NodeState(StartLevel);
 
109
  NodeState(StartLevel, bool systemShutdown);
 
110
  NodeState(StartLevel, Uint32 startPhase, StartType);
 
111
  void init();
 
112
 
 
113
  /**
 
114
   * Current start level
 
115
   */
 
116
  Uint32 startLevel;
 
117
 
 
118
  /**
 
119
   * Node group 
 
120
   */
 
121
  Uint32 nodeGroup;  // valid when startLevel == SL_STARTING
 
122
 
 
123
  /**
 
124
   * Dynamic id
 
125
   */ 
 
126
  union {
 
127
    Uint32 dynamicId;    // valid when startLevel == SL_STARTING to API
 
128
    Uint32 masterNodeId; // When from cntr
 
129
  };
 
130
    
 
131
  /**
 
132
   * 
 
133
   */
 
134
  union {
 
135
    struct {
 
136
      Uint32 startPhase;     // valid when startLevel == SL_STARTING
 
137
      Uint32 restartType;    // valid when startLevel == SL_STARTING
 
138
    } starting;
 
139
    struct {
 
140
      Uint32 systemShutdown; // valid when startLevel == SL_STOPPING_{X}
 
141
      Uint32 timeout;
 
142
      Uint32 alarmTime;
 
143
    } stopping;
 
144
 
 
145
    
 
146
  };
 
147
  Uint32 singleUserMode;
 
148
  Uint32 singleUserApi;          //the single user node
 
149
 
 
150
  BitmaskPOD<NdbNodeBitmask::Size> m_connected_nodes;
 
151
 
 
152
  void setDynamicId(Uint32 dynamic);
 
153
  void setNodeGroup(Uint32 group);
 
154
  void setSingleUser(Uint32 s);
 
155
  void setSingleUserApi(Uint32 n);
 
156
  
 
157
 
 
158
  /**
 
159
   * Is a node restart in progress (ordinary or initial)
 
160
   */
 
161
  bool getNodeRestartInProgress() const;
 
162
 
 
163
  /**
 
164
   * Is a system restart ongoing
 
165
   */
 
166
  bool getSystemRestartInProgress() const;
 
167
 
 
168
  /**
 
169
   * Is in single user mode?
 
170
   */
 
171
  bool getSingleUserMode() const;
 
172
 
 
173
  /**
 
174
   * Is in single user mode
 
175
   */
 
176
  Uint32 getSingleUserApi() const;
 
177
 
 
178
  friend NdbOut & operator<<(NdbOut&, const NodeState&); 
 
179
};
 
180
 
 
181
inline
 
182
NodeState::NodeState(){
 
183
  init();
 
184
}
 
185
 
 
186
inline
 
187
void
 
188
NodeState::init(){
 
189
  startLevel = SL_CMVMI;
 
190
  nodeGroup = 0xFFFFFFFF;
 
191
  dynamicId = 0xFFFFFFFF;
 
192
  singleUserMode = 0;
 
193
  singleUserApi = 0xFFFFFFFF;
 
194
  m_connected_nodes.clear();
 
195
}
 
196
 
 
197
inline
 
198
NodeState::NodeState(StartLevel sl){
 
199
  init();
 
200
  startLevel = sl;
 
201
  singleUserMode = 0;
 
202
  singleUserApi = 0xFFFFFFFF;
 
203
}
 
204
 
 
205
inline
 
206
NodeState::NodeState(StartLevel sl, Uint32 sp, StartType typeOfStart){
 
207
  init();
 
208
  startLevel = sl;
 
209
  starting.startPhase = sp;
 
210
  starting.restartType = typeOfStart;
 
211
  singleUserMode = 0;
 
212
  singleUserApi = 0xFFFFFFFF;
 
213
}
 
214
 
 
215
inline
 
216
NodeState::NodeState(StartLevel sl, bool sys){
 
217
  init();
 
218
  startLevel = sl;
 
219
  stopping.systemShutdown = sys;
 
220
  singleUserMode = 0;
 
221
  singleUserApi = 0xFFFFFFFF;
 
222
}
 
223
 
 
224
inline
 
225
void NodeState::setDynamicId(Uint32 dynamic){
 
226
  dynamicId = dynamic;
 
227
}
 
228
  
 
229
inline
 
230
void NodeState::setNodeGroup(Uint32 group){
 
231
  nodeGroup = group;
 
232
}
 
233
 
 
234
inline 
 
235
void NodeState::setSingleUser(Uint32 s) {
 
236
  singleUserMode = s;
 
237
}
 
238
 
 
239
inline 
 
240
void NodeState::setSingleUserApi(Uint32 n) {
 
241
  singleUserApi = n;
 
242
}
 
243
inline 
 
244
bool NodeState::getNodeRestartInProgress() const {
 
245
  return startLevel == SL_STARTING && 
 
246
    (starting.restartType == ST_NODE_RESTART || 
 
247
     starting.restartType == ST_INITIAL_NODE_RESTART);
 
248
}
 
249
 
 
250
inline 
 
251
bool NodeState::getSingleUserMode() const {
 
252
  return singleUserMode;
 
253
}
 
254
 
 
255
inline 
 
256
Uint32 NodeState::getSingleUserApi() const {
 
257
  return singleUserApi;
 
258
}
 
259
 
 
260
inline 
 
261
bool NodeState::getSystemRestartInProgress() const {
 
262
  return startLevel == SL_STARTING && starting.restartType == ST_SYSTEM_RESTART;
 
263
}
 
264
 
 
265
inline
 
266
NdbOut &
 
267
operator<<(NdbOut& ndbout, const NodeState & state){
 
268
  ndbout << "[NodeState: startLevel: ";
 
269
  switch(state.startLevel){
 
270
  case NodeState::SL_NOTHING:
 
271
    ndbout << "<NOTHING> ]";
 
272
    break;
 
273
  case NodeState::SL_CMVMI:
 
274
    ndbout << "<CMVMI> ]";
 
275
    break;
 
276
  case NodeState::SL_STARTING:
 
277
    ndbout << "<STARTING type: ";
 
278
    switch(state.starting.restartType){
 
279
    case NodeState::ST_INITIAL_START:
 
280
      ndbout << " INITIAL START";
 
281
      break;
 
282
    case NodeState::ST_SYSTEM_RESTART:
 
283
      ndbout << " SYSTEM RESTART ";
 
284
      break;
 
285
    case NodeState::ST_NODE_RESTART:
 
286
      ndbout << " NODE RESTART ";
 
287
      break;
 
288
    case NodeState::ST_INITIAL_NODE_RESTART:
 
289
      ndbout << " INITIAL NODE RESTART ";
 
290
      break;
 
291
    case NodeState::ST_ILLEGAL_TYPE:
 
292
    default:
 
293
      ndbout << " UNKNOWN " << state.starting.restartType;
 
294
    }
 
295
    ndbout << " phase: " << state.starting.startPhase << "> ]";
 
296
    break;
 
297
  case NodeState::SL_STARTED:
 
298
    ndbout << "<STARTED> ]";
 
299
    break;
 
300
  case NodeState::SL_STOPPING_1:
 
301
    ndbout << "<STOPPING 1 sys: " << state.stopping.systemShutdown << "> ]";
 
302
    break;
 
303
  case NodeState::SL_STOPPING_2:
 
304
    ndbout << "<STOPPING 2 sys: " << state.stopping.systemShutdown << "> ]";
 
305
    break;
 
306
  case NodeState::SL_STOPPING_3:
 
307
    ndbout << "<STOPPING 3 sys: " << state.stopping.systemShutdown << "> ]";
 
308
    break;
 
309
  case NodeState::SL_STOPPING_4: 
 
310
    ndbout << "<STOPPING 4 sys: " << state.stopping.systemShutdown << "> ]";
 
311
    break;
 
312
  default:
 
313
    ndbout << "<UNKNOWN " << state.startLevel << "> ]";
 
314
  }
 
315
  return ndbout;
 
316
}
 
317
 
 
318
#endif