MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimBlockList.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 #include "SimBlockList.hpp"
19 #include <Emulator.hpp>
20 #include <SimulatedBlock.hpp>
21 #include <Cmvmi.hpp>
22 #include <Ndbfs.hpp>
23 #include <Dbacc.hpp>
24 #include <Dbdict.hpp>
25 #include <Dbdih.hpp>
26 #include <Dblqh.hpp>
27 #include <Dbspj.hpp>
28 #include <Dbtc.hpp>
29 #include <Dbtup.hpp>
30 #include <Ndbcntr.hpp>
31 #include <Qmgr.hpp>
32 #include <Trix.hpp>
33 #include <Backup.hpp>
34 #include <DbUtil.hpp>
35 #include <Suma.hpp>
36 #include <Dbtux.hpp>
37 #include <tsman.hpp>
38 #include <lgman.hpp>
39 #include <pgman.hpp>
40 #include <restore.hpp>
41 #include <Dbinfo.hpp>
42 #include <NdbEnv.h>
43 #include <LocalProxy.hpp>
44 #include <DblqhProxy.hpp>
45 #include <DbspjProxy.hpp>
46 #include <DbaccProxy.hpp>
47 #include <DbtupProxy.hpp>
48 #include <DbtuxProxy.hpp>
49 #include <BackupProxy.hpp>
50 #include <RestoreProxy.hpp>
51 #include <PgmanProxy.hpp>
52 #include <mt.hpp>
53 
54 #ifndef VM_TRACE
55 #define NEW_BLOCK(B) new B
56 #else
57 enum SIMBLOCKLIST_DUMMY { A_VALUE = 0 };
58 
59 void * operator new (size_t sz, SIMBLOCKLIST_DUMMY dummy){
60  char * tmp = (char *)malloc(sz);
61  if (!tmp)
62  abort();
63 
64 #ifndef NDB_PURIFY
65 #ifdef VM_TRACE
66  const int initValue = 0xf3;
67 #else
68  const int initValue = 0x0;
69 #endif
70 
71  const int p = (sz / 4096);
72  const int r = (sz % 4096);
73 
74  for(int i = 0; i<p; i++)
75  memset(tmp+(i*4096), initValue, 4096);
76 
77  if(r > 0)
78  memset(tmp+p*4096, initValue, r);
79 
80 #endif
81 
82  return tmp;
83 }
84 #define NEW_BLOCK(B) new(A_VALUE) B
85 #endif
86 
87 void
88 SimBlockList::load(EmulatorData& data){
89  noOfBlocks = NO_OF_BLOCKS;
90  theList = new SimulatedBlock * [noOfBlocks];
91  if (!theList)
92  {
93  ERROR_SET(fatal, NDBD_EXIT_MEMALLOC,
94  "Failed to create the block list", "");
95  }
96 
97  Block_context ctx(*data.theConfiguration, *data.m_mem_manager);
98 
99  SimulatedBlock * fs = 0;
100  {
101  Uint32 dl;
102  const ndb_mgm_configuration_iterator * p =
103  ctx.m_config.getOwnConfigIterator();
104  if(p && !ndb_mgm_get_int_parameter(p, CFG_DB_DISCLESS, &dl) && dl){
105  fs = NEW_BLOCK(VoidFs)(ctx);
106  } else {
107  fs = NEW_BLOCK(Ndbfs)(ctx);
108  }
109  }
110 
111  const bool mtLqh = globalData.isNdbMtLqh;
112 
113  if (!mtLqh)
114  theList[0] = NEW_BLOCK(Pgman)(ctx);
115  else
116  theList[0] = NEW_BLOCK(PgmanProxy)(ctx);
117  theList[1] = NEW_BLOCK(Lgman)(ctx);
118  theList[2] = NEW_BLOCK(Tsman)(ctx);
119  if (!mtLqh)
120  theList[3] = NEW_BLOCK(Dbacc)(ctx);
121  else
122  theList[3] = NEW_BLOCK(DbaccProxy)(ctx);
123  theList[4] = NEW_BLOCK(Cmvmi)(ctx);
124  theList[5] = fs;
125  theList[6] = NEW_BLOCK(Dbdict)(ctx);
126  theList[7] = NEW_BLOCK(Dbdih)(ctx);
127  if (!mtLqh)
128  theList[8] = NEW_BLOCK(Dblqh)(ctx);
129  else
130  theList[8] = NEW_BLOCK(DblqhProxy)(ctx);
131  theList[9] = NEW_BLOCK(Dbtc)(ctx);
132  if (!mtLqh)
133  theList[10] = NEW_BLOCK(Dbtup)(ctx);
134  else
135  theList[10] = NEW_BLOCK(DbtupProxy)(ctx);
136  theList[11] = NEW_BLOCK(Ndbcntr)(ctx);
137  theList[12] = NEW_BLOCK(Qmgr)(ctx);
138  theList[13] = NEW_BLOCK(Trix)(ctx);
139  if (!mtLqh)
140  theList[14] = NEW_BLOCK(Backup)(ctx);
141  else
142  theList[14] = NEW_BLOCK(BackupProxy)(ctx);
143  theList[15] = NEW_BLOCK(DbUtil)(ctx);
144  theList[16] = NEW_BLOCK(Suma)(ctx);
145  if (!mtLqh)
146  theList[17] = NEW_BLOCK(Dbtux)(ctx);
147  else
148  theList[17] = NEW_BLOCK(DbtuxProxy)(ctx);
149  if (!mtLqh)
150  theList[18] = NEW_BLOCK(Restore)(ctx);
151  else
152  theList[18] = NEW_BLOCK(RestoreProxy)(ctx);
153  theList[19] = NEW_BLOCK(Dbinfo)(ctx);
154  theList[20] = NEW_BLOCK(Dbspj)(ctx);
155  assert(NO_OF_BLOCKS == 21);
156 
157  if (globalData.isNdbMt) {
158  add_main_thr_map();
159  if (globalData.isNdbMtLqh) {
160  for (int i = 0; i < noOfBlocks; i++)
161  theList[i]->loadWorkers();
162  }
163  finalize_thr_map();
164  }
165 
166  // Check that all blocks could be created
167  for (int i = 0; i < noOfBlocks; i++)
168  {
169  if (!theList[i])
170  {
171  ERROR_SET(fatal, NDBD_EXIT_MEMALLOC,
172  "Failed to create block", "");
173  }
174  }
175 }
176 
177 void
178 SimBlockList::unload(){
179  if(theList != 0){
180  for(int i = 0; i<noOfBlocks; i++){
181  if(theList[i] != 0){
182 #ifdef VM_TRACE
183  theList[i]->~SimulatedBlock();
184  free(theList[i]);
185 #else
186  delete(theList[i]);
187 #endif
188  theList[i] = 0;
189  }
190  }
191  delete [] theList;
192  theList = 0;
193  noOfBlocks = 0;
194  }
195 }