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, version 2.0, 6 as published by the Free Software Foundation. 7 8 This program is also distributed with certain software (including 9 but not limited to OpenSSL) that is licensed under separate terms, 10 as designated in a particular file or component or in included license 11 documentation. The authors of MySQL hereby grant you an additional 12 permission to link the program and your derivative works with the 13 separately licensed software that they have included with MySQL. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License, version 2.0, for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 25 #ifndef NDBCNTR_H 26 #define NDBCNTR_H 27 28 29 #include <pc.hpp> 30 #include <SimulatedBlock.hpp> 31 #include <ndb_limits.h> 32 #include <signaldata/StopReq.hpp> 33 #include <signaldata/ResumeReq.hpp> 34 #include <signaldata/DictTabInfo.hpp> 35 #include <signaldata/CntrStart.hpp> 36 #include <signaldata/CheckNodeGroups.hpp> 37 38 #include <NodeState.hpp> 39 #include <NdbTick.h> 40 41 #ifdef NDBCNTR_C 42 /* 43 2.1 GLOBAL SYMBOLS 44 ------------------ 45 */ 46 /* 47 2.2 LOCAL SYMBOLS 48 ----------------- 49 */ 50 #define ZNO_NDB_BLOCKS 6 /* ACC, DICT, DIH, LQH, TC, TUP */ 51 52 #define ZNOT_AVAILABLE 913 53 54 //------- OTHERS --------------------------------------------- 55 #define ZSTARTUP 1 56 #define ZSHUTDOWN 2 57 #define ZBLOCK_STTOR 3 58 59 #define ZSIZE_NDB_BLOCKS_REC 16 /* MAX BLOCKS IN NDB */ 60 #define ZSIZE_SYSTAB 2048 61 #define ZSTART_PHASE_1 1 62 #define ZSTART_PHASE_2 2 63 #define ZSTART_PHASE_3 3 64 #define ZSTART_PHASE_4 4 65 #define ZSTART_PHASE_5 5 66 #define ZSTART_PHASE_6 6 67 #define ZSTART_PHASE_7 7 68 #define ZSTART_PHASE_8 8 69 #define ZSTART_PHASE_9 9 70 #define ZSTART_PHASE_END 255 71 #endif 72 73 class Ndbcntr: public SimulatedBlock { 74 public: 75 // Records 76 77 /* FSREADREQ FSWRITEREQ */ 78 /** 79 * 2.3 RECORDS AND FILESIZES 80 * ------------------------------------------------------------ 81 */ 82 83 struct StartRecord { StartRecordNdbcntr::StartRecord84 StartRecord() {} 85 Uint64 m_startTime; 86 87 void reset(); 88 NdbNodeBitmask m_starting; 89 NdbNodeBitmask m_waiting; // == (m_withLog | m_withoutLog | m_waitTO) 90 NdbNodeBitmask m_withLog; 91 NdbNodeBitmask m_withoutLog; 92 NdbNodeBitmask m_waitTO; 93 Uint32 m_lastGci; 94 Uint32 m_lastGciNodeId; 95 96 Uint64 m_startPartialTimeout; 97 Uint64 m_startPartitionedTimeout; 98 Uint64 m_startFailureTimeout; 99 struct { 100 Uint32 m_nodeId; 101 Uint32 m_lastGci; 102 } m_logNodes[MAX_NDB_NODES]; 103 Uint32 m_logNodesCount; 104 105 Uint32 m_wait_sp[MAX_NDB_NODES]; 106 } c_start; 107 108 struct NdbBlocksRec { 109 BlockReference blockref; 110 }; /* p2c: size = 2 bytes */ 111 112 typedef Ptr<NdbBlocksRec> NdbBlocksRecPtr; 113 114 /** 115 * Ndbcntr creates and initializes system tables on initial system start. 116 * The tables are defined in static structs in NdbcntrSysTable.cpp. 117 */ 118 struct SysColumn { 119 unsigned pos; 120 const char* name; 121 // DictTabInfo 122 DictTabInfo::ExtType type; 123 Uint32 length; 124 bool keyFlag; 125 bool nullable; 126 }; 127 struct SysTable { 128 const char* name; 129 unsigned columnCount; 130 const SysColumn* columnList; 131 // DictTabInfo 132 DictTabInfo::TableType tableType; 133 DictTabInfo::FragmentType fragmentType; 134 bool tableLoggedFlag; 135 // saved table id 136 mutable Uint32 tableId; 137 mutable Uint32 tableVersion; 138 }; 139 struct SysIndex { 140 const char* name; 141 const SysTable* primaryTable; 142 Uint32 columnCount; 143 Uint32 columnList[4]; 144 // DictTabInfo 145 DictTabInfo::TableType indexType; 146 DictTabInfo::FragmentType fragmentType; 147 bool indexLoggedFlag; 148 // saved index table id 149 mutable Uint32 indexId; 150 }; 151 static const SysTable* g_sysTableList[]; 152 static const unsigned g_sysTableCount; 153 // the system tables 154 static const SysTable g_sysTable_SYSTAB_0; 155 static SysTable g_sysTable_NDBEVENTS_0; 156 // schema trans 157 Uint32 c_schemaTransId; 158 Uint32 c_schemaTransKey; 159 Uint32 c_hashMapId; 160 Uint32 c_hashMapVersion; 161 162 public: 163 Ndbcntr(Block_context&); 164 virtual ~Ndbcntr(); 165 166 private: 167 BLOCK_DEFINES(Ndbcntr); 168 169 // Transit signals 170 void execAPI_START_REP(Signal*); 171 void execCONTINUEB(Signal* signal); 172 void execREAD_NODESCONF(Signal* signal); 173 void execREAD_NODESREF(Signal* signal); 174 void execCM_ADD_REP(Signal* signal); 175 void execCNTR_START_REQ(Signal* signal); 176 void execCNTR_START_REF(Signal* signal); 177 void execCNTR_START_CONF(Signal* signal); 178 void execCNTR_START_REP(Signal* signal); 179 void execCNTR_WAITREP(Signal* signal); 180 void execNODE_FAILREP(Signal* signal); 181 void execSYSTEM_ERROR(Signal* signal); 182 183 void execSTART_PERMREP(Signal*); 184 185 // Received signals 186 void execDUMP_STATE_ORD(Signal* signal); 187 void execREAD_CONFIG_REQ(Signal* signal); 188 void execSTTOR(Signal* signal); 189 void execTCSEIZECONF(Signal* signal); 190 void execTCSEIZEREF(Signal* signal); 191 void execTCRELEASECONF(Signal* signal); 192 void execTCRELEASEREF(Signal* signal); 193 void execTCKEYCONF(Signal* signal); 194 void execTCKEYREF(Signal* signal); 195 void execTCROLLBACKREP(Signal* signal); 196 void execGETGCICONF(Signal* signal); 197 void execDIH_RESTARTCONF(Signal* signal); 198 void execDIH_RESTARTREF(Signal* signal); 199 void execSCHEMA_TRANS_BEGIN_CONF(Signal* signal); 200 void execSCHEMA_TRANS_BEGIN_REF(Signal* signal); 201 void execSCHEMA_TRANS_END_CONF(Signal* signal); 202 void execSCHEMA_TRANS_END_REF(Signal* signal); 203 void execCREATE_TABLE_REF(Signal* signal); 204 void execCREATE_TABLE_CONF(Signal* signal); 205 void execCREATE_HASH_MAP_REF(Signal* signal); 206 void execCREATE_HASH_MAP_CONF(Signal* signal); 207 void execCREATE_FILEGROUP_REF(Signal* signal); 208 void execCREATE_FILEGROUP_CONF(Signal* signal); 209 void execCREATE_FILE_REF(Signal* signal); 210 void execCREATE_FILE_CONF(Signal* signal); 211 void execNDB_STTORRY(Signal* signal); 212 void execNDB_STARTCONF(Signal* signal); 213 void execREAD_NODESREQ(Signal* signal); 214 void execNDB_STARTREF(Signal* signal); 215 216 void execSTOP_PERM_REF(Signal* signal); 217 void execSTOP_PERM_CONF(Signal* signal); 218 219 void execSTOP_ME_REF(Signal* signal); 220 void execSTOP_ME_CONF(Signal* signal); 221 222 void execWAIT_GCP_REF(Signal* signal); 223 void execWAIT_GCP_CONF(Signal* signal); 224 225 void execSTOP_REQ(Signal* signal); 226 void execSTOP_CONF(Signal* signal); 227 void execRESUME_REQ(Signal* signal); 228 229 void execCHANGE_NODE_STATE_CONF(Signal* signal); 230 231 void execABORT_ALL_REF(Signal* signal); 232 void execABORT_ALL_CONF(Signal* signal); 233 234 // Statement blocks 235 void beginSchemaTransLab(Signal* signal); 236 void endSchemaTransLab(Signal* signal); 237 void sendCreateTabReq(Signal* signal, const char* buffer, Uint32 bufLen); 238 void startInsertTransactions(Signal* signal); 239 void initData(Signal* signal); 240 void resetStartVariables(Signal* signal); 241 void sendCntrStartReq(Signal* signal); 242 void sendCntrStartRef(Signal*, Uint32 nodeId, CntrStartRef::ErrorCode); 243 void sendNdbSttor(Signal* signal); 244 void sendSttorry(Signal* signal); 245 246 bool trySystemRestart(Signal* signal); 247 void startWaitingNodes(Signal* signal); 248 CheckNodeGroups::Output checkNodeGroups(Signal*, const NdbNodeBitmask &); 249 250 // Generated statement blocks 251 void systemErrorLab(Signal* signal, int line); 252 253 void createHashMap(Signal*, Uint32 index); 254 void createSystableLab(Signal* signal, unsigned index); 255 void createDDObjects(Signal*, unsigned index); 256 void crSystab7Lab(Signal* signal); 257 void crSystab8Lab(Signal* signal); 258 void crSystab9Lab(Signal* signal); 259 260 void startPhase1Lab(Signal* signal); 261 void startPhase2Lab(Signal* signal); 262 void startPhase3Lab(Signal* signal); 263 void startPhase4Lab(Signal* signal); 264 void startPhase5Lab(Signal* signal); 265 // jump 2 to resync phase counters 266 void startPhase8Lab(Signal* signal); 267 void startPhase9Lab(Signal* signal); 268 void ph2ALab(Signal* signal); 269 void ph2CLab(Signal* signal); 270 void ph2ELab(Signal* signal); 271 void ph2FLab(Signal* signal); 272 void ph2GLab(Signal* signal); 273 void ph3ALab(Signal* signal); 274 void ph4ALab(Signal* signal); 275 void ph4BLab(Signal* signal); 276 void ph4CLab(Signal* signal); 277 void ph5ALab(Signal* signal); 278 void ph6ALab(Signal* signal); 279 void ph6BLab(Signal* signal); 280 void ph7ALab(Signal* signal); 281 void ph8ALab(Signal* signal); 282 283 void waitpoint41Lab(Signal* signal); 284 void waitpoint51Lab(Signal* signal); 285 void waitpoint52Lab(Signal* signal); 286 void waitpoint61Lab(Signal* signal); 287 void waitpoint71Lab(Signal* signal); 288 void waitpoint42To(Signal* signal); 289 290 /** 291 * Wait before starting sp 292 * so that all nodes in cluster is waiting for >= sp 293 */ 294 bool wait_sp(Signal*, Uint32 sp); 295 void wait_sp_rep(Signal*); 296 297 void execSTART_COPYREF(Signal*); 298 void execSTART_COPYCONF(Signal*); 299 300 void execCREATE_NODEGROUP_IMPL_REQ(Signal*); 301 void execDROP_NODEGROUP_IMPL_REQ(Signal*); 302 303 void updateNodeState(Signal* signal, const NodeState & newState) const ; 304 void getNodeGroup(Signal* signal); 305 306 // Initialisation 307 void initData(); 308 void initRecords(); 309 310 // Variables 311 /**------------------------------------------------------------------------ 312 * CONTAIN INFO ABOUT ALL NODES IN CLUSTER. NODE_PTR ARE USED AS NODE NUMBER 313 * IF THE STATE ARE ZDELETE THEN THE NODE DOESN'T EXIST. NODES ARE ALLOWED 314 * TO REGISTER (ZADD) DURING RESTART. 315 * 316 * WHEN THE SYSTEM IS RUNNING THE MASTER WILL CHECK IF ANY NODE HAS MADE 317 * A CNTR_MASTERREQ AND TAKE CARE OF THE REQUEST. 318 * TO CONFIRM THE REQ, THE MASTER DEMANDS THAT ALL RUNNING NODES HAS VOTED 319 * FOR THE NEW NODE. 320 * NODE_PTR:MASTER_REQ IS USED DURING RESTART TO LOG 321 * POSTPONED CNTR_MASTERREQ'S 322 *------------------------------------------------------------------------*/ 323 NdbBlocksRec *ndbBlocksRec; 324 325 /* 326 2.4 COMMON STORED VARIABLES 327 */ 328 UintR cgciSystab; 329 UintR ckey; 330 //UintR csystabId; 331 UintR cnoWaitrep6; 332 UintR cnoWaitrep7; 333 UintR ctcConnectionP; 334 Uint32 ctcReference; 335 UintR ctcReqInfo; 336 Uint8 ctransidPhase; 337 Uint16 cresponses; 338 339 Uint8 cstartPhase; 340 Uint16 cinternalStartphase; 341 342 bool m_cntr_start_conf; 343 Uint16 cmasterNodeId; 344 Uint16 cndbBlocksCount; 345 Uint16 cnoStartNodes; 346 UintR cnoWaitrep; 347 NodeState::StartType ctypeOfStart; 348 NodeState::StartType cdihStartType; 349 Uint16 cdynamicNodeId; 350 351 Uint32 c_fsRemoveCount; 352 Uint32 c_nodeGroup; 353 void clearFilesystem(Signal* signal); 354 void execFSREMOVECONF(Signal* signal); 355 356 NdbNodeBitmask c_allDefinedNodes; 357 NdbNodeBitmask c_clusterNodes; // All members of qmgr cluster 358 NdbNodeBitmask c_startedNodes; // All cntr started nodes 359 360 public: 361 struct StopRecord { 362 public: StopRecordNdbcntr::StopRecord363 StopRecord(Ndbcntr & _cntr) : cntr(_cntr) { 364 stopReq.senderRef = 0; 365 } 366 367 Ndbcntr & cntr; 368 StopReq stopReq; // Signal data 369 NDB_TICKS stopInitiatedTime; // When was the stop initiated 370 371 bool checkNodeFail(Signal* signal); 372 void checkTimeout(Signal* signal); 373 void checkApiTimeout(Signal* signal); 374 void checkTcTimeout(Signal* signal); 375 void checkLqhTimeout_1(Signal* signal); 376 void checkLqhTimeout_2(Signal* signal); 377 numberNdbcntr::StopRecord378 BlockNumber number() const { return cntr.number(); } jamBufferNdbcntr::StopRecord379 EmulatedJamBuffer *jamBuffer() const { return cntr.jamBuffer(); } progErrorNdbcntr::StopRecord380 void progError(int line, int cause, const char * extra) { 381 cntr.progError(line, cause, extra); 382 } 383 384 enum StopNodesStep { 385 SR_BLOCK_GCP_START_GCP = 0, 386 SR_WAIT_COMPLETE_GCP = 1, 387 SR_UNBLOCK_GCP_START_GCP = 2, 388 SR_QMGR_STOP_REQ = 3, 389 SR_WAIT_NODE_FAILURES = 4, 390 SR_CLUSTER_SHUTDOWN = 12 391 } m_state; 392 SignalCounter m_stop_req_counter; 393 }; 394 private: 395 StopRecord c_stopRec; 396 friend struct StopRecord; 397 398 struct Missra { MissraNdbcntr::Missra399 Missra(Ndbcntr & ref) : cntr(ref) { } 400 401 Uint32 currentBlockIndex; 402 Uint32 currentStartPhase; 403 Uint32 nextStartPhase[NO_OF_BLOCKS]; 404 405 void execSTART_ORD(Signal* signal); 406 void execSTTORRY(Signal* signal); 407 void sendNextSTTOR(Signal* signal); 408 void execREAD_CONFIG_CONF(Signal* signal); 409 void sendNextREAD_CONFIG_REQ(Signal* signal); 410 numberNdbcntr::Missra411 BlockNumber number() const { return cntr.number(); } jamBufferNdbcntr::Missra412 EmulatedJamBuffer *jamBuffer() const { return cntr.jamBuffer(); } progErrorNdbcntr::Missra413 void progError(int line, int cause, const char * extra) { 414 cntr.progError(line, cause, extra); 415 } 416 Ndbcntr & cntr; 417 }; 418 419 Missra c_missra; 420 friend struct Missra; 421 422 void execSTTORRY(Signal* signal); 423 void execSTART_ORD(Signal* signal); 424 void execREAD_CONFIG_CONF(Signal*); 425 }; 426 427 #endif 428