mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / src / kernel / blocks / dbdih / Sysfile.hpp
bloba86a9733f414e7991c5707cc9ef6764a4da1e380
1 /* Copyright (c) 2003-2005 MySQL AB
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #ifndef SYSFILE_HPP
17 #define SYSFILE_HPP
19 #include <ndb_types.h>
20 #include <ndb_limits.h>
21 #include <NodeBitmask.hpp>
23 /**
24 * No bits in Sysfile to represent nodeid
26 #define NODEID_BITS 8
28 /**
29 * Constant representing that node do not belong to
30 * any node group
32 #define NO_NODE_GROUP_ID ((1 << NODEID_BITS) - 1)
34 /**
35 * No of 32 bits word in sysfile
37 * 6 + // was 5 in < version 5.1
38 * MAX_NDB_NODES + // lastCompletedGCI
39 * NODE_ARRAY_SIZE(MAX_NDB_NODES, 4) + // nodeStatus
40 * NODE_ARRAY_SIZE(MAX_NDB_NODES, NODEID_BITS) + // nodeGroups
41 * NODE_ARRAY_SIZE(MAX_NDB_NODES, NODEID_BITS) + // takeOver
42 * NodeBitmask::NDB_NODE_BITMASK_SIZE // Lcp Active
44 #define _SYSFILE_SIZE32 (6 + \
45 MAX_NDB_NODES + \
46 NODE_ARRAY_SIZE(MAX_NDB_NODES, 4) + \
47 NODE_ARRAY_SIZE(MAX_NDB_NODES, NODEID_BITS) + \
48 NODE_ARRAY_SIZE(MAX_NDB_NODES, NODEID_BITS) + \
49 _NDB_NODE_BITMASK_SIZE)
51 /**
52 * This struct defines the format of P<X>.sysfile
54 struct Sysfile {
55 public:
57 /**
58 * No of 32 bits words in the sysfile
60 STATIC_CONST( SYSFILE_SIZE32 = _SYSFILE_SIZE32 );
62 Uint32 systemRestartBits;
64 /**
65 * Restart seq for _this_ node...
67 Uint32 m_restart_seq;
69 static bool getInitialStartOngoing(const Uint32 & systemRestartBits);
70 static void setInitialStartOngoing(Uint32 & systemRestartBits);
71 static void clearInitialStartOngoing(Uint32 & systemRestartBits);
73 static bool getRestartOngoing(const Uint32 & systemRestartBits);
74 static void setRestartOngoing(Uint32 & systemRestartBits);
75 static void clearRestartOngoing(Uint32 & systemRestartBits);
77 static bool getLCPOngoing(const Uint32 & systemRestartBits);
78 static void setLCPOngoing(Uint32 & systemRestartBits);
79 static void clearLCPOngoing(Uint32 & systemRestartBits);
81 Uint32 keepGCI;
82 Uint32 oldestRestorableGCI;
83 Uint32 newestRestorableGCI;
84 Uint32 latestLCP_ID;
86 /**
87 * Last completed GCI for each node
89 Uint32 lastCompletedGCI[MAX_NDB_NODES];
91 /**
92 * Active status bits
94 * It takes 4 bits to represent it
96 enum ActiveStatus {
97 NS_Active = 0
98 ,NS_ActiveMissed_1 = 1
99 ,NS_ActiveMissed_2 = 2
100 ,NS_ActiveMissed_3 = 3
101 ,NS_HotSpare = 4
102 ,NS_NotActive_NotTakenOver = 5
103 ,NS_TakeOver = 6
104 ,NS_NotActive_TakenOver = 7
105 ,NS_NotDefined = 8
106 ,NS_Standby = 9
108 STATIC_CONST( NODE_STATUS_SIZE = NODE_ARRAY_SIZE(MAX_NDB_NODES, 4) );
109 Uint32 nodeStatus[NODE_STATUS_SIZE];
111 static Uint32 getNodeStatus(NodeId, const Uint32 nodeStatus[]);
112 static void setNodeStatus(NodeId, Uint32 nodeStatus[], Uint32 status);
115 * The node group of each node
116 * Sizeof(NodeGroup) = 8 Bit
118 STATIC_CONST( NODE_GROUPS_SIZE = NODE_ARRAY_SIZE(MAX_NDB_NODES,
119 NODEID_BITS) );
120 Uint32 nodeGroups[NODE_GROUPS_SIZE];
122 static Uint16 getNodeGroup(NodeId, const Uint32 nodeGroups[]);
123 static void setNodeGroup(NodeId, Uint32 nodeGroups[], Uint16 group);
126 * Any node can take over for any node
128 STATIC_CONST( TAKE_OVER_SIZE = NODE_ARRAY_SIZE(MAX_NDB_NODES,
129 NODEID_BITS) );
130 Uint32 takeOver[TAKE_OVER_SIZE];
132 static NodeId getTakeOverNode(NodeId, const Uint32 takeOver[]);
133 static void setTakeOverNode(NodeId, Uint32 takeOver[], NodeId toNode);
136 * Is a node running a LCP
138 Uint32 lcpActive[NdbNodeBitmask::Size];
141 #if (MAX_NDB_NODES > (1<<NODEID_BITS))
142 #error "Sysfile node id is too small"
143 #endif
146 * Restart Info
148 * i = Initial start completed
149 * r = Crash during system restart
150 * l = Crash during local checkpoint
152 * 1111111111222222222233
153 * 01234567890123456789012345678901
154 * irl
156 inline
157 bool
158 Sysfile::getInitialStartOngoing(const Uint32 & systemRestartBits){
159 return systemRestartBits & 1;
162 inline
163 void
164 Sysfile::setInitialStartOngoing(Uint32 & systemRestartBits){
165 systemRestartBits |= 1;
168 inline
169 void
170 Sysfile::clearInitialStartOngoing(Uint32 & systemRestartBits){
171 systemRestartBits &= ~1;
174 inline
175 bool
176 Sysfile::getRestartOngoing(const Uint32 & systemRestartBits){
177 return (systemRestartBits & 2) != 0;
180 inline
181 void
182 Sysfile::setRestartOngoing(Uint32 & systemRestartBits){
183 systemRestartBits |= 2;
186 inline
187 void
188 Sysfile::clearRestartOngoing(Uint32 & systemRestartBits){
189 systemRestartBits &= ~2;
192 inline
193 bool
194 Sysfile::getLCPOngoing(const Uint32 & systemRestartBits){
195 return systemRestartBits & 4;
198 inline
199 void
200 Sysfile::setLCPOngoing(Uint32 & systemRestartBits){
201 systemRestartBits |= 4;
204 inline
205 void
206 Sysfile::clearLCPOngoing(Uint32 & systemRestartBits){
207 systemRestartBits &= ~4;
210 inline
211 Uint32
212 Sysfile::getNodeStatus(NodeId nodeId, const Uint32 nodeStatus[]){
213 const int word = nodeId >> 3;
214 const int shift = (nodeId & 7) << 2;
216 return (nodeStatus[word] >> shift) & 15;
219 inline
220 void
221 Sysfile::setNodeStatus(NodeId nodeId, Uint32 nodeStatus[], Uint32 status){
222 const int word = nodeId >> 3;
223 const int shift = (nodeId & 7) << 2;
225 const Uint32 mask = ~(((Uint32)15) << shift);
226 const Uint32 tmp = nodeStatus[word];
228 nodeStatus[word] = (tmp & mask) | ((status & 15) << shift);
231 inline
232 Uint16
233 Sysfile::getNodeGroup(NodeId nodeId, const Uint32 nodeGroups[]){
234 const int word = nodeId >> 2;
235 const int shift = (nodeId & 3) << 3;
237 return (nodeGroups[word] >> shift) & 255;
240 inline
241 void
242 Sysfile::setNodeGroup(NodeId nodeId, Uint32 nodeGroups[], Uint16 group){
243 const int word = nodeId >> 2;
244 const int shift = (nodeId & 3) << 3;
246 const Uint32 mask = ~(((Uint32)255) << shift);
247 const Uint32 tmp = nodeGroups[word];
249 nodeGroups[word] = (tmp & mask) | ((group & 255) << shift);
252 inline
253 NodeId
254 Sysfile::getTakeOverNode(NodeId nodeId, const Uint32 takeOver[]){
255 const int word = nodeId >> 2;
256 const int shift = (nodeId & 3) << 3;
258 return (takeOver[word] >> shift) & 255;
261 inline
262 void
263 Sysfile::setTakeOverNode(NodeId nodeId, Uint32 takeOver[], NodeId toNode){
264 const int word = nodeId >> 2;
265 const int shift = (nodeId & 3) << 3;
267 const Uint32 mask = ~(((Uint32)255) << shift);
268 const Uint32 tmp = takeOver[word];
270 takeOver[word] = (tmp & mask) | ((toNode & 255) << shift);
274 #endif