MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbRestarter.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 NDBT_RESTARTER_HPP
19 #define NDBT_RESTARTER_HPP
20 
21 #include <mgmapi.h>
22 #include <Vector.hpp>
23 #include <BaseString.hpp>
24 
25 class NdbRestarter {
26 public:
27  NdbRestarter(const char* _addr = 0);
28  ~NdbRestarter();
29 
30  int getDbNodeId(int _i);
31 
32  enum RestartFlags {
33  NRRF_INITIAL = 0x1,
34  NRRF_NOSTART = 0x2,
35  NRRF_ABORT = 0x4,
36  NRRF_FORCE = 0x8
37  };
38 
39  int restartOneDbNode(int _nodeId,
40  bool initial = false,
41  bool nostart = false,
42  bool abort = false,
43  bool force = false);
44 
45  int restartOneDbNode2(int _nodeId, Uint32 flags){
46  return restartOneDbNode(_nodeId,
47  flags & NRRF_INITIAL,
48  flags & NRRF_NOSTART,
49  flags & NRRF_ABORT,
50  flags & NRRF_FORCE);
51  }
52 
53  int restartAll(bool initial = false,
54  bool nostart = false,
55  bool abort = false,
56  bool force = false);
57 
58  int restartAll2(Uint32 flags){
59  return restartAll(flags & NRRF_INITIAL,
60  flags & NRRF_NOSTART,
61  flags & NRRF_ABORT,
62  flags & NRRF_FORCE);
63  }
64 
65  int restartNodes(int * nodes, int num_nodes, Uint32 flags);
66 
67  int startAll();
68  int startNodes(const int * _nodes, int _num_nodes);
69  int waitConnected(unsigned int _timeout = 120);
70  int waitClusterStarted(unsigned int _timeout = 120);
71  int waitClusterSingleUser(unsigned int _timeout = 120);
72  int waitClusterStartPhase(int _startphase, unsigned int _timeout = 120);
73  int waitClusterNoStart(unsigned int _timeout = 120);
74  int waitNodesStarted(const int * _nodes, int _num_nodes,
75  unsigned int _timeout = 120);
76  int waitNodesStartPhase(const int * _nodes, int _num_nodes,
77  int _startphase, unsigned int _timeout = 120);
78  int waitNodesNoStart(const int * _nodes, int _num_nodes,
79  unsigned int _timeout = 120);
80 
81  int checkClusterAlive(const int * deadnodes, int num_nodes);
82 
83  int getNumDbNodes();
84  int insertErrorInNode(int _nodeId, int error);
85  int insertErrorInAllNodes(int error);
86 
87  int enterSingleUserMode(int _nodeId);
88  int exitSingleUserMode();
89 
90  int dumpStateOneNode(int _nodeId, const int * _args, int _num_args);
91  int dumpStateAllNodes(const int * _args, int _num_args);
92 
93  int getMasterNodeId();
94  int getNextMasterNodeId(int nodeId);
95  int getNodeGroup(int nodeId);
96  int getRandomNodeSameNodeGroup(int nodeId, int randomNumber);
97  int getRandomNodeOtherNodeGroup(int nodeId, int randomNumber);
98  int getRandomNotMasterNodeId(int randomNumber);
99 
100  int getMasterNodeVersion(int& version);
101  int getNodeTypeVersionRange(ndb_mgm_node_type type, int& minVer, int& maxVer);
102 
103  int getNodeStatus(int nodeId); // return NDB_MGM_NODE_STATUS_*
104 
105  NdbMgmHandle handle;
106 
107  enum NodeSelector
108  {
109  NS_RANDOM = 0, // Any node
110  NS_MASTER = 1, // Master node
111  NS_NON_MASTER = 2
112  };
113 
114  int getNode(NodeSelector);
115 
116  void setReconnect(bool);
117 
118  int rollingRestart(Uint32 flags = 0);
119 protected:
120 
121  int waitClusterState(ndb_mgm_node_status _status,
122  unsigned int _timeout,
123  int _startphase = -1);
124 
125  int waitNodesState(const int * _nodes, int _num_nodes,
126  ndb_mgm_node_status _status,
127  unsigned int _timeout,
128  int _startphase = -1);
129 
130  bool isConnected();
131  int connect();
132  void disconnect();
133  int getStatus();
134 
137 
138  bool connected;
139  BaseString addr;
140  ndb_mgm_configuration * m_config;
141  bool m_reconnect;
142 protected:
143  ndb_mgm_configuration * getConfig();
144 
145 public:
147 };
148 
149 #endif