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 */
19 #include <ndb_types.h>
20 #include <ndb_limits.h>
21 #include <NodeBitmask.hpp>
24 * No bits in Sysfile to represent nodeid
29 * Constant representing that node do not belong to
32 #define NO_NODE_GROUP_ID ((1 << NODEID_BITS) - 1)
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 + \
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)
52 * This struct defines the format of P<X>.sysfile
58 * No of 32 bits words in the sysfile
60 STATIC_CONST( SYSFILE_SIZE32
= _SYSFILE_SIZE32
);
62 Uint32 systemRestartBits
;
65 * Restart seq for _this_ node...
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
);
82 Uint32 oldestRestorableGCI
;
83 Uint32 newestRestorableGCI
;
87 * Last completed GCI for each node
89 Uint32 lastCompletedGCI
[MAX_NDB_NODES
];
94 * It takes 4 bits to represent it
98 ,NS_ActiveMissed_1
= 1
99 ,NS_ActiveMissed_2
= 2
100 ,NS_ActiveMissed_3
= 3
102 ,NS_NotActive_NotTakenOver
= 5
104 ,NS_NotActive_TakenOver
= 7
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
,
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
,
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"
148 * i = Initial start completed
149 * r = Crash during system restart
150 * l = Crash during local checkpoint
152 * 1111111111222222222233
153 * 01234567890123456789012345678901
158 Sysfile::getInitialStartOngoing(const Uint32
& systemRestartBits
){
159 return systemRestartBits
& 1;
164 Sysfile::setInitialStartOngoing(Uint32
& systemRestartBits
){
165 systemRestartBits
|= 1;
170 Sysfile::clearInitialStartOngoing(Uint32
& systemRestartBits
){
171 systemRestartBits
&= ~1;
176 Sysfile::getRestartOngoing(const Uint32
& systemRestartBits
){
177 return (systemRestartBits
& 2) != 0;
182 Sysfile::setRestartOngoing(Uint32
& systemRestartBits
){
183 systemRestartBits
|= 2;
188 Sysfile::clearRestartOngoing(Uint32
& systemRestartBits
){
189 systemRestartBits
&= ~2;
194 Sysfile::getLCPOngoing(const Uint32
& systemRestartBits
){
195 return systemRestartBits
& 4;
200 Sysfile::setLCPOngoing(Uint32
& systemRestartBits
){
201 systemRestartBits
|= 4;
206 Sysfile::clearLCPOngoing(Uint32
& systemRestartBits
){
207 systemRestartBits
&= ~4;
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;
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
);
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;
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
);
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;
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
);