MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ScanFrag.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 SCAN_FRAG_HPP
19 #define SCAN_FRAG_HPP
20 
21 #include "SignalData.hpp"
22 #include "ndb_limits.h"
23 
24 class ScanFragReq {
28  friend class Dbtc;
29  friend class Backup;
30  friend class Suma;
31 
35  friend class Dblqh;
36  friend class Dbspj;
37 public:
38  STATIC_CONST( SignalLength = 12 );
39 
40  STATIC_CONST( AttrInfoSectionNum = 0 );
41  STATIC_CONST( KeyInfoSectionNum = 1 );
42 
43  friend bool printSCAN_FRAGREQ(FILE *, const Uint32*, Uint32, Uint16);
44  friend bool printSCAN_FRAGCONF(FILE *, const Uint32*, Uint32, Uint16);
45 
46 public:
47  enum ReorgFlag
48  {
49  REORG_ALL = 0
50  ,REORG_NOT_MOVED = 1 // Only return not moved rows
51  ,REORG_MOVED = 2 // Only return moved rows
52  };
53 
54  Uint32 senderData;
55  Uint32 resultRef; // Where to send the result
56  Uint32 savePointId;
57  Uint32 requestInfo;
58  Uint32 tableId;
59  Uint32 fragmentNoKeyLen;
60  Uint32 schemaVersion;
61  Uint32 transId1;
62  Uint32 transId2;
63  union {
64  Uint32 clientOpPtr;
65  Uint32 resultData;
66  };
67  Uint32 batch_size_rows;
68  Uint32 batch_size_bytes;
69  Uint32 variableData[1];
70 
71  static Uint32 getLockMode(const Uint32 & requestInfo);
72  static Uint32 getHoldLockFlag(const Uint32 & requestInfo);
73  static Uint32 getKeyinfoFlag(const Uint32 & requestInfo);
74  static Uint32 getReadCommittedFlag(const Uint32 & requestInfo);
75  static Uint32 getRangeScanFlag(const Uint32 & requestInfo);
76  static Uint32 getDescendingFlag(const Uint32 & requestInfo);
77  static Uint32 getTupScanFlag(const Uint32 & requestInfo);
78  static Uint32 getAttrLen(const Uint32 & requestInfo);
79  static Uint32 getScanPrio(const Uint32 & requestInfo);
80  static Uint32 getNoDiskFlag(const Uint32 & requestInfo);
81  static Uint32 getLcpScanFlag(const Uint32 & requestInfo);
82  static Uint32 getStatScanFlag(const Uint32 & requestInfo);
83 
84  static void setLockMode(Uint32 & requestInfo, Uint32 lockMode);
85  static void setHoldLockFlag(Uint32 & requestInfo, Uint32 holdLock);
86  static void setKeyinfoFlag(Uint32 & requestInfo, Uint32 keyinfo);
87  static void setReadCommittedFlag(Uint32 & requestInfo, Uint32 readCommitted);
88  static void setRangeScanFlag(Uint32 & requestInfo, Uint32 rangeScan);
89  static void setDescendingFlag(Uint32 & requestInfo, Uint32 descending);
90  static void setTupScanFlag(Uint32 & requestInfo, Uint32 tupScan);
91  static void setAttrLen(Uint32 & requestInfo, Uint32 attrLen);
92  static void setScanPrio(Uint32& requestInfo, Uint32 prio);
93  static void setNoDiskFlag(Uint32& requestInfo, Uint32 val);
94  static void setLcpScanFlag(Uint32 & requestInfo, Uint32 val);
95  static void setStatScanFlag(Uint32 & requestInfo, Uint32 val);
96 
97  static void setReorgFlag(Uint32 & requestInfo, Uint32 val);
98  static Uint32 getReorgFlag(const Uint32 & requestInfo);
99 
100  static void setCorrFactorFlag(Uint32 & requestInfo, Uint32 val);
101  static Uint32 getCorrFactorFlag(const Uint32 & requestInfo);
102 };
103 
104 /*
105  The KEYINFO20 signal is sent from LQH to API for each row in a scan when the
106  ScanTabReq::getKeyinfoFlag() is set in requestInfo in the SCAN_TABREQ signal.
107 
108  The '20' in the signal name refers to the number of keyInfo data words in
109  the signal, which is actually a bit misleading since now it is sent as a
110  single long signal if the keyinfo has more than 20 words.
111 
112  The information in this signal is used in the NDB API to request the take
113  over of a lock from the scan with a TCKEYREQ, using the primary key info
114  sent as data and the scanInfo_Node word to identify the lock.
115 */
116 class KeyInfo20 {
120  friend class Dblqh;
121 
125  friend class Backup;
126  friend class NdbOperation;
127  friend class NdbScanReceiver;
128 public:
129  STATIC_CONST( HeaderLength = 5);
130  STATIC_CONST( DataLength = 20 );
131 
132 
133  static Uint32 setScanInfo(Uint32 noOfOps, Uint32 scanNo);
134  static Uint32 getScanNo(Uint32 scanInfo);
135  static Uint32 getScanOp(Uint32 scanInfo);
136 
137 public:
138  Uint32 clientOpPtr;
139  Uint32 keyLen;
140  /*
141  The scanInfo_Node word contains the information needed to identify the
142  row and lock to take over in the TCKEYREQ signal. It has two parts:
143  1. ScanInfo Lower 20 bits
144  2. ScanFragment Upper 14 bits
145  */
146  Uint32 scanInfo_Node;
147  Uint32 transId1;
148  Uint32 transId2;
149  Uint32 keyData[DataLength];
150  /*
151  Note that if the key info data does not fit within the maximum of 20
152  in-signal words, the entire key info is instead sent in long signal
153  section 0.
154  The data here is a word string suitable for sending as KEYINFO in
155  the TCKEYREQ signal.
156  */
157 };
158 
163  friend class Dblqh;
164 
168  friend class Dbtc;
169  friend class Backup;
170  friend class Suma;
171 public:
172  STATIC_CONST( SignalLength = 6 );
173 
174 public:
175  Uint32 senderData;
176  Uint32 completedOps;
177  Uint32 fragmentCompleted;
178  Uint32 transId1;
179  Uint32 transId2;
180  Uint32 total_len;
181 };
182 
183 class ScanFragRef {
187  friend class Dblqh;
188 
192  friend class Dbtc;
193  friend class Backup;
194  friend class Suma;
195 public:
196  STATIC_CONST( SignalLength = 4 );
197 public:
198  enum ErrorCode {
199  ZNO_FREE_TC_CONREC_ERROR = 484,
200  ZTOO_FEW_CONCURRENT_OPERATIONS = 485,
201  ZTOO_MANY_CONCURRENT_OPERATIONS = 486,
202  ZSCAN_NO_FRAGMENT_ERROR = 487,
203  ZTOO_MANY_ACTIVE_SCAN_ERROR = 488,
204  ZNO_FREE_SCANREC_ERROR = 489,
205  ZWRONG_BATCH_SIZE = 1230,
206  ZSTANDBY_SCAN_ERROR = 1209,
207  NO_TC_CONNECT_ERROR = 1217,
208  ZSCAN_BOOK_ACC_OP_ERROR = 1219,
209  ZUNKNOWN_TRANS_ERROR = 1227
210  };
211 
212  Uint32 senderData;
213  Uint32 transId1;
214  Uint32 transId2;
215  Uint32 errorCode;
216 };
217 
227  friend class Dbtc;
228  friend class Backup;
229  friend class Suma;
230 
234  friend class Dblqh;
235 
236  friend bool printSCANFRAGNEXTREQ(FILE * output, const Uint32 * theData,
237  Uint32 len, Uint16 receiverBlockNo);
238 public:
239  STATIC_CONST( SignalLength = 6 );
240 
241 public:
242  Uint32 senderData;
243  Uint32 requestInfo; // 1 == close
244  Uint32 transId1;
245  Uint32 transId2;
246  Uint32 batch_size_rows;
247  Uint32 batch_size_bytes;
248  Uint32 variableData[1];
249 
250  STATIC_CONST( ZCLOSE = 1 );
251 
252  static Uint32 getCloseFlag(const Uint32&);
253  static void setCloseFlag(Uint32&, Uint32);
254 
255  static Uint32 getCorrFactorFlag(const Uint32&);
256  static void setCorrFactorFlag(Uint32&);
257 };
258 
282 #define SF_LOCK_MODE_SHIFT (5)
283 #define SF_LOCK_MODE_MASK (1)
284 
285 #define SF_NO_DISK_SHIFT (4)
286 #define SF_HOLD_LOCK_SHIFT (7)
287 #define SF_KEYINFO_SHIFT (8)
288 #define SF_READ_COMMITTED_SHIFT (9)
289 #define SF_RANGE_SCAN_SHIFT (6)
290 #define SF_DESCENDING_SHIFT (10)
291 #define SF_TUP_SCAN_SHIFT (11)
292 #define SF_LCP_SCAN_SHIFT (3)
293 
294 #define SF_ATTR_LEN_SHIFT (16)
295 #define SF_ATTR_LEN_MASK (65535)
296 
297 #define SF_PRIO_SHIFT 12
298 #define SF_PRIO_MASK 15
299 
300 #define SF_REORG_SHIFT (1)
301 #define SF_REORG_MASK (3)
302 
303 #define SF_CORR_FACTOR_SHIFT (16)
304 
305 #define SF_STAT_SCAN_SHIFT (17)
306 
307 inline
308 Uint32
309 ScanFragReq::getLockMode(const Uint32 & requestInfo){
310  return (requestInfo >> SF_LOCK_MODE_SHIFT) & SF_LOCK_MODE_MASK;
311 }
312 
313 inline
314 Uint32
315 ScanFragReq::getHoldLockFlag(const Uint32 & requestInfo){
316  return (requestInfo >> SF_HOLD_LOCK_SHIFT) & 1;
317 }
318 
319 inline
320 Uint32
321 ScanFragReq::getKeyinfoFlag(const Uint32 & requestInfo){
322  return (requestInfo >> SF_KEYINFO_SHIFT) & 1;
323 }
324 
325 inline
326 Uint32
327 ScanFragReq::getRangeScanFlag(const Uint32 & requestInfo){
328  return (requestInfo >> SF_RANGE_SCAN_SHIFT) & 1;
329 }
330 
331 inline
332 Uint32
333 ScanFragReq::getDescendingFlag(const Uint32 & requestInfo){
334  return (requestInfo >> SF_DESCENDING_SHIFT) & 1;
335 }
336 
337 inline
338 Uint32
339 ScanFragReq::getTupScanFlag(const Uint32 & requestInfo){
340  return (requestInfo >> SF_TUP_SCAN_SHIFT) & 1;
341 }
342 
343 inline
344 Uint32
345 ScanFragReq::getReadCommittedFlag(const Uint32 & requestInfo){
346  return (requestInfo >> SF_READ_COMMITTED_SHIFT) & 1;
347 }
348 
349 inline
350 Uint32
351 ScanFragReq::getAttrLen(const Uint32 & requestInfo){
352  return (requestInfo >> SF_ATTR_LEN_SHIFT) & SF_ATTR_LEN_MASK;
353 }
354 
355 inline
356 Uint32
357 ScanFragReq::getScanPrio(const Uint32 & requestInfo){
358  return (requestInfo >> SF_PRIO_SHIFT) & SF_PRIO_MASK;
359 }
360 
361 inline
362 void
363 ScanFragReq::setScanPrio(UintR & requestInfo, UintR val){
364  ASSERT_MAX(val, SF_PRIO_MASK, "ScanFragReq::setScanPrio");
365  requestInfo |= (val << SF_PRIO_SHIFT);
366 }
367 
368 inline
369 void
370 ScanFragReq::setLockMode(UintR & requestInfo, UintR val){
371  ASSERT_MAX(val, SF_LOCK_MODE_MASK, "ScanFragReq::setLockMode");
372  requestInfo |= (val << SF_LOCK_MODE_SHIFT);
373 }
374 
375 inline
376 void
377 ScanFragReq::setHoldLockFlag(UintR & requestInfo, UintR val){
378  ASSERT_BOOL(val, "ScanFragReq::setHoldLockFlag");
379  requestInfo |= (val << SF_HOLD_LOCK_SHIFT);
380 }
381 
382 inline
383 void
384 ScanFragReq::setKeyinfoFlag(UintR & requestInfo, UintR val){
385  ASSERT_BOOL(val, "ScanFragReq::setKeyinfoFlag");
386  requestInfo |= (val << SF_KEYINFO_SHIFT);
387 }
388 
389 inline
390 void
391 ScanFragReq::setReadCommittedFlag(UintR & requestInfo, UintR val){
392  ASSERT_BOOL(val, "ScanFragReq::setReadCommittedFlag");
393  requestInfo |= (val << SF_READ_COMMITTED_SHIFT);
394 }
395 
396 inline
397 void
398 ScanFragReq::setRangeScanFlag(UintR & requestInfo, UintR val){
399  ASSERT_BOOL(val, "ScanFragReq::setRangeScanFlag");
400  requestInfo |= (val << SF_RANGE_SCAN_SHIFT);
401 }
402 
403 inline
404 void
405 ScanFragReq::setDescendingFlag(UintR & requestInfo, UintR val){
406  ASSERT_BOOL(val, "ScanFragReq::setDescendingFlag");
407  requestInfo |= (val << SF_DESCENDING_SHIFT);
408 }
409 
410 inline
411 void
412 ScanFragReq::setTupScanFlag(UintR & requestInfo, UintR val){
413  ASSERT_BOOL(val, "ScanFragReq::setTupScanFlag");
414  requestInfo |= (val << SF_TUP_SCAN_SHIFT);
415 }
416 
417 inline
418 void
419 ScanFragReq::setAttrLen(UintR & requestInfo, UintR val){
420  ASSERT_MAX(val, SF_ATTR_LEN_MASK, "ScanFragReq::setAttrLen");
421  requestInfo |= (val << SF_ATTR_LEN_SHIFT);
422 }
423 
424 inline
425 Uint32
426 ScanFragReq::getNoDiskFlag(const Uint32 & requestInfo){
427  return (requestInfo >> SF_NO_DISK_SHIFT) & 1;
428 }
429 
430 inline
431 void
432 ScanFragReq::setNoDiskFlag(UintR & requestInfo, UintR val){
433  ASSERT_BOOL(val, "ScanFragReq::setNoDiskFlag");
434  requestInfo |= (val << SF_NO_DISK_SHIFT);
435 }
436 
437 inline
438 Uint32
439 ScanFragReq::getLcpScanFlag(const Uint32 & requestInfo){
440  return (requestInfo >> SF_LCP_SCAN_SHIFT) & 1;
441 }
442 
443 inline
444 void
445 ScanFragReq::setLcpScanFlag(UintR & requestInfo, UintR val){
446  ASSERT_BOOL(val, "ScanFragReq::setLcpScanFlag");
447  requestInfo |= (val << SF_LCP_SCAN_SHIFT);
448 }
449 
450 inline
451 Uint32
452 KeyInfo20::setScanInfo(Uint32 opNo, Uint32 scanNo){
453  ASSERT_MAX(opNo, 1023, "KeyInfo20::setScanInfo");
454  ASSERT_MAX(scanNo, 255, "KeyInfo20::setScanInfo");
455  return (opNo << 8) + scanNo;
456 }
457 
458 inline
459 Uint32
460 KeyInfo20::getScanNo(Uint32 scanInfo){
461  return scanInfo & 0xFF;
462 }
463 
464 inline
465 Uint32
466 KeyInfo20::getScanOp(Uint32 scanInfo){
467  return (scanInfo >> 8) & 0x3FF;
468 }
469 
470 inline
471 Uint32
472 ScanFragReq::getReorgFlag(const Uint32 & requestInfo){
473  return (requestInfo >> SF_REORG_SHIFT) & SF_REORG_MASK;
474 }
475 
476 inline
477 void
478 ScanFragReq::setReorgFlag(UintR & requestInfo, UintR val){
479  ASSERT_MAX(val, SF_REORG_MASK, "ScanFragReq::setLcpScanFlag");
480  requestInfo |= (val << SF_REORG_SHIFT);
481 }
482 
483 inline
484 Uint32
485 ScanFragReq::getCorrFactorFlag(const Uint32 & requestInfo){
486  return (requestInfo >> SF_CORR_FACTOR_SHIFT) & 1;
487 }
488 
489 inline
490 void
491 ScanFragReq::setCorrFactorFlag(UintR & requestInfo, UintR val){
492  ASSERT_BOOL(val, "ScanFragReq::setCorrFactorFlag");
493  requestInfo |= (val << SF_CORR_FACTOR_SHIFT);
494 }
495 
496 inline
497 Uint32
498 ScanFragReq::getStatScanFlag(const Uint32 & requestInfo){
499  return (requestInfo >> SF_STAT_SCAN_SHIFT) & 1;
500 }
501 
502 inline
503 void
504 ScanFragReq::setStatScanFlag(UintR & requestInfo, UintR val){
505  ASSERT_BOOL(val, "ScanFragReq::setStatScanFlag");
506  requestInfo |= (val << SF_STAT_SCAN_SHIFT);
507 }
508 
519 #define SFN_CLOSE_SHIFT 0
520 #define SFN_CORR_SHIFT 1
521 
522 inline
523 Uint32
524 ScanFragNextReq::getCorrFactorFlag(const Uint32 & ri)
525 {
526  return (ri >> SFN_CORR_SHIFT) & 1;
527 }
528 
529 inline
530 void
531 ScanFragNextReq::setCorrFactorFlag(Uint32 & ri)
532 {
533  ri |= (1 << SFN_CORR_SHIFT);
534 }
535 
536 #endif