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 
26 
27 #define QMGR_C
28 #include "Qmgr.hpp"
29 
30 #define DEBUG(x) { ndbout << "Qmgr::" << x << endl; }
31 
32 
initData()33 void Qmgr::initData()
34 {
35   creadyDistCom = ZFALSE;
36 
37   // Records with constant sizes
38   nodeRec = new NodeRec[MAX_NODES];
39   for (Uint32 i = 0; i<MAX_NODES; i++)
40   {
41     nodeRec[i].m_secret = 0;
42   }
43 
44   cnoCommitFailedNodes = 0;
45   c_maxDynamicId = 0;
46   c_clusterNodes.clear();
47   c_stopReq.senderRef = 0;
48 
49   /**
50    * Check sanity for NodeVersion
51    */
52   ndbrequire((Uint32)NodeInfo::DB == 0);
53   ndbrequire((Uint32)NodeInfo::API == 1);
54   ndbrequire((Uint32)NodeInfo::MGM == 2);
55 
56   m_micro_gcp_enabled = false;
57   m_hb_order_config_used = false;
58 
59   NodeRecPtr nodePtr;
60   nodePtr.i = getOwnNodeId();
61   ptrAss(nodePtr, nodeRec);
62   nodePtr.p->blockRef = reference();
63 
64   c_connectedNodes.set(getOwnNodeId());
65   setNodeInfo(getOwnNodeId()).m_version = NDB_VERSION;
66 
67 
68   /**
69    * Timeouts
70    */
71   const ndb_mgm_configuration_iterator * p =
72     m_ctx.m_config.getOwnConfigIterator();
73   ndbrequire(p != 0);
74 
75   Uint32 hbDBAPI = 1500;
76   ndb_mgm_get_int_parameter(p, CFG_DB_API_HEARTBEAT_INTERVAL, &hbDBAPI);
77 
78   setHbApiDelay(hbDBAPI);
79 
80 #ifdef ERROR_INSERT
81   nodeFailCount = 0;
82 #endif
83 
84   cfailureNr = 1;
85   ccommitFailureNr = 1;
86   cprepareFailureNr = 1;
87   cnoFailedNodes = 0;
88   cnoPrepFailedNodes = 0;
89   creadyDistCom = ZFALSE;
90   cpresident = ZNIL;
91   c_start.m_president_candidate = ZNIL;
92   c_start.m_president_candidate_gci = 0;
93   cpdistref = 0;
94   cneighbourh = ZNIL;
95   cneighbourl = ZNIL;
96   cdelayRegreq = ZDELAY_REGREQ;
97   cactivateApiCheck = 0;
98   c_allow_api_connect = 0;
99   ctoStatus = Q_NOT_ACTIVE;
100   clatestTransactionCheck = 0;
101 }//Qmgr::initData()
102 
initRecords()103 void Qmgr::initRecords()
104 {
105   // Records with dynamic sizes
106 }//Qmgr::initRecords()
107 
Qmgr(Block_context & ctx)108 Qmgr::Qmgr(Block_context& ctx)
109   : SimulatedBlock(QMGR, ctx)
110 {
111   BLOCK_CONSTRUCTOR(Qmgr);
112 
113   // Transit signals
114   addRecSignal(GSN_DUMP_STATE_ORD, &Qmgr::execDUMP_STATE_ORD);
115   addRecSignal(GSN_STOP_REQ, &Qmgr::execSTOP_REQ);
116   addRecSignal(GSN_DEBUG_SIG, &Qmgr::execDEBUG_SIG);
117   addRecSignal(GSN_CONTINUEB, &Qmgr::execCONTINUEB);
118   addRecSignal(GSN_CM_HEARTBEAT, &Qmgr::execCM_HEARTBEAT);
119   addRecSignal(GSN_CM_ADD, &Qmgr::execCM_ADD);
120   addRecSignal(GSN_CM_ACKADD, &Qmgr::execCM_ACKADD);
121   addRecSignal(GSN_CM_REGREQ, &Qmgr::execCM_REGREQ);
122   addRecSignal(GSN_CM_REGCONF, &Qmgr::execCM_REGCONF);
123   addRecSignal(GSN_CM_REGREF, &Qmgr::execCM_REGREF);
124   addRecSignal(GSN_CM_NODEINFOREQ, &Qmgr::execCM_NODEINFOREQ);
125   addRecSignal(GSN_CM_NODEINFOCONF, &Qmgr::execCM_NODEINFOCONF);
126   addRecSignal(GSN_CM_NODEINFOREF, &Qmgr::execCM_NODEINFOREF);
127   addRecSignal(GSN_PREP_FAILREQ, &Qmgr::execPREP_FAILREQ);
128   addRecSignal(GSN_PREP_FAILCONF, &Qmgr::execPREP_FAILCONF);
129   addRecSignal(GSN_PREP_FAILREF, &Qmgr::execPREP_FAILREF);
130   addRecSignal(GSN_COMMIT_FAILREQ, &Qmgr::execCOMMIT_FAILREQ);
131   addRecSignal(GSN_COMMIT_FAILCONF, &Qmgr::execCOMMIT_FAILCONF);
132   addRecSignal(GSN_FAIL_REP, &Qmgr::execFAIL_REP);
133   addRecSignal(GSN_PRES_TOREQ, &Qmgr::execPRES_TOREQ);
134   addRecSignal(GSN_PRES_TOCONF, &Qmgr::execPRES_TOCONF);
135 
136   // Received signals
137   addRecSignal(GSN_CONNECT_REP, &Qmgr::execCONNECT_REP);
138   addRecSignal(GSN_NDB_FAILCONF, &Qmgr::execNDB_FAILCONF);
139   addRecSignal(GSN_NF_COMPLETEREP, &Qmgr::execNF_COMPLETEREP);
140   addRecSignal(GSN_READ_CONFIG_REQ, &Qmgr::execREAD_CONFIG_REQ);
141   addRecSignal(GSN_STTOR, &Qmgr::execSTTOR);
142   addRecSignal(GSN_CLOSE_COMCONF, &Qmgr::execCLOSE_COMCONF);
143   addRecSignal(GSN_API_REGREQ, &Qmgr::execAPI_REGREQ);
144   addRecSignal(GSN_API_VERSION_REQ, &Qmgr::execAPI_VERSION_REQ);
145   addRecSignal(GSN_DISCONNECT_REP, &Qmgr::execDISCONNECT_REP);
146   addRecSignal(GSN_API_FAILREQ, &Qmgr::execAPI_FAILREQ);
147   addRecSignal(GSN_API_FAILCONF, &Qmgr::execAPI_FAILCONF);
148   addRecSignal(GSN_READ_NODESREQ, &Qmgr::execREAD_NODESREQ);
149   addRecSignal(GSN_API_BROADCAST_REP,  &Qmgr::execAPI_BROADCAST_REP);
150 
151   addRecSignal(GSN_NODE_FAILREP, &Qmgr::execNODE_FAILREP);
152   addRecSignal(GSN_ALLOC_NODEID_REQ,  &Qmgr::execALLOC_NODEID_REQ);
153   addRecSignal(GSN_ALLOC_NODEID_CONF,  &Qmgr::execALLOC_NODEID_CONF);
154   addRecSignal(GSN_ALLOC_NODEID_REF,  &Qmgr::execALLOC_NODEID_REF);
155   addRecSignal(GSN_ENABLE_COMCONF,  &Qmgr::execENABLE_COMCONF);
156 
157   // Arbitration signals
158   addRecSignal(GSN_ARBIT_PREPREQ, &Qmgr::execARBIT_PREPREQ);
159   addRecSignal(GSN_ARBIT_PREPCONF, &Qmgr::execARBIT_PREPCONF);
160   addRecSignal(GSN_ARBIT_PREPREF, &Qmgr::execARBIT_PREPREF);
161   addRecSignal(GSN_ARBIT_STARTCONF, &Qmgr::execARBIT_STARTCONF);
162   addRecSignal(GSN_ARBIT_STARTREF, &Qmgr::execARBIT_STARTREF);
163   addRecSignal(GSN_ARBIT_CHOOSECONF, &Qmgr::execARBIT_CHOOSECONF);
164   addRecSignal(GSN_ARBIT_CHOOSEREF, &Qmgr::execARBIT_CHOOSEREF);
165   addRecSignal(GSN_ARBIT_STOPREP, &Qmgr::execARBIT_STOPREP);
166 
167   addRecSignal(GSN_READ_NODESREF, &Qmgr::execREAD_NODESREF);
168   addRecSignal(GSN_READ_NODESCONF, &Qmgr::execREAD_NODESCONF);
169 
170   addRecSignal(GSN_DIH_RESTARTREF, &Qmgr::execDIH_RESTARTREF);
171   addRecSignal(GSN_DIH_RESTARTCONF, &Qmgr::execDIH_RESTARTCONF);
172   addRecSignal(GSN_NODE_VERSION_REP, &Qmgr::execNODE_VERSION_REP);
173   addRecSignal(GSN_START_ORD, &Qmgr::execSTART_ORD);
174 
175   addRecSignal(GSN_UPGRADE_PROTOCOL_ORD, &Qmgr::execUPGRADE_PROTOCOL_ORD);
176 
177   // Connectivity check signals
178   addRecSignal(GSN_NODE_PING_REQ, &Qmgr::execNODE_PINGREQ);
179   addRecSignal(GSN_NODE_PING_CONF, &Qmgr::execNODE_PINGCONF);
180 
181   initData();
182 }//Qmgr::Qmgr()
183 
~Qmgr()184 Qmgr::~Qmgr()
185 {
186   delete []nodeRec;
187 }//Qmgr::~Qmgr()
188 
189 
190 BLOCK_FUNCTIONS(Qmgr)
191