MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Trix.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 TRIX_H
19 #define TRIX_H
20 
21 #include <SimulatedBlock.hpp>
22 #include <trigger_definitions.h>
23 #include <DataBuffer.hpp>
24 #include <SimpleProperties.hpp>
25 #include <signaldata/DictTabInfo.hpp>
26 #include <signaldata/CreateTrig.hpp>
27 #include <signaldata/BuildIndx.hpp>
28 #include <signaldata/IndexStatSignal.hpp>
29 #include <signaldata/GetTabInfo.hpp>
30 #include <signaldata/TuxBound.hpp>
31 #define ZNOT_FOUND 626
32 
33 // Error codes
34 #define INTERNAL_ERROR_ILLEGAL_CALL 4344
35 #define INTERNAL_ERROR_TRIX_BUSY 4345
36 
40 class Trix : public SimulatedBlock
41 {
42 public:
44  virtual ~Trix();
45 
46 public:
47  // Subscription data, when communicating with SUMA
48 
49  enum RequestType {
50  REORG_COPY = 0
51  ,REORG_DELETE = 1
52  ,INDEX_BUILD = 2
53  ,STAT_UTIL = 3 // PK op of HEAD table directly via DBUTIL
54  ,STAT_CLEAN = 4
55  ,STAT_SCAN = 5
56  //ALTER_TABLE
57  };
59 
60 private:
61  // Private attributes
62 
63  BLOCK_DEFINES(Trix);
64 
65  // Declared but not defined
66  //DBtrix(const Trix &obj);
67  //void operator = (const Trix &);
68 
69  // Block state
70  enum BlockState {
71  NOT_STARTED,
72  STARTED,
73  NODE_FAILURE,
74  IDLE,
75  BUSY
76  };
77 
78  BlockState c_blockState;
79 
80  // Node data needed when communicating with remote TRIX:es
81  struct NodeRecord {
82  NodeRecord() {}
83  bool alive;
84  BlockReference trixRef;
85  union {
86  Uint32 nextPool;
87  Uint32 nextList;
88  };
89  Uint32 prevList;
90  };
91 
93 
97  ArrayPool<NodeRecord> c_theNodeRecPool;
98 
102  DLList<NodeRecord> c_theNodes;
103 
104  Uint32 c_masterNodeId;
105  BlockReference c_masterTrixRef;
106  Uint16 c_noNodesFailed;
107  Uint16 c_noActiveNodes;
108 
109  AttrOrderBuffer::DataBufferPool c_theAttrOrderBufferPool;
110 
111  struct SubscriptionRecord {
112  SubscriptionRecord(AttrOrderBuffer::DataBufferPool & aop):
113  attributeOrder(aop)
114  {}
115  enum RequestFlags {
116  RF_WAIT_GCP = 0x1
117  ,RF_NO_DISK = 0x2
118  ,RF_TUP_ORDER = 0x4
119  };
120  Uint32 m_flags;
121  RequestType requestType;
122  BlockReference userReference; // For user
123  Uint32 connectionPtr; // For user
124  Uint32 subscriptionId; // For Suma
125  Uint32 schemaTransId;
126  Uint32 subscriptionKey; // For Suma
127  Uint32 prepareId; // For DbUtil
128  Uint32 indexType;
129  Uint32 sourceTableId;
130  Uint32 targetTableId;
131  AttrOrderBuffer attributeOrder;
132  Uint32 noOfIndexColumns;
133  Uint32 noOfKeyColumns;
134  Uint32 parallelism;
135  Uint32 fragCount;
136  Uint32 fragId;
137  Uint32 syncPtr;
138  BuildIndxRef::ErrorCode errorCode;
139  bool subscriptionCreated;
140  bool pendingSubSyncContinueConf;
141  Uint32 expectedConf; // Count in n UTIL_EXECUTE_CONF + 1 SUB_SYNC_CONF
142  Uint64 m_rows_processed;
143  Uint64 m_gci;
144  Uint32 m_statPtrI;
145  union {
146  Uint32 nextPool;
147  Uint32 nextList;
148  };
149  Uint32 prevList;
150  };
151 
153 
157  ArrayPool<SubscriptionRecord> c_theSubscriptionRecPool;
158  RSS_AP_SNAPSHOT(c_theSubscriptionRecPool);
159 
163  DLList<SubscriptionRecord> c_theSubscriptions;
164 
165  /*
166  * Ordered index stats. Implements sub-ops of DBDICT index stat
167  * schema op. Each sub-op is a simple REQ which seizes and releases
168  * a stat op here before returning CONF or REF. A stat op always has
169  * an associated SubscriptionRecord. It is used for SUMA index scans
170  * and as proxy for PK ops to DBUTIL.
171  */
172 
173  bool c_statGetMetaDone;
174  struct SysColumn {
175  Uint32 pos;
176  const char* name;
177  bool keyFlag;
178  };
179  struct SysTable {
180  const char* name;
181  mutable Uint32 tableId;
182  const Uint32 columnCount;
183  const SysColumn* columnList;
184  };
185  struct SysIndex {
186  const char* name;
187  mutable Uint32 tableId;
188  mutable Uint32 indexId;
189  };
190  static const SysColumn g_statMetaHead_column[];
191  static const SysColumn g_statMetaSample_column[];
192  static const SysTable g_statMetaHead;
193  static const SysTable g_statMetaSample;
194  static const SysIndex g_statMetaSampleX1;
195 
196  struct StatOp {
197  struct Meta {
198  GetTabInfoConf m_conf;
199  Callback m_cb;
200  };
201  struct Data {
202  Int32 m_head_found;
203  Uint32 m_indexId;
204  Uint32 m_indexVersion;
205  Uint32 m_tableId;
206  Uint32 m_fragCount;
207  Uint32 m_valueFormat;
208  Uint32 m_sampleVersion;
209  Uint32 m_loadTime;
210  Uint32 m_sampleCount;
211  Uint32 m_keyBytes;
212  Uint32* m_statKey;
213  Uint32* m_statValue;
214  Data() {
215  m_head_found = -1;
216  m_sampleVersion = 0;
217  }
218  };
219  struct Attr {
220  Uint32* m_attr;
221  Uint32 m_attrMax;
222  Uint32 m_attrSize;
223  Uint32* m_data;
224  Uint32 m_dataMax;
225  Uint32 m_dataSize;
226  Attr() {}
227  };
228  struct Util {
229  Uint32 m_prepareId;
230  bool m_not_found;
231  Callback m_cb;
232  Util() {
233  m_prepareId = RNIL;
234  m_not_found = false; // read + ZNOT_FOUND
235  };
236  };
237  struct Clean {
238  Uint32 m_cleanCount;
239  // bounds on index_id, index_version, sample_version
240  Uint32 m_bound[3 * 3];
241  Uint32 m_boundCount;
242  Uint32 m_boundSize;
243  Clean() {}
244  };
245  struct Scan {
246  Uint32 m_sampleCount;
247  Uint32 m_keyBytes;
248  Scan() {}
249  };
250  struct Drop {
251  };
252  struct Send {
253  const SysTable* m_sysTable;
254  Uint32 m_operationType; // UtilPrepareReq::OperationTypeValue
255  Uint32 m_prepareId;
256  Send() {}
257  };
258  IndexStatImplReq m_req;
259  Uint32 m_requestType;
260  const char* m_requestName;
261  Uint32 m_subRecPtrI;
262  Meta m_meta;
263  Data m_data;
264  Attr m_attr;
265  Util m_util;
266  Clean m_clean;
267  Scan m_scan;
268  Drop m_drop;
269  Send m_send;
270  Uint32 m_errorCode;
271  Uint32 m_errorLine;
272  union {
273  Uint32 m_ownPtrI;
274  Uint32 nextPool;
275  };
276  StatOp() {
277  m_subRecPtrI = RNIL;
278  m_errorCode = 0;
279  m_errorLine = 0;
280  };
281  };
282  typedef Ptr<StatOp> StatOpPtr;
283  ArrayPool<StatOp> c_statOpPool;
284  RSS_AP_SNAPSHOT(c_statOpPool);
285 
286  // System start
287  void execREAD_CONFIG_REQ(Signal* signal);
288  void execSTTOR(Signal* signal);
289  void execNDB_STTOR(Signal* signal);
290 
291  // Node management
292  void execREAD_NODESCONF(Signal* signal);
293  void execREAD_NODESREF(Signal* signal);
294  void execNODE_FAILREP(Signal* signal);
295  void execINCL_NODEREQ(Signal* signal);
296  // Debugging
297  void execDUMP_STATE_ORD(Signal* signal);
298 
299  void execDBINFO_SCANREQ(Signal* signal);
300 
301  // Build index
302  void execBUILD_INDX_IMPL_REQ(Signal* signal);
303  void execBUILD_INDX_IMPL_CONF(Signal* signal);
304  void execBUILD_INDX_IMPL_REF(Signal* signal);
305 
306  void execCOPY_DATA_IMPL_REQ(Signal* signal);
307 
308  void execUTIL_PREPARE_CONF(Signal* signal);
309  void execUTIL_PREPARE_REF(Signal* signal);
310  void execUTIL_EXECUTE_CONF(Signal* signal);
311  void execUTIL_EXECUTE_REF(Signal* signal);
312  void execUTIL_RELEASE_CONF(Signal* signal);
313  void execUTIL_RELEASE_REF(Signal* signal);
314 
315  // Suma signals
316  void execSUB_CREATE_CONF(Signal* signal);
317  void execSUB_CREATE_REF(Signal* signal);
318  void execSUB_REMOVE_CONF(Signal* signal);
319  void execSUB_REMOVE_REF(Signal* signal);
320  void execSUB_SYNC_CONF(Signal* signal);
321  void execSUB_SYNC_REF(Signal* signal);
322  void execSUB_SYNC_CONTINUE_REQ(Signal* signal);
323  void execSUB_TABLE_DATA(Signal* signal);
324 
325  // GCP
326  void execWAIT_GCP_REF(Signal*);
327  void execWAIT_GCP_CONF(Signal*);
328 
329  // Utility functions
330  void setupSubscription(Signal* signal, SubscriptionRecPtr subRecPtr);
331  void startTableScan(Signal* signal, SubscriptionRecPtr subRecPtr);
332  void prepareInsertTransactions(Signal* signal, SubscriptionRecPtr subRecPtr);
333  void executeBuildInsertTransaction(Signal* signal, SubscriptionRecPtr);
334  void executeReorgTransaction(Signal*, SubscriptionRecPtr, Uint32);
335  void buildComplete(Signal* signal, SubscriptionRecPtr subRecPtr);
336  void wait_gcp(Signal*, SubscriptionRecPtr subRecPtr, Uint32 delay = 0);
337  void buildFailed(Signal* signal,
338  SubscriptionRecPtr subRecPtr,
339  BuildIndxRef::ErrorCode);
340  void checkParallelism(Signal* signal, SubscriptionRecord* subRec);
341 
342  // index stats
343  StatOp& statOpGetPtr(Uint32 statPtrI);
344  bool statOpSeize(Uint32& statPtrI);
345  void statOpRelease(StatOp&);
346  void execINDEX_STAT_IMPL_REQ(Signal*);
347  // sys tables metadata
348  void statMetaGetHead(Signal*, StatOp&);
349  void statMetaGetHeadCB(Signal*, Uint32 statPtrI, Uint32 ret);
350  void statMetaGetSample(Signal*, StatOp&);
351  void statMetaGetSampleCB(Signal*, Uint32 statPtrI, Uint32 ret);
352  void statMetaGetSampleX1(Signal*, StatOp&);
353  void statMetaGetSampleX1CB(Signal*, Uint32 statPtrI, Uint32 ret);
354  void sendGetTabInfoReq(Signal*, StatOp&, const char* name);
355  void execGET_TABINFO_CONF(Signal*);
356  void execGET_TABINFO_REF(Signal*);
357  // continue
358  void statGetMetaDone(Signal*, StatOp&);
359  // head table ops
360  void statHeadRead(Signal*, StatOp&);
361  void statHeadReadCB(Signal*, Uint32 statPtrI, Uint32 ret);
362  void statHeadInsert(Signal*, StatOp&);
363  void statHeadInsertCB(Signal*, Uint32 statPtrI, Uint32 ret);
364  void statHeadUpdate(Signal*, StatOp&);
365  void statHeadUpdateCB(Signal*, Uint32 statPtrI, Uint32 ret);
366  void statHeadDelete(Signal*, StatOp&);
367  void statHeadDeleteCB(Signal*, Uint32 statPtrI, Uint32 ret);
368  // util
369  void statUtilPrepare(Signal*, StatOp&);
370  void statUtilPrepareConf(Signal*, Uint32 statPtrI);
371  void statUtilPrepareRef(Signal*, Uint32 statPtrI);
372  void statUtilExecute(Signal*, StatOp&);
373  void statUtilExecuteConf(Signal*, Uint32 statPtrI);
374  void statUtilExecuteRef(Signal*, Uint32 statPtrI);
375  void statUtilRelease(Signal*, StatOp&);
376  void statUtilReleaseConf(Signal*, Uint32 statPtrI);
377  // continue
378  void statReadHeadDone(Signal*, StatOp&);
379  void statInsertHeadDone(Signal*, StatOp&);
380  void statUpdateHeadDone(Signal*, StatOp&);
381  void statDeleteHeadDone(Signal*, StatOp&);
382  // clean
383  void statCleanBegin(Signal*, StatOp&);
384  void statCleanPrepare(Signal*, StatOp&);
385  void statCleanExecute(Signal*, StatOp&);
386  void statCleanRelease(Signal*, StatOp&);
387  void statCleanEnd(Signal*, StatOp&);
388  // scan
389  void statScanBegin(Signal*, StatOp&);
390  void statScanPrepare(Signal*, StatOp&);
391  void statScanExecute(Signal*, StatOp&);
392  void statScanRelease(Signal*, StatOp&);
393  void statScanEnd(Signal*, StatOp&);
394  // drop
395  void statDropBegin(Signal*, StatOp&);
396  void statDropEnd(Signal*, StatOp&);
397  // send
398  void statSendPrepare(Signal*, StatOp&);
399  void statSendExecute(Signal*, StatOp&);
400  void statSendRelease(Signal*, StatOp&);
401  // data
402  void statDataPtr(StatOp&, Uint32 i, Uint32*& dptr, Uint32& bytes);
403  void statDataOut(StatOp&, Uint32 i);
404  void statDataIn(StatOp&, Uint32 i);
405  // abort ongoing
406  void statAbortUtil(Signal*, StatOp&);
407  void statAbortUtilCB(Signal*, Uint32 statPtrI, Uint32 ret);
408  // conf and ref
409  void statOpSuccess(Signal*, StatOp&);
410  void statOpConf(Signal*, StatOp&);
411  void statOpError(Signal*, StatOp&, Uint32 errorCode, Uint32 errorLine,
412  const Uint32 * supress = 0);
413  void statOpAbort(Signal*, StatOp&);
414  void statOpRef(Signal*, StatOp&);
415  void statOpRef(Signal*, const IndexStatImplReq*, Uint32 errorCode, Uint32 errorLine);
416  void statOpEvent(StatOp&, const char* level, const char* msg, ...);
417  // debug
418  friend class NdbOut& operator<<(NdbOut&, const StatOp& stat);
419 };
420 
421 #endif