MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sysfile.hpp
1 /*
2  Copyright (C) 2003-2006, 2008 MySQL AB
3  All rights reserved. Use is subject to license terms.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef SYSFILE_HPP
20 #define SYSFILE_HPP
21 
22 #include <ndb_types.h>
23 #include <ndb_limits.h>
24 #include <NodeBitmask.hpp>
25 
29 #define NODEID_BITS 8
30 
35 #define NO_NODE_GROUP_ID ((1 << NODEID_BITS) - 1)
36 
47 #define _SYSFILE_SIZE32 (6 + \
48  MAX_NDB_NODES + \
49  NODE_ARRAY_SIZE(MAX_NDB_NODES, 4) + \
50  NODE_ARRAY_SIZE(MAX_NDB_NODES, NODEID_BITS) + \
51  NODE_ARRAY_SIZE(MAX_NDB_NODES, NODEID_BITS) + \
52  _NDB_NODE_BITMASK_SIZE)
53 
57 struct Sysfile {
58 public:
59 
63  STATIC_CONST( SYSFILE_SIZE32 = _SYSFILE_SIZE32 );
64 
65  Uint32 systemRestartBits;
66 
70  Uint32 m_restart_seq;
71 
72  static bool getInitialStartOngoing(const Uint32 & systemRestartBits);
73  static void setInitialStartOngoing(Uint32 & systemRestartBits);
74  static void clearInitialStartOngoing(Uint32 & systemRestartBits);
75 
76  static bool getRestartOngoing(const Uint32 & systemRestartBits);
77  static void setRestartOngoing(Uint32 & systemRestartBits);
78  static void clearRestartOngoing(Uint32 & systemRestartBits);
79 
80  static bool getLCPOngoing(const Uint32 & systemRestartBits);
81  static void setLCPOngoing(Uint32 & systemRestartBits);
82  static void clearLCPOngoing(Uint32 & systemRestartBits);
83 
84  Uint32 keepGCI;
85  Uint32 oldestRestorableGCI;
86  Uint32 newestRestorableGCI;
87  Uint32 latestLCP_ID;
88 
92  Uint32 lastCompletedGCI[MAX_NDB_NODES];
93 
99  enum ActiveStatus {
100  NS_Active = 0
101  ,NS_ActiveMissed_1 = 1
102  ,NS_ActiveMissed_2 = 2
103  ,NS_ActiveMissed_3 = 3
104  ,NS_NotActive_NotTakenOver = 5
105  ,NS_TakeOver = 6
106  ,NS_NotActive_TakenOver = 7
107  ,NS_NotDefined = 8
108  ,NS_Configured = 9
109  };
110  STATIC_CONST( NODE_STATUS_SIZE = NODE_ARRAY_SIZE(MAX_NDB_NODES, 4) );
111  Uint32 nodeStatus[NODE_STATUS_SIZE];
112 
113  static Uint32 getNodeStatus(NodeId, const Uint32 nodeStatus[]);
114  static void setNodeStatus(NodeId, Uint32 nodeStatus[], Uint32 status);
115 
120  STATIC_CONST( NODE_GROUPS_SIZE = NODE_ARRAY_SIZE(MAX_NDB_NODES,
121  NODEID_BITS) );
122  Uint32 nodeGroups[NODE_GROUPS_SIZE];
123 
124  static Uint16 getNodeGroup(NodeId, const Uint32 nodeGroups[]);
125  static void setNodeGroup(NodeId, Uint32 nodeGroups[], Uint16 group);
126 
130  STATIC_CONST( TAKE_OVER_SIZE = NODE_ARRAY_SIZE(MAX_NDB_NODES,
131  NODEID_BITS) );
132  Uint32 takeOver[TAKE_OVER_SIZE];
133 
134  static NodeId getTakeOverNode(NodeId, const Uint32 takeOver[]);
135  static void setTakeOverNode(NodeId, Uint32 takeOver[], NodeId toNode);
136 
140  Uint32 lcpActive[NdbNodeBitmask::Size];
141 };
142 
143 #if (MAX_NDB_NODES > (1<<NODEID_BITS))
144 #error "Sysfile node id is too small"
145 #endif
146 
158 inline
159 bool
160 Sysfile::getInitialStartOngoing(const Uint32 & systemRestartBits){
161  return systemRestartBits & 1;
162 }
163 
164 inline
165 void
166 Sysfile::setInitialStartOngoing(Uint32 & systemRestartBits){
167  systemRestartBits |= 1;
168 }
169 
170 inline
171 void
172 Sysfile::clearInitialStartOngoing(Uint32 & systemRestartBits){
173  systemRestartBits &= ~1;
174 }
175 
176 inline
177 bool
178 Sysfile::getRestartOngoing(const Uint32 & systemRestartBits){
179  return (systemRestartBits & 2) != 0;
180 }
181 
182 inline
183 void
184 Sysfile::setRestartOngoing(Uint32 & systemRestartBits){
185  systemRestartBits |= 2;
186 }
187 
188 inline
189 void
190 Sysfile::clearRestartOngoing(Uint32 & systemRestartBits){
191  systemRestartBits &= ~2;
192 }
193 
194 inline
195 bool
196 Sysfile::getLCPOngoing(const Uint32 & systemRestartBits){
197  return systemRestartBits & 4;
198 }
199 
200 inline
201 void
202 Sysfile::setLCPOngoing(Uint32 & systemRestartBits){
203  systemRestartBits |= 4;
204 }
205 
206 inline
207 void
208 Sysfile::clearLCPOngoing(Uint32 & systemRestartBits){
209  systemRestartBits &= ~4;
210 }
211 
212 inline
213 Uint32
214 Sysfile::getNodeStatus(NodeId nodeId, const Uint32 nodeStatus[]){
215  const int word = nodeId >> 3;
216  const int shift = (nodeId & 7) << 2;
217 
218  return (nodeStatus[word] >> shift) & 15;
219 }
220 
221 inline
222 void
223 Sysfile::setNodeStatus(NodeId nodeId, Uint32 nodeStatus[], Uint32 status){
224  const int word = nodeId >> 3;
225  const int shift = (nodeId & 7) << 2;
226 
227  const Uint32 mask = ~(((Uint32)15) << shift);
228  const Uint32 tmp = nodeStatus[word];
229 
230  nodeStatus[word] = (tmp & mask) | ((status & 15) << shift);
231 }
232 
233 inline
234 Uint16
235 Sysfile::getNodeGroup(NodeId nodeId, const Uint32 nodeGroups[]){
236  const int word = nodeId >> 2;
237  const int shift = (nodeId & 3) << 3;
238 
239  return (nodeGroups[word] >> shift) & 255;
240 }
241 
242 inline
243 void
244 Sysfile::setNodeGroup(NodeId nodeId, Uint32 nodeGroups[], Uint16 group){
245  const int word = nodeId >> 2;
246  const int shift = (nodeId & 3) << 3;
247 
248  const Uint32 mask = ~(((Uint32)255) << shift);
249  const Uint32 tmp = nodeGroups[word];
250 
251  nodeGroups[word] = (tmp & mask) | ((group & 255) << shift);
252 }
253 
254 inline
255 NodeId
256 Sysfile::getTakeOverNode(NodeId nodeId, const Uint32 takeOver[]){
257  const int word = nodeId >> 2;
258  const int shift = (nodeId & 3) << 3;
259 
260  return (takeOver[word] >> shift) & 255;
261 }
262 
263 inline
264 void
265 Sysfile::setTakeOverNode(NodeId nodeId, Uint32 takeOver[], NodeId toNode){
266  const int word = nodeId >> 2;
267  const int shift = (nodeId & 3) << 3;
268 
269  const Uint32 mask = ~(((Uint32)255) << shift);
270  const Uint32 tmp = takeOver[word];
271 
272  takeOver[word] = (tmp & mask) | ((toNode & 255) << shift);
273 }
274 
275 
276 #endif