summaryrefslogtreecommitdiff
path: root/storage/ndb/src/kernel/blocks/dbdih/Sysfile.hpp
blob: 48daf42675a4697cbb30d6b78925c415a25ee8e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/* Copyright (C) 2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#ifndef SYSFILE_HPP
#define SYSFILE_HPP

#include <ndb_types.h>
#include <ndb_limits.h>
#include <NodeBitmask.hpp>

/**
 * No bits in Sysfile to represent nodeid
 */
#define NODEID_BITS 8

/**
 * Constant representing that node do not belong to
 * any node group
 */
#define NO_NODE_GROUP_ID ((1 << NODEID_BITS) - 1)

/**
 * No of 32 bits word in sysfile
 *
 *   6 +                                           // was 5 in < version 5.1
 *   MAX_NDB_NODES +                               // lastCompletedGCI
 *   NODE_ARRAY_SIZE(MAX_NDB_NODES, 4) +           // nodeStatus
 *   NODE_ARRAY_SIZE(MAX_NDB_NODES, NODEID_BITS) + // nodeGroups
 *   NODE_ARRAY_SIZE(MAX_NDB_NODES, NODEID_BITS) + // takeOver
 *   NodeBitmask::NDB_NODE_BITMASK_SIZE            // Lcp Active
 */
#define _SYSFILE_SIZE32 (6 + \
                         MAX_NDB_NODES + \
                         NODE_ARRAY_SIZE(MAX_NDB_NODES, 4) + \
                         NODE_ARRAY_SIZE(MAX_NDB_NODES, NODEID_BITS) + \
                         NODE_ARRAY_SIZE(MAX_NDB_NODES, NODEID_BITS) + \
                         _NDB_NODE_BITMASK_SIZE)

/**
 * This struct defines the format of P<X>.sysfile
 */
struct Sysfile {
public:

  /**
   * No of 32 bits words in the sysfile
   */
  STATIC_CONST( SYSFILE_SIZE32 = _SYSFILE_SIZE32 );
  
  Uint32 systemRestartBits;

  /**
   * Restart seq for _this_ node...
   */
  Uint32 m_restart_seq;

  static bool getInitialStartOngoing(const Uint32 & systemRestartBits);
  static void setInitialStartOngoing(Uint32 & systemRestartBits);
  static void clearInitialStartOngoing(Uint32 & systemRestartBits);

  static bool getRestartOngoing(const Uint32 & systemRestartBits);
  static void setRestartOngoing(Uint32 & systemRestartBits);
  static void clearRestartOngoing(Uint32 & systemRestartBits);

  static bool getLCPOngoing(const Uint32 & systemRestartBits);
  static void setLCPOngoing(Uint32 & systemRestartBits);
  static void clearLCPOngoing(Uint32 & systemRestartBits);
  
  Uint32 keepGCI;
  Uint32 oldestRestorableGCI;
  Uint32 newestRestorableGCI;
  Uint32 latestLCP_ID;
  
  /**
   * Last completed GCI for each node
   */
  Uint32 lastCompletedGCI[MAX_NDB_NODES];
  
  /**
   * Active status bits
   *
   *  It takes 4 bits to represent it
   */
  enum ActiveStatus {
    NS_Active                  = 0
    ,NS_ActiveMissed_1         = 1
    ,NS_ActiveMissed_2         = 2
    ,NS_ActiveMissed_3         = 3
    ,NS_HotSpare               = 4
    ,NS_NotActive_NotTakenOver = 5
    ,NS_TakeOver               = 6
    ,NS_NotActive_TakenOver    = 7
    ,NS_NotDefined             = 8
    ,NS_Standby                = 9
  };
  STATIC_CONST( NODE_STATUS_SIZE = NODE_ARRAY_SIZE(MAX_NDB_NODES, 4) );
  Uint32 nodeStatus[NODE_STATUS_SIZE];

  static Uint32 getNodeStatus(NodeId, const Uint32 nodeStatus[]);
  static void   setNodeStatus(NodeId, Uint32 nodeStatus[], Uint32 status);
  
  /**
   * The node group of each node
   *   Sizeof(NodeGroup) = 8 Bit
   */
  STATIC_CONST( NODE_GROUPS_SIZE = NODE_ARRAY_SIZE(MAX_NDB_NODES, 
							 NODEID_BITS) );
  Uint32 nodeGroups[NODE_GROUPS_SIZE];
  
