MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DbUtil.hpp
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 #ifndef DBUTIL_H
19 #define DBUTIL_H
20 
21 #include <ndb_limits.h>
22 #include <SimulatedBlock.hpp>
23 #include <NodeBitmask.hpp>
24 
25 #include <ArrayPool.hpp>
26 #include <SLList.hpp>
27 #include <DLList.hpp>
28 #include <DLFifoList.hpp>
29 #include <DataBuffer.hpp>
30 #include <KeyTable.hpp>
31 
32 #include <signaldata/KeyInfo.hpp>
33 #include <signaldata/AttrInfo.hpp>
34 #include <signaldata/TcKeyReq.hpp>
35 #include <signaldata/UtilPrepare.hpp>
36 #include <signaldata/UtilExecute.hpp>
37 #include <signaldata/UtilLock.hpp>
38 #include <SimpleProperties.hpp>
39 #include <Array.hpp>
40 
41 #include <LockQueue.hpp>
42 
43 #define UTIL_WORDS_PER_PAGE 1023
44 
64 class DbUtil : public SimulatedBlock
65 {
66 public:
67  DbUtil(Block_context& ctx);
68  virtual ~DbUtil();
69  BLOCK_DEFINES(DbUtil);
70 
71 protected:
75  void execREAD_CONFIG_REQ(Signal* signal);
76  void execSTTOR(Signal* signal);
77  void execNDB_STTOR(Signal* signal);
78  void execDUMP_STATE_ORD(Signal* signal);
79  void execDBINFO_SCANREQ(Signal* signal);
80  void execCONTINUEB(Signal* signal);
81  void execNODE_FAILREP(Signal* signal);
82 
86  void execUTIL_SEQUENCE_REQ(Signal* signal);
87  void execUTIL_SEQUENCE_REF(Signal* signal);
88  void execUTIL_SEQUENCE_CONF(Signal* signal);
89 
93  void execUTIL_PREPARE_REQ(Signal* signal);
94  void execUTIL_PREPARE_CONF(Signal* signal);
95  void execUTIL_PREPARE_REF(Signal* signal);
96 
100  void execUTIL_DELETE_REQ(Signal* signal);
101  void execUTIL_DELETE_REF(Signal* signal);
102  void execUTIL_DELETE_CONF(Signal* signal);
103 
107  void execUTIL_EXECUTE_REQ(Signal* signal);
108  void execUTIL_EXECUTE_REF(Signal* signal);
109  void execUTIL_EXECUTE_CONF(Signal* signal);
110 
114  void execUTIL_RELEASE_REQ(Signal* signal);
115  void execUTIL_RELEASE_CONF(Signal* signal);
116  void execUTIL_RELEASE_REF(Signal* signal);
117 
121  void execTCSEIZECONF(Signal* signal);
122  void execTCKEYCONF(Signal* signal);
123  void execTCKEYREF(Signal* signal);
124  void execTCROLLBACKREP(Signal* signal);
125  void execTCKEY_FAILCONF(Signal* signal);
126  void execTCKEY_FAILREF(Signal* signal);
127  void execTRANSID_AI(Signal* signal);
128 
132  void execGET_TABINFOREF(Signal*);
133  void execGET_TABINFO_CONF(Signal* signal);
134 
135 private:
136 
137 public:
138  struct PreparedOperation;
139 
141  typedef KeyInfoBuffer::ConstDataBufferIterator KeyInfoIterator;
143  typedef AttrInfoBuffer::ConstDataBufferIterator AttrInfoIterator;
147 
152  struct Page32 {
153  union {
154  Uint32 data[UTIL_WORDS_PER_PAGE];
155  Uint32 chunkSize;
156  Uint32 nextChunk;
157  Uint32 lastChunk;
158  };
159  Uint32 nextPool; // Note: This used as data when seized
160  };
161 
170  struct Prepare {
171  Prepare(ArrayPool<Page32> & ap) : preparePages(ap) {}
172 
173  /*** Client info ***/
174  Uint32 clientRef;
175  Uint32 clientData;
176  Uint32 schemaTransId;
177 
187  Uint32 prepDataLen;
188  Array<Page32> preparePages;
189 
190  /*** PreparedOperation constructed in Prepare phase ***/
191  Ptr<PreparedOperation> prepOpPtr;
192 
193  union {
194  Uint32 nextPool;
195  Uint32 nextList;
196  };
197  Uint32 prevList;
198 
199  void print() const {
200  ndbout << "[-Prepare-" << endl
201  << " clientRef: " << clientRef
202  << ", clientData: " << clientData
203  << "]" << endl;
204  }
205  };
206 
218  releaseFlag(false), attrMapping(am), attrInfo(ai), rsInfo(rs)
219  {
220  pkBitmask.clear();
221  }
222 
223  /*** Various Operation Info ***/
224  Uint32 rsLen; // Size of result set
225  Uint32 noOfKeyAttr; // Number of key attributes
226  Uint32 noOfAttr; // Number of attributes
227  bool releaseFlag; // flag if operation release after completion
228 
243 
244  /*** First signal in tckeyreq train ***/
245  Uint32 tckeyLen; // TcKeyReq total signal length
246  Uint32 keyDataPos; // Where to store keydata[] in tckey signal
247  // (in #words from base in tckey signal)
248  TcKeyReq tckey; // Signaldata for first signal in train
249 
250  /*** Attrinfo signals sent to TC (part of tckeyreq train) ***/
251  AttrInfoBuffer attrInfo;
252 
253  /*** Result of executed operation ***/
254  ResultSetInfoBuffer rsInfo;
255 
257 
258  union {
259  Uint32 nextPool;
260  Uint32 nextList;
261  };
262  Uint32 prevList;
263 
264  void print() const {
265  ndbout << "[-PreparedOperation-" << endl
266  << ", rsLen: " << rsLen
267  << ", noOfKeyAttr: " << noOfKeyAttr
268  << ", noOfAttr: " << noOfAttr
269  << ", tckeyLen: " << tckeyLen
270  << ", keyDataPos: " << keyDataPos << endl
271  << "-AttrMapping- (AttrId, KeyPos)-pairs "
272  << "(Pos=3fff if non-key attr):" << endl;
273  attrMapping.print(stdout);
274  ndbout << "[-tckey- ";
275  printTCKEYREQ(stdout, (Uint32*)&tckey, 8, 0);
276  ndbout << "[-attrInfo- ";
277  attrInfo.print(stdout);
278  ndbout << "[-rsInfo- ";
279  rsInfo.print(stdout);
280  ndbout << "]]]]" << endl;
281  }
282  };
283 
288  struct Operation {
292  prepOp_i(RNIL), keyInfo(ki), attrInfo(ai), rs(_rs) {}
293 
294  PreparedOperation * prepOp;
295  Uint32 prepOp_i;
296  KeyInfoBuffer keyInfo;
297  AttrInfoBuffer attrInfo;
298  ResultSetBuffer rs;
299 
300  Uint32 transPtrI;
301 
302  Uint32 m_scanTakeOver;
303  Uint32 rsRecv;
304  Uint32 rsExpect;
305  inline bool complete() const { return rsRecv == rsExpect; }
306 
307  union {
308  Uint32 nextPool;
309  Uint32 nextList;
310  };
311 
312  void print() const {
313  ndbout << "[-Operation-" << endl
314  << " transPtrI: " << transPtrI
315  << ", rsRecv: " << rsRecv;
316  ndbout << "[-PreparedOperation-" << endl;
317  prepOp->print();
318  ndbout << "[-keyInfo-" << endl;
319  keyInfo.print(stdout);
320  ndbout << "[-attrInfo-" << endl;
321  attrInfo.print(stdout);
322  ndbout << "]]" << endl;
323  }
324  };
325 
330  struct Transaction {
332  executePages(ap), operations(op) {}
333 
334  Uint32 clientRef;
335  Uint32 clientData;
336  Array<Page32> executePages;
337 
338  Uint32 gsn; // Request type (SEQUENCE, DELETE, etc)
339  union {
343  struct {
344  Uint32 sequenceId;
345  Uint32 requestType;
346  } sequence;
347  };
348 
349  Uint32 connectPtr;
350  Uint32 connectRef;
351  Uint32 transId[2];
352  SLList<Operation> operations;
353 
354  Uint32 errorCode;
355  Uint32 noOfRetries;
356  Uint32 gci_hi;
357  Uint32 gci_lo;
358  Uint32 sent; // No of operations sent
359  Uint32 recv; // No of completed operations received
360  inline bool complete() const { return sent == recv; };
361 
362  union {
363  Uint32 nextPool;
364  Uint32 nextList;
365  };
366  Uint32 prevList;
367 
368  void print() const {
369  ndbout << "[-Transaction-" << endl
370  << " clientRef: " << clientRef
371  << ", clientData: " << clientData
372  << ", gsn: " << gsn
373  << ", errorCode: " << errorCode
374  << endl
375  << " sent: " << sent << " operations"
376  << ", recv: " << recv << " completed operations";
377  OperationPtr opPtr;
378  this->operations.first(opPtr);
379  while(opPtr.i != RNIL){
380  ndbout << "[-Operation-" << endl;
381  opPtr.p->print();
382  this->operations.next(opPtr);
383  }
384  ndbout << "]" << endl;
385  }
386  };
387 
388  typedef Ptr<Page32> Page32Ptr;
389  typedef Ptr<Prepare> PreparePtr;
393 
394  Uint32 c_transId[2];
395  ArrayPool<Page32> c_pagePool;
396  ArrayPool<Prepare> c_preparePool;
397  ArrayPool<Operation> c_operationPool;
398  ArrayPool<PreparedOperation> c_preparedOperationPool;
399  ArrayPool<Transaction> c_transactionPool;
400 
401  DataBuffer<1>::DataBufferPool c_attrMappingPool;
402  DataBuffer<11>::DataBufferPool c_dataBufPool;
403  DLList<Prepare> c_runningPrepares;
404  DLList<Transaction> c_seizingTransactions; // Being seized at TC
405  DLList<Transaction> c_runningTransactions; // Seized and now exec.
406 
407  void getTransId(Transaction *);
408  void initResultSet(ResultSetBuffer &, const ResultSetInfoBuffer &);
409  void runTransaction(Signal* signal, TransactionPtr);
410  void runOperation(Signal* signal, TransactionPtr &, OperationPtr &, Uint32);
411  void sendKeyInfo(Signal* signal, Uint32 ref,
412  KeyInfo* keyInfo,
413  const KeyInfoBuffer & keyBuf,
414  KeyInfoIterator & kit);
415  void sendAttrInfo(Signal*, Uint32 ref,
416  AttrInfo* attrInfo,
417  const AttrInfoBuffer &,
418  AttrInfoIterator & ait);
419  int getResultSet(Signal* signal, const Transaction * transP,
420  struct LinearSectionPtr sectionsPtr[]);
421  void finishTransaction(Signal*, TransactionPtr);
422  void releaseTransaction(TransactionPtr transPtr);
423  void get_systab_tableid(Signal*);
424  void hardcodedPrepare(Signal*, Uint32 SYSTAB_0);
425  void connectTc(Signal* signal);
426  void reportSequence(Signal*, const Transaction *);
427  void readPrepareProps(Signal* signal,
428  SimpleProperties::Reader* reader,
429  PreparePtr);
430  void prepareOperation(Signal*, PreparePtr, SegmentedSectionPtr);
431  void sendUtilPrepareRef(Signal*, UtilPrepareRef::ErrorCode, Uint32, Uint32,
432  Uint32 extraError = 0);
433  void sendUtilExecuteRef(Signal*, UtilExecuteRef::ErrorCode,
434  Uint32, Uint32, Uint32);
435  void releasePrepare(PreparePtr);
436  void releasePreparedOperation(PreparedOperationPtr);
437 
438  /***************************************************************************
439  * Lock manager
440  */
443  LockQueueInstance(Uint32 id) : m_queue() { m_lockId = id; }
444  union {
445  Uint32 m_lockId;
446  Uint32 key;
447  };
448 
449  LockQueue m_queue;
450  union {
451  Uint32 nextHash;
452  Uint32 nextPool;
453  };
454  Uint32 prevHash;
455 
456  Uint32 hashValue() const {
457  return m_lockId;
458  }
459  bool equal(const LockQueueInstance & rec) const {
460  return m_lockId == rec.m_lockId;
461  }
462  };
464 
465  ArrayPool<LockQueueInstance> c_lockQueuePool;
466  KeyTable<LockQueueInstance> c_lockQueues;
467  LockQueue::Pool c_lockElementPool;
468 
469  void execUTIL_CREATE_LOCK_REQ(Signal* signal);
470  void execUTIL_DESTORY_LOCK_REQ(Signal* signal);
471  void execUTIL_LOCK_REQ(Signal* signal);
472  void execUTIL_UNLOCK_REQ(Signal* signal);
473 
474  void sendLOCK_REF(Signal*, const UtilLockReq * req, UtilLockRef::ErrorCode);
475  void sendLOCK_CONF(Signal*, const UtilLockReq * req);
476 
477  void sendUNLOCK_REF(Signal*, const UtilUnlockReq*, UtilUnlockRef::ErrorCode);
478 
479  // For testing of mutex:es
480  void mutex_created(Signal* signal, Uint32 mutexId, Uint32 retVal);
481  void mutex_destroyed(Signal* signal, Uint32 mutexId, Uint32 retVal);
482  void mutex_locked(Signal* signal, Uint32 mutexId, Uint32 retVal);
483  void mutex_unlocked(Signal* signal, Uint32 mutexId, Uint32 retVal);
484 };
485 
486 #endif