MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Ndbinit.cpp
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 as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 
19 #include <ndb_global.h>
20 
21 #include "API.hpp"
22 #include "NdbApiSignal.hpp"
23 #include "NdbImpl.hpp"
24 #include <ConfigRetriever.hpp>
25 #include <ndb_limits.h>
26 #include <NdbOut.hpp>
27 #include <NdbSleep.h>
28 #include "ObjectMap.hpp"
29 #include "NdbUtil.hpp"
30 
31 #include <EventLogger.hpp>
32 extern EventLogger * g_eventLogger;
33 
34 Ndb::Ndb( Ndb_cluster_connection *ndb_cluster_connection,
35  const char* aDataBase , const char* aSchema)
36  : theImpl(NULL)
37 {
38  DBUG_ENTER("Ndb::Ndb()");
39  DBUG_PRINT("enter",("Ndb::Ndb this: 0x%lx", (long) this));
40  setup(ndb_cluster_connection, aDataBase, aSchema);
41  DBUG_VOID_RETURN;
42 }
43 
44 void Ndb::setup(Ndb_cluster_connection *ndb_cluster_connection,
45  const char* aDataBase , const char* aSchema)
46 {
47  DBUG_ENTER("Ndb::setup");
48 
49  assert(theImpl == NULL);
50  theImpl= new NdbImpl(ndb_cluster_connection,*this);
51  theDictionary= &(theImpl->m_dictionary);
52 
53  thePreparedTransactionsArray= NULL;
54  theSentTransactionsArray= NULL;
55  theCompletedTransactionsArray= NULL;
56  theNoOfPreparedTransactions= 0;
57  theNoOfSentTransactions= 0;
58  theNoOfCompletedTransactions= 0;
59  theRemainingStartTransactions= 0;
60  theMaxNoOfTransactions= 0;
61  theMinNoOfEventsToWakeUp= 0;
62  theTransactionList= NULL;
63  theConnectionArray= NULL;
64  the_last_check_time= 0;
65  theFirstTransId= 0;
66  theRestartGCI= 0;
67  theNdbBlockNumber= -1;
68  theInitState= NotConstructed;
69 
70  theNode= 0;
71  theFirstTransId= 0;
72  theMyRef= 0;
73 
74  fullyQualifiedNames = true;
75 
76 #ifdef POORMANSPURIFY
77  cgetSignals =0;
78  cfreeSignals = 0;
79  cnewSignals = 0;
80  creleaseSignals = 0;
81 #endif
82 
83  theError.code = 0;
84 
85  theConnectionArray = new NdbConnection * [MAX_NDB_NODES];
86  theCommitAckSignal = NULL;
87  theCachedMinDbNodeVersion = 0;
88 
89  int i;
90  for (i = 0; i < MAX_NDB_NODES ; i++) {
91  theConnectionArray[i] = NULL;
92  }//forg
93  m_sys_tab_0 = NULL;
94 
95  theImpl->m_dbname.assign(aDataBase);
96  theImpl->m_schemaname.assign(aSchema);
97  theImpl->update_prefix();
98 
99  // Signal that the constructor has finished OK
100  if (theInitState == NotConstructed)
101  theInitState = NotInitialised;
102 
103  {
104  // theImpl->theWaiter.m_mutex must be set before this
105  theEventBuffer= new NdbEventBuffer(this);
106  if (theEventBuffer == NULL) {
107  ndbout_c("Failed NdbEventBuffer()");
108  exit(-1);
109  }
110  }
111 
112  theImpl->m_ndb_cluster_connection.link_ndb_object(this);
113 
114  DBUG_VOID_RETURN;
115 }
116 
117 
118 /*****************************************************************************
119  * ~Ndb();
120  *
121  * Remark: Disconnect with the database.
122  *****************************************************************************/
123 Ndb::~Ndb()
124 {
125  DBUG_ENTER("Ndb::~Ndb()");
126  DBUG_PRINT("enter",("this: 0x%lx", (long) this));
127 
128  if (m_sys_tab_0)
129  getDictionary()->removeTableGlobal(*m_sys_tab_0, 0);
130 
131  if (theImpl->m_ev_op != 0)
132  {
133  g_eventLogger->warning("Deleting Ndb-object with NdbEventOperation still"
134  " active");
135  printf("this: %p NdbEventOperation(s): ", this);
136  for (NdbEventOperationImpl *op= theImpl->m_ev_op; op; op=op->m_next)
137  {
138  printf("%p ", op);
139  }
140  printf("\n");
141  fflush(stdout);
142  }
143 
144  assert(theImpl->m_ev_op == 0); // user should return NdbEventOperation's
145  for (NdbEventOperationImpl *op= theImpl->m_ev_op; op; op=op->m_next)
146  {
147  if (op->m_state == NdbEventOperation::EO_EXECUTING && op->stop())
148  g_eventLogger->error("stopping NdbEventOperation failed in Ndb destructor");
149  op->m_magic_number= 0;
150  }
151  doDisconnect();
152 
153  /* Disconnect from transporter to stop signals from coming in */
154  theImpl->close();
155 
156  delete theEventBuffer;
157 
158  releaseTransactionArrays();
159 
160  delete []theConnectionArray;
161  if(theCommitAckSignal != NULL){
162  delete theCommitAckSignal;
163  theCommitAckSignal = NULL;
164  }
165 
166  theImpl->m_ndb_cluster_connection.unlink_ndb_object(this);
167 
168  delete theImpl;
169 
170 #ifdef POORMANSPURIFY
171 #ifdef POORMANSGUI
172  ndbout << "cnewSignals=" << cnewSignals << endl;
173  ndbout << "cfreeSignals=" << cfreeSignals << endl;
174  ndbout << "cgetSignals=" << cgetSignals << endl;
175  ndbout << "creleaseSignals=" << creleaseSignals << endl;
176 #endif
177  // Poor mans purifier
178  assert(cnewSignals == cfreeSignals);
179  assert(cgetSignals == creleaseSignals);
180 #endif
181  DBUG_VOID_RETURN;
182 }
183 
184 NdbWaiter::NdbWaiter(trp_client* clnt)
185  : m_clnt(clnt)
186 {
187  m_node = 0;
188  m_state = NO_WAIT;
189 }
190 
191 NdbWaiter::~NdbWaiter()
192 {
193 }
194 
195 NdbImpl::NdbImpl(Ndb_cluster_connection *ndb_cluster_connection,
196  Ndb& ndb)
197  : m_ndb(ndb),
198  m_next_ndb_object(0),
199  m_prev_ndb_object(0),
200  m_ndb_cluster_connection(ndb_cluster_connection->m_impl),
201  m_transporter_facade(ndb_cluster_connection->m_impl.m_transporter_facade),
202  m_dictionary(ndb),
203  theCurrentConnectIndex(0),
204  theNdbObjectIdMap(1024,1024),
205  theNoOfDBnodes(0),
206  theWaiter(this),
207  m_ev_op(0),
208  customDataPtr(0)
209 {
210  int i;
211  for (i = 0; i < MAX_NDB_NODES; i++) {
212  the_release_ind[i] = 0;
213  }
214  m_optimized_node_selection=
215  m_ndb_cluster_connection.m_optimized_node_selection;
216 
217  m_systemPrefix.assfmt("%s%c%s%c", NDB_SYSTEM_DATABASE, table_name_separator,
218  NDB_SYSTEM_SCHEMA, table_name_separator);
219 
220  forceShortRequests = false;
221  const char* f= getenv("NDB_FORCE_SHORT_REQUESTS");
222  if (f != 0 && *f != 0 && *f != '0' && *f != 'n' && *f != 'N')
223  forceShortRequests = true;
224 
225  for (i = 0; i < Ndb::NumClientStatistics; i++)
226  clientStats[i] = 0;
227 }
228 
229 NdbImpl::~NdbImpl()
230 {
231 }
232