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 DBACC_C
28 #include "Dbacc.hpp"
29 
30 #define DEBUG(x) { ndbout << "ACC::" << x << endl; }
31 
initData()32 void Dbacc::initData()
33 {
34   cdirarraysize = ZDIRARRAY;
35   coprecsize = ZOPRECSIZE;
36   cpagesize = ZPAGESIZE;
37   ctablesize = ZTABLESIZE;
38   cfragmentsize = ZFRAGMENTSIZE;
39   cdirrangesize = ZDIRRANGESIZE;
40   coverflowrecsize = ZOVERFLOWRECSIZE;
41   cscanRecSize = ZSCAN_REC_SIZE;
42 
43 
44   dirRange = 0;
45   directoryarray = 0;
46   fragmentrec = 0;
47   operationrec = 0;
48   overflowRecord = 0;
49   page8 = 0;
50   scanRec = 0;
51   tabrec = 0;
52 
53   cnoOfAllocatedPagesMax = cnoOfAllocatedPages = cpagesize = cpageCount = 0;
54   // Records with constant sizes
55 
56   RSS_OP_COUNTER_INIT(cnoOfFreeFragrec);
57 
58 }//Dbacc::initData()
59 
initRecords()60 void Dbacc::initRecords()
61 {
62   {
63     AllocChunk chunks[16];
64     const Uint32 pages = (cpagesize + 3) / 4;
65     const Uint32 chunkcnt = allocChunks(chunks, 16, RT_DBTUP_PAGE, pages,
66                                         CFG_DB_INDEX_MEM);
67 
68     /**
69      * Set base ptr
70      */
71     Ptr<GlobalPage> pagePtr;
72     m_shared_page_pool.getPtr(pagePtr, chunks[0].ptrI);
73     page8 = (Page8*)pagePtr.p;
74 
75     /**
76      * 1) Build free-list per chunk
77      * 2) Add chunks to cfirstfreepage-list
78      */
79     cfirstfreepage = RNIL;
80     cpagesize = 0;
81     cpageCount = 0;
82     for (Int32 i = chunkcnt - 1; i >= 0; i--)
83     {
84       Ptr<GlobalPage> pagePtr;
85       m_shared_page_pool.getPtr(pagePtr, chunks[i].ptrI);
86       const Uint32 cnt = 4 * chunks[i].cnt; // 4 8k per 32k
87       Page8* base = (Page8*)pagePtr.p;
88       ndbrequire(base >= page8);
89       const Uint32 ptrI = Uint32(base - page8);
90       for (Uint32 j = 0; j < cnt; j++)
91       {
92         refresh_watch_dog();
93         base[j].word32[0] = ptrI + j + 1;
94       }
95 
96       base[cnt-1].word32[0] = cfirstfreepage;
97       cfirstfreepage = ptrI;
98 
99       cpageCount += cnt;
100       if (ptrI + cnt > cpagesize)
101         cpagesize = ptrI + cnt;
102     }
103   }
104 
105   operationrec = (Operationrec*)allocRecord("Operationrec",
106 					    sizeof(Operationrec),
107 					    coprecsize);
108 
109   dirRange = (DirRange*)allocRecord("DirRange",
110 				    sizeof(DirRange),
111 				    cdirrangesize);
112 
113   directoryarray = (Directoryarray*)allocRecord("Directoryarray",
114 						sizeof(Directoryarray),
115 						cdirarraysize);
116 
117   fragmentrec = (Fragmentrec*)allocRecord("Fragmentrec",
118 					  sizeof(Fragmentrec),
119 					  cfragmentsize);
120 
121   overflowRecord = (OverflowRecord*)allocRecord("OverflowRecord",
122 						sizeof(OverflowRecord),
123 						coverflowrecsize);
124 
125   scanRec = (ScanRec*)allocRecord("ScanRec",
126 				  sizeof(ScanRec),
127 				  cscanRecSize);
128 
129   tabrec = (Tabrec*)allocRecord("Tabrec",
130 				sizeof(Tabrec),
131 				ctablesize);
132 }//Dbacc::initRecords()
133 
Dbacc(Block_context & ctx,Uint32 instanceNumber)134 Dbacc::Dbacc(Block_context& ctx, Uint32 instanceNumber):
135   SimulatedBlock(DBACC, ctx, instanceNumber),
136   c_tup(0)
137 {
138   BLOCK_CONSTRUCTOR(Dbacc);
139 
140   // Transit signals
141   addRecSignal(GSN_DUMP_STATE_ORD, &Dbacc::execDUMP_STATE_ORD);
142   addRecSignal(GSN_DEBUG_SIG, &Dbacc::execDEBUG_SIG);
143   addRecSignal(GSN_CONTINUEB, &Dbacc::execCONTINUEB);
144   addRecSignal(GSN_ACC_CHECK_SCAN, &Dbacc::execACC_CHECK_SCAN);
145   addRecSignal(GSN_EXPANDCHECK2, &Dbacc::execEXPANDCHECK2);
146   addRecSignal(GSN_SHRINKCHECK2, &Dbacc::execSHRINKCHECK2);
147   addRecSignal(GSN_READ_PSEUDO_REQ, &Dbacc::execREAD_PSEUDO_REQ);
148 
149   // Received signals
150   addRecSignal(GSN_STTOR, &Dbacc::execSTTOR);
151   addRecSignal(GSN_ACCKEYREQ, &Dbacc::execACCKEYREQ);
152   addRecSignal(GSN_ACCSEIZEREQ, &Dbacc::execACCSEIZEREQ);
153   addRecSignal(GSN_ACCFRAGREQ, &Dbacc::execACCFRAGREQ);
154   addRecSignal(GSN_NEXT_SCANREQ, &Dbacc::execNEXT_SCANREQ);
155   addRecSignal(GSN_ACC_ABORTREQ, &Dbacc::execACC_ABORTREQ);
156   addRecSignal(GSN_ACC_SCANREQ, &Dbacc::execACC_SCANREQ);
157   addRecSignal(GSN_ACCMINUPDATE, &Dbacc::execACCMINUPDATE);
158   addRecSignal(GSN_ACC_COMMITREQ, &Dbacc::execACC_COMMITREQ);
159   addRecSignal(GSN_ACC_TO_REQ, &Dbacc::execACC_TO_REQ);
160   addRecSignal(GSN_ACC_LOCKREQ, &Dbacc::execACC_LOCKREQ);
161   addRecSignal(GSN_NDB_STTOR, &Dbacc::execNDB_STTOR);
162   addRecSignal(GSN_DROP_TAB_REQ, &Dbacc::execDROP_TAB_REQ);
163   addRecSignal(GSN_READ_CONFIG_REQ, &Dbacc::execREAD_CONFIG_REQ, true);
164   addRecSignal(GSN_DROP_FRAG_REQ, &Dbacc::execDROP_FRAG_REQ);
165 
166   addRecSignal(GSN_DBINFO_SCANREQ, &Dbacc::execDBINFO_SCANREQ);
167 
168   initData();
169 
170 #ifdef VM_TRACE
171   {
172     void* tmp[] = { &expDirRangePtr,
173 		    &gnsDirRangePtr,
174 		    &newDirRangePtr,
175 		    &rdDirRangePtr,
176 		    &nciOverflowrangeptr,
177                     &expDirptr,
178                     &rdDirptr,
179                     &sdDirptr,
180                     &nciOverflowDirptr,
181                     &fragrecptr,
182                     &operationRecPtr,
183                     &idrOperationRecPtr,
184                     &mlpqOperPtr,
185                     &queOperPtr,
186                     &readWriteOpPtr,
187                     &iopOverflowRecPtr,
188                     &tfoOverflowRecPtr,
189                     &porOverflowRecPtr,
190                     &priOverflowRecPtr,
191                     &rorOverflowRecPtr,
192                     &sorOverflowRecPtr,
193                     &troOverflowRecPtr,
194                     &ancPageptr,
195                     &colPageptr,
196                     &ccoPageptr,
197                     &datapageptr,
198                     &delPageptr,
199                     &excPageptr,
200                     &expPageptr,
201                     &gdiPageptr,
202                     &gePageptr,
203                     &gflPageptr,
204                     &idrPageptr,
205                     &ilcPageptr,
206                     &inpPageptr,
207                     &iopPageptr,
208                     &lastPageptr,
209                     &lastPrevpageptr,
210                     &lcnPageptr,
211                     &lcnCopyPageptr,
212                     &lupPageptr,
213                     &ciPageidptr,
214                     &gsePageidptr,
215                     &isoPageptr,
216                     &nciPageidptr,
217                     &rsbPageidptr,
218                     &rscPageidptr,
219                     &slPageidptr,
220                     &sscPageidptr,
221                     &rlPageptr,
222                     &rlpPageptr,
223                     &ropPageptr,
224                     &rpPageptr,
225                     &slPageptr,
226                     &spPageptr,
227                     &scanPtr,
228                     &tabptr
229     };
230     init_globals_list(tmp, sizeof(tmp)/sizeof(tmp[0]));
231   }
232 #endif
233 }//Dbacc::Dbacc()
234 
~Dbacc()235 Dbacc::~Dbacc()
236 {
237   deallocRecord((void **)&dirRange, "DirRange",
238 		sizeof(DirRange),
239 		cdirrangesize);
240 
241   deallocRecord((void **)&directoryarray, "Directoryarray",
242 		sizeof(Directoryarray),
243 		cdirarraysize);
244 
245   deallocRecord((void **)&fragmentrec, "Fragmentrec",
246 		sizeof(Fragmentrec),
247 		cfragmentsize);
248 
249   deallocRecord((void **)&operationrec, "Operationrec",
250 		sizeof(Operationrec),
251 		coprecsize);
252 
253   deallocRecord((void **)&overflowRecord, "OverflowRecord",
254 		sizeof(OverflowRecord),
255 		coverflowrecsize);
256 
257   deallocRecord((void **)&scanRec, "ScanRec",
258 		sizeof(ScanRec),
259 		cscanRecSize);
260 
261   deallocRecord((void **)&tabrec, "Tabrec",
262 		sizeof(Tabrec),
263 		ctablesize);
264   }//Dbacc::~Dbacc()
265 
266 BLOCK_FUNCTIONS(Dbacc)
267