MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NodeState.hpp
1 /*
2  Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef NODE_STATE_HPP
19 #define NODE_STATE_HPP
20 
21 #include <NdbOut.hpp>
22 #include <NodeBitmask.hpp>
23 
25 {
26  enum StartLevel {
32 
39  SL_CMVMI = 1,
40 
48 
53 
54  SL_SINGLEUSER = 4,
55 
64 
70 
71 
72 
73 
82 
91  };
92 
93  enum StartType {
94  ST_INITIAL_START = 0,
95  ST_SYSTEM_RESTART = 1,
96  ST_NODE_RESTART = 2,
97  ST_INITIAL_NODE_RESTART = 3,
98  ST_ILLEGAL_TYPE = 4
99  };
100 
104  STATIC_CONST( DataLength = 8 + NodeBitmask::Size );
105 
109  void init();
110 
114  Uint32 startLevel;
115 
119  Uint32 nodeGroup; // valid when startLevel == SL_STARTING
120 
124  union {
125  Uint32 dynamicId; // valid when startLevel == SL_STARTING to API
126  Uint32 masterNodeId; // When from cntr
127  };
128 
132  union {
133  struct {
134  Uint32 startPhase; // valid when startLevel == SL_STARTING
135  Uint32 restartType; // valid when startLevel == SL_STARTING
136  } starting;
137  struct {
138  Uint32 systemShutdown; // valid when startLevel == SL_STOPPING_{X}
139  Uint32 timeout;
140  Uint32 alarmTime;
141  } stopping;
142 
143 
144  };
145  Uint32 singleUserMode;
146  Uint32 singleUserApi; //the single user node
147 
148  BitmaskPOD<NodeBitmask::Size> m_connected_nodes;
149 
150  void setDynamicId(Uint32 dynamic);
151  void setNodeGroup(Uint32 group);
152  void setSingleUser(Uint32 s);
153  void setSingleUserApi(Uint32 n);
154 
155 
159  bool getNodeRestartInProgress() const;
160 
164  bool getSystemRestartInProgress() const;
165 
169  bool getStarted() const {
170  return startLevel == SL_STARTED || startLevel == SL_SINGLEUSER;
171  }
172 
176  bool getSingleUserMode() const;
177 
181  Uint32 getSingleUserApi() const;
182 };
183 
184 class NodeState : public NodeStatePOD
185 {
186 public:
187  NodeState();
189  NodeState(StartLevel, bool systemShutdown);
190  NodeState(StartLevel, Uint32 startPhase, StartType);
191 
192  NodeState& operator=(const NodeStatePOD&);
193 };
194 
195 inline
196 NodeState::NodeState(){
197  init();
198 }
199 
200 inline
201 void
204  nodeGroup = 0xFFFFFFFF;
205  dynamicId = 0xFFFFFFFF;
206  singleUserMode = 0;
207  singleUserApi = 0xFFFFFFFF;
208  m_connected_nodes.clear();
209 }
210 
211 inline
212 NodeState::NodeState(StartLevel sl){
213  init();
214  startLevel = sl;
215  singleUserMode = 0;
216  singleUserApi = 0xFFFFFFFF;
217 }
218 
219 inline
220 NodeState::NodeState(StartLevel sl, Uint32 sp, StartType typeOfStart){
221  init();
222  startLevel = sl;
223  starting.startPhase = sp;
224  starting.restartType = typeOfStart;
225  singleUserMode = 0;
226  singleUserApi = 0xFFFFFFFF;
227 }
228 
229 inline
230 NodeState::NodeState(StartLevel sl, bool sys){
231  init();
232  startLevel = sl;
233  stopping.systemShutdown = sys;
234  singleUserMode = 0;
235  singleUserApi = 0xFFFFFFFF;
236 }
237 
238 inline
239 void NodeStatePOD::setDynamicId(Uint32 dynamic){
240  dynamicId = dynamic;
241 }
242 
243 inline
244 void NodeStatePOD::setNodeGroup(Uint32 group){
245  nodeGroup = group;
246 }
247 
248 inline
249 void NodeStatePOD::setSingleUser(Uint32 s) {
250  singleUserMode = s;
251 }
252 
253 inline
254 void NodeStatePOD::setSingleUserApi(Uint32 n) {
255  singleUserApi = n;
256 }
257 inline
259  return startLevel == SL_STARTING &&
260  (starting.restartType == ST_NODE_RESTART ||
261  starting.restartType == ST_INITIAL_NODE_RESTART);
262 }
263 
264 inline
266  return singleUserMode;
267 }
268 
269 inline
271  return singleUserApi;
272 }
273 
274 inline
276  return startLevel == SL_STARTING && starting.restartType == ST_SYSTEM_RESTART;
277 }
278 
279 inline
280 NdbOut &
281 operator<<(NdbOut& ndbout, const NodeStatePOD & state){
282  ndbout << "[NodeState: startLevel: ";
283  switch(state.startLevel){
285  ndbout << "<NOTHING> ]";
286  break;
287  case NodeState::SL_CMVMI:
288  ndbout << "<CMVMI> ]";
289  break;
291  ndbout << "<STARTING type: ";
292  switch(state.starting.restartType){
293  case NodeState::ST_INITIAL_START:
294  ndbout << " INITIAL START";
295  break;
296  case NodeState::ST_SYSTEM_RESTART:
297  ndbout << " SYSTEM RESTART ";
298  break;
299  case NodeState::ST_NODE_RESTART:
300  ndbout << " NODE RESTART ";
301  break;
302  case NodeState::ST_INITIAL_NODE_RESTART:
303  ndbout << " INITIAL NODE RESTART ";
304  break;
305  case NodeState::ST_ILLEGAL_TYPE:
306  default:
307  ndbout << " UNKNOWN " << state.starting.restartType;
308  }
309  ndbout << " phase: " << state.starting.startPhase << "> ]";
310  break;
312  ndbout << "<STARTED> ]";
313  break;
315  ndbout << "<STOPPING 1 sys: " << state.stopping.systemShutdown << "> ]";
316  break;
318  ndbout << "<STOPPING 2 sys: " << state.stopping.systemShutdown << "> ]";
319  break;
321  ndbout << "<STOPPING 3 sys: " << state.stopping.systemShutdown << "> ]";
322  break;
324  ndbout << "<STOPPING 4 sys: " << state.stopping.systemShutdown << "> ]";
325  break;
326  default:
327  ndbout << "<UNKNOWN " << state.startLevel << "> ]";
328  }
329  return ndbout;
330 }
331 
332 inline
333 NodeState&
334 NodeState::operator=(const NodeStatePOD& ns)
335 {
336  startLevel = ns.startLevel;
337  nodeGroup = ns.nodeGroup;
338  dynamicId = ns.dynamicId;
339  // masterNodeId is union with dynamicId
340  starting.startPhase = ns.starting.startPhase;
341  starting.restartType = ns.starting.restartType;
342  // stopping.systemShutdown is union with starting.startPhase
343  // stopping.timeout is union with starting.restartType
344  stopping.alarmTime = ns.stopping.alarmTime;
345  singleUserMode = ns.singleUserMode;
346  singleUserApi = ns.singleUserApi;
347  m_connected_nodes.assign(ns.m_connected_nodes);
348  return * this;
349 }
350 #endif