  static Uint16 getNodeGroup(NodeId, const Uint32 nodeGroups[]);
  static void   setNodeGroup(NodeId, Uint32 nodeGroups[], Uint16 group);

  /**
   * Any node can take over for any node
   */
  STATIC_CONST( TAKE_OVER_SIZE = NODE_ARRAY_SIZE(MAX_NDB_NODES, 
						 NODEID_BITS) );
  Uint32 takeOver[TAKE_OVER_SIZE];

  static NodeId getTakeOverNode(NodeId, const Uint32 takeOver[]);
  static void   setTakeOverNode(NodeId, Uint32 takeOver[], NodeId toNode);
  
  /**
   * Is a node running a LCP
   */
  Uint32 lcpActive[NdbNodeBitmask::Size];
};

#if (MAX_NDB_NODES > (1<<NODEID_BITS))
#error "Sysfile node id is too small"
#endif

/**
 * Restart Info
 *
 * i = Initial start completed
 * r = Crash during system restart
 * l = Crash during local checkpoint

 *           1111111111222222222233
 * 01234567890123456789012345678901
 * irl
 */
inline
bool 
Sysfile::getInitialStartOngoing(const Uint32 & systemRestartBits){
  return systemRestartBits & 1;
}

inline 
void 
Sysfile::setInitialStartOngoing(Uint32 & systemRestartBits){
  systemRestartBits |= 1;
}

inline
void
Sysfile::clearInitialStartOngoing(Uint32 & systemRestartBits){
  systemRestartBits &= ~1;
}

inline 
bool 
Sysfile::getRestartOngoing(const Uint32 & systemRestartBits){
  return (systemRestartBits & 2) != 0;
}

inline
void 
Sysfile::setRestartOngoing(Uint32 & systemRestartBits){
  systemRestartBits |= 2;
}

inline
void 
Sysfile::clearRestartOngoing(Uint32 & systemRestartBits){
  systemRestartBits &= ~2;
}

inline 
bool
Sysfile::getLCPOngoing(const Uint32 & systemRestartBits){
  return systemRestartBits & 4;
}

inline
void 
Sysfile::setLCPOngoing(Uint32 & systemRestartBits){
  systemRestartBits |= 4;
}

inline
void 
Sysfile::clearLCPOngoing(Uint32 & systemRestartBits){
  systemRestartBits &= ~4;
}

inline
Uint32 
Sysfile::getNodeStatus(NodeId nodeId, const Uint32 nodeStatus[]){
  const int word  = nodeId >> 3;
  const int shift = (nodeId & 7) << 2;
  
  return (nodeStatus[word] >> shift) & 15;
}

inline
void
Sysfile::setNodeStatus(NodeId nodeId, Uint32 nodeStatus[], Uint32 status){
  const int word  = nodeId >> 3;
  const int shift = (nodeId & 7) << 2;

  const Uint32 mask = ~(((Uint32)15) << shift);
  const Uint32 tmp = nodeStatus[word];
  
  nodeStatus[word] = (tmp & mask) | ((status & 15) << shift);
}

inline
Uint16
Sysfile::getNodeGroup(NodeId nodeId, const Uint32 nodeGroups[]){
  const int word = nodeId >> 2;
  const int shift = (nodeId & 3) << 3;
  
  return (nodeGroups[word] >> shift) & 255;
}

inline
void
Sysfile::setNodeGroup(NodeId nodeId, Uint32 nodeGroups[], Uint16 group){
  const int word = nodeId >> 2;
  const int shift = (nodeId & 3) << 3;
  
  const Uint32 mask = ~(((Uint32)255) << shift);
  const Uint32 tmp = nodeGroups[word];
  
  nodeGroups[word] = (tmp & mask) | ((group & 255) << shift);  
}

inline 
NodeId 
Sysfile::getTakeOverNode(NodeId nodeId, const Uint32 takeOver[]){
  const int word = nodeId >> 2;
  const int shift = (nodeId & 3) << 3;
  
  return (takeOver[word] >> shift) & 255;
}

inline
void
Sysfile::setTakeOverNode(NodeId nodeId, Uint32 takeOver[], NodeId toNode){
  const int word = nodeId >> 2;
  const int shift = (nodeId & 3) << 3;
  
  const Uint32 mask = ~(((Uint32)255) << shift);
  const Uint32 tmp = takeOver[word];
  
  takeOver[word] = (tmp & mask) | ((toNode & 255) << shift);  
}


#endif