1 /* Copyright (c) 2003-2005, 2007 MySQL AB
2    Use is subject to license terms
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 Street, Fifth Floor, Boston, MA  02110-1301, USA */
16 
17 #ifndef SCAN_TAB_H
18 #define SCAN_TAB_H
19 
20 #include "SignalData.hpp"
21 
22 /**
23  *
24  * SENDER:  API
25  * RECIVER: Dbtc
26  */
27 class ScanTabReq {
28   /**
29    * Reciver(s)
30    */
31   friend class Dbtc;         // Reciver
32 
33   /**
34    * Sender(s)
35    */
36   friend class NdbTransaction;
37   friend class NdbScanOperation;
38   friend class NdbIndexScanOperation;
39 
40   /**
41    * For printing
42    */
43   friend bool printSCANTABREQ(FILE * output, const Uint32 * theData, Uint32 len, Uint16 receiverBlockNo);
44 
45 public:
46   /**
47    * Length of signal
48    */
49   STATIC_CONST( StaticLength = 11 );
50   STATIC_CONST( MaxTotalAttrInfo = 0xFFFF );
51 
52 private:
53 
54   // Type definitions
55 
56   /**
57    * DATA VARIABLES
58    */
59   UintR apiConnectPtr;        // DATA 0
60   UintR attrLenKeyLen;        // DATA 1
61   UintR requestInfo;          // DATA 2
62   UintR tableId;              // DATA 3
63   UintR tableSchemaVersion;   // DATA 4
64   UintR storedProcId;         // DATA 5
65   UintR transId1;             // DATA 6
66   UintR transId2;             // DATA 7
67   UintR buddyConPtr;          // DATA 8
68   UintR batch_byte_size;      // DATA 9
69   UintR first_batch_size;     // DATA 10
70 
71   /**
72    * Optional
73    */
74   Uint32 distributionKey;
75 
76   /**
77    * Get:ers for requestInfo
78    */
79   static Uint8 getParallelism(const UintR & requestInfo);
80   static Uint8 getLockMode(const UintR & requestInfo);
81   static Uint8 getHoldLockFlag(const UintR & requestInfo);
82   static Uint8 getReadCommittedFlag(const UintR & requestInfo);
83   static Uint8 getRangeScanFlag(const UintR & requestInfo);
84   static Uint8 getDescendingFlag(const UintR & requestInfo);
85   static Uint8 getTupScanFlag(const UintR & requestInfo);
86   static Uint8 getKeyinfoFlag(const UintR & requestInfo);
87   static Uint16 getScanBatch(const UintR & requestInfo);
88   static Uint8 getDistributionKeyFlag(const UintR & requestInfo);
89   static UintR getNoDiskFlag(const UintR & requestInfo);
90 
91   /**
92    * Set:ers for requestInfo
93    */
94   static void clearRequestInfo(UintR & requestInfo);
95   static void setParallelism(UintR & requestInfo, Uint32 flag);
96   static void setLockMode(UintR & requestInfo, Uint32 flag);
97   static void setHoldLockFlag(UintR & requestInfo, Uint32 flag);
98   static void setReadCommittedFlag(UintR & requestInfo, Uint32 flag);
99   static void setRangeScanFlag(UintR & requestInfo, Uint32 flag);
100   static void setDescendingFlag(UintR & requestInfo, Uint32 flag);
101   static void setTupScanFlag(UintR & requestInfo, Uint32 flag);
102   static void setKeyinfoFlag(UintR & requestInfo, Uint32 flag);
103   static void setScanBatch(Uint32& requestInfo, Uint32 sz);
104   static void setDistributionKeyFlag(Uint32& requestInfo, Uint32 flag);
105   static void setNoDiskFlag(UintR & requestInfo, UintR val);
106 };
107 
108 /**
109  * Request Info
110  *
111  p = Parallelism           - 8  Bits -> Max 256 (Bit 0-7)
112  l = Lock mode             - 1  Bit 8
113  h = Hold lock mode        - 1  Bit 10
114  c = Read Committed        - 1  Bit 11
115  k = Keyinfo               - 1  Bit 12
116  t = Tup scan              - 1  Bit 13
117  z = Descending (TUX)      - 1  Bit 14
118  x = Range Scan (TUX)      - 1  Bit 15
119  b = Scan batch            - 10 Bit 16-25 (max 1023)
120  d = Distribution key flag - 1  Bit 26
121  n = No disk flag          - 1  Bit 9
122 
123            1111111111222222222233
124  01234567890123456789012345678901
125  pppppppplnhcktzxbbbbbbbbbbd
126 */
127 
128 #define PARALLEL_SHIFT     (0)
129 #define PARALLEL_MASK      (255)
130 
131 #define LOCK_MODE_SHIFT     (8)
132 #define LOCK_MODE_MASK      (1)
133 
134 #define HOLD_LOCK_SHIFT     (10)
135 #define HOLD_LOCK_MASK      (1)
136 
137 #define KEYINFO_SHIFT       (12)
138 #define KEYINFO_MASK        (1)
139 
140 #define READ_COMMITTED_SHIFT     (11)
141 #define READ_COMMITTED_MASK      (1)
142 
143 #define RANGE_SCAN_SHIFT        (15)
144 #define RANGE_SCAN_MASK         (1)
145 
146 #define DESCENDING_SHIFT        (14)
147 #define DESCENDING_MASK         (1)
148 
149 #define TUP_SCAN_SHIFT          (13)
150 #define TUP_SCAN_MASK           (1)
151 
152 #define SCAN_BATCH_SHIFT (16)
153 #define SCAN_BATCH_MASK  (1023)
154 
155 #define SCAN_DISTR_KEY_SHIFT (26)
156 #define SCAN_DISTR_KEY_MASK (1)
157 
158 #define SCAN_NODISK_SHIFT (9)
159 #define SCAN_NODISK_MASK (1)
160 
161 inline
162 Uint8
getParallelism(const UintR & requestInfo)163 ScanTabReq::getParallelism(const UintR & requestInfo){
164   return (Uint8)((requestInfo >> PARALLEL_SHIFT) & PARALLEL_MASK);
165 }
166 
167 inline
168 Uint8
getLockMode(const UintR & requestInfo)169 ScanTabReq::getLockMode(const UintR & requestInfo){
170   return (Uint8)((requestInfo >> LOCK_MODE_SHIFT) & LOCK_MODE_MASK);
171 }
172 
173 inline
174 Uint8
getHoldLockFlag(const UintR & requestInfo)175 ScanTabReq::getHoldLockFlag(const UintR & requestInfo){
176   return (Uint8)((requestInfo >> HOLD_LOCK_SHIFT) & HOLD_LOCK_MASK);
177 }
178 
179 inline
180 Uint8
getReadCommittedFlag(const UintR & requestInfo)181 ScanTabReq::getReadCommittedFlag(const UintR & requestInfo){
182   return (Uint8)((requestInfo >> READ_COMMITTED_SHIFT) & READ_COMMITTED_MASK);
183 }
184 
185 inline
186 Uint8
getRangeScanFlag(const UintR & requestInfo)187 ScanTabReq::getRangeScanFlag(const UintR & requestInfo){
188   return (Uint8)((requestInfo >> RANGE_SCAN_SHIFT) & RANGE_SCAN_MASK);
189 }
190 
191 inline
192 Uint8
getDescendingFlag(const UintR & requestInfo)193 ScanTabReq::getDescendingFlag(const UintR & requestInfo){
194   return (Uint8)((requestInfo >> DESCENDING_SHIFT) & DESCENDING_MASK);
195 }
196 
197 inline
198 Uint8
getTupScanFlag(const UintR & requestInfo)199 ScanTabReq::getTupScanFlag(const UintR & requestInfo){
200   return (Uint8)((requestInfo >> TUP_SCAN_SHIFT) & TUP_SCAN_MASK);
201 }
202 
203 inline
204 Uint16
getScanBatch(const Uint32 & requestInfo)205 ScanTabReq::getScanBatch(const Uint32 & requestInfo){
206   return (Uint16)((requestInfo >> SCAN_BATCH_SHIFT) & SCAN_BATCH_MASK);
207 }
208 
209 inline
210 void
clearRequestInfo(UintR & requestInfo)211 ScanTabReq::clearRequestInfo(UintR & requestInfo){
212   requestInfo = 0;
213 }
214 
215 inline
216 void
setParallelism(UintR & requestInfo,Uint32 type)217 ScanTabReq::setParallelism(UintR & requestInfo, Uint32 type){
218   ASSERT_MAX(type, PARALLEL_MASK, "ScanTabReq::setParallelism");
219   requestInfo= (requestInfo & ~(PARALLEL_MASK << PARALLEL_SHIFT)) |
220                ((type & PARALLEL_MASK) << PARALLEL_SHIFT);
221 }
222 
223 inline
224 void
setLockMode(UintR & requestInfo,Uint32 mode)225 ScanTabReq::setLockMode(UintR & requestInfo, Uint32 mode){
226   ASSERT_MAX(mode, LOCK_MODE_MASK,  "ScanTabReq::setLockMode");
227   requestInfo= (requestInfo & ~(LOCK_MODE_MASK << LOCK_MODE_SHIFT)) |
228                ((mode & LOCK_MODE_MASK) << LOCK_MODE_SHIFT);
229 }
230 
231 inline
232 void
setHoldLockFlag(UintR & requestInfo,Uint32 flag)233 ScanTabReq::setHoldLockFlag(UintR & requestInfo, Uint32 flag){
234   ASSERT_BOOL(flag, "ScanTabReq::setHoldLockFlag");
235   requestInfo= (requestInfo & ~(HOLD_LOCK_MASK << HOLD_LOCK_SHIFT)) |
236                ((flag & HOLD_LOCK_MASK) << HOLD_LOCK_SHIFT);
237 }
238 
239 inline
240 void
setReadCommittedFlag(UintR & requestInfo,Uint32 flag)241 ScanTabReq::setReadCommittedFlag(UintR & requestInfo, Uint32 flag){
242   ASSERT_BOOL(flag, "ScanTabReq::setReadCommittedFlag");
243   requestInfo= (requestInfo & ~(READ_COMMITTED_MASK << READ_COMMITTED_SHIFT)) |
244                ((flag & READ_COMMITTED_MASK) << READ_COMMITTED_SHIFT);
245 }
246 
247 inline
248 void
setRangeScanFlag(UintR & requestInfo,Uint32 flag)249 ScanTabReq::setRangeScanFlag(UintR & requestInfo, Uint32 flag){
250   ASSERT_BOOL(flag, "ScanTabReq::setRangeScanFlag");
251   requestInfo= (requestInfo & ~(RANGE_SCAN_MASK << RANGE_SCAN_SHIFT)) |
252                ((flag & RANGE_SCAN_MASK) << RANGE_SCAN_SHIFT);
253 }
254 
255 inline
256 void
setDescendingFlag(UintR & requestInfo,Uint32 flag)257 ScanTabReq::setDescendingFlag(UintR & requestInfo, Uint32 flag){
258   ASSERT_BOOL(flag, "ScanTabReq::setDescendingFlag");
259   requestInfo= (requestInfo & ~(DESCENDING_MASK << DESCENDING_SHIFT)) |
260                ((flag & DESCENDING_MASK) << DESCENDING_SHIFT);
261 }
262 
263 inline
264 void
setTupScanFlag(UintR & requestInfo,Uint32 flag)265 ScanTabReq::setTupScanFlag(UintR & requestInfo, Uint32 flag){
266   ASSERT_BOOL(flag, "ScanTabReq::setTupScanFlag");
267   requestInfo= (requestInfo & ~(TUP_SCAN_MASK << TUP_SCAN_SHIFT)) |
268                ((flag & TUP_SCAN_MASK) << TUP_SCAN_SHIFT);
269 }
270 
271 inline
272 void
setScanBatch(Uint32 & requestInfo,Uint32 flag)273 ScanTabReq::setScanBatch(Uint32 & requestInfo, Uint32 flag){
274   ASSERT_MAX(flag, SCAN_BATCH_MASK,  "ScanTabReq::setScanBatch");
275   requestInfo= (requestInfo & ~(SCAN_BATCH_MASK << SCAN_BATCH_SHIFT)) |
276                ((flag & SCAN_BATCH_MASK) << SCAN_BATCH_SHIFT);
277 }
278 
279 inline
280 Uint8
getKeyinfoFlag(const UintR & requestInfo)281 ScanTabReq::getKeyinfoFlag(const UintR & requestInfo){
282   return (Uint8)((requestInfo >> KEYINFO_SHIFT) & KEYINFO_MASK);
283 }
284 
285 inline
286 void
setKeyinfoFlag(UintR & requestInfo,Uint32 flag)287 ScanTabReq::setKeyinfoFlag(UintR & requestInfo, Uint32 flag){
288   ASSERT_BOOL(flag, "ScanTabReq::setKeyinfoFlag");
289   requestInfo= (requestInfo & ~(KEYINFO_MASK << KEYINFO_SHIFT)) |
290                ((flag & KEYINFO_MASK) << KEYINFO_SHIFT);
291 }
292 
293 inline
294 Uint8
getDistributionKeyFlag(const UintR & requestInfo)295 ScanTabReq::getDistributionKeyFlag(const UintR & requestInfo){
296   return (Uint8)((requestInfo >> SCAN_DISTR_KEY_SHIFT) & SCAN_DISTR_KEY_MASK);
297 }
298 
299 inline
300 void
setDistributionKeyFlag(UintR & requestInfo,Uint32 flag)301 ScanTabReq::setDistributionKeyFlag(UintR & requestInfo, Uint32 flag){
302   ASSERT_BOOL(flag, "ScanTabReq::setKeyinfoFlag");
303   requestInfo= (requestInfo & ~(SCAN_DISTR_KEY_MASK << SCAN_DISTR_KEY_SHIFT)) |
304                ((flag & SCAN_DISTR_KEY_MASK) << SCAN_DISTR_KEY_SHIFT);
305 }
306 
307 inline
308 UintR
getNoDiskFlag(const UintR & requestInfo)309 ScanTabReq::getNoDiskFlag(const UintR & requestInfo){
310   return (requestInfo >> SCAN_NODISK_SHIFT) & SCAN_NODISK_MASK;
311 }
312 
313 inline
314 void
setNoDiskFlag(UintR & requestInfo,Uint32 flag)315 ScanTabReq::setNoDiskFlag(UintR & requestInfo, Uint32 flag){
316   ASSERT_BOOL(flag, "TcKeyReq::setNoDiskFlag");
317   requestInfo= (requestInfo & ~(SCAN_NODISK_MASK << SCAN_NODISK_SHIFT)) |
318                ((flag & SCAN_NODISK_MASK) << SCAN_NODISK_SHIFT);
319 }
320 
321 /**
322  *
323  * SENDER:  Dbtc
324  * RECIVER: API
325  */
326 class ScanTabConf {
327   /**
328    * Reciver(s)
329    */
330   friend class NdbTransaction;         // Reciver
331 
332   /**
333    * Sender(s)
334    */
335   friend class Dbtc;
336 
337   /**
338    * For printing
339    */
340   friend bool printSCANTABCONF(FILE * output, const Uint32 * theData, Uint32 len, Uint16 receiverBlockNo);
341 
342 public:
343   /**
344    * Length of signal
345    */
346   STATIC_CONST( SignalLength = 4 );
347   STATIC_CONST( EndOfData = (1 << 31) );
348 
349 private:
350 
351   // Type definitions
352 
353   /**
354    * DATA VARIABLES
355    */
356   UintR apiConnectPtr;        // DATA 0
357   UintR requestInfo;          // DATA 1
358   UintR transId1;             // DATA 2
359   UintR transId2;             // DATA 3
360 
361   struct OpData {
362     Uint32 apiPtrI;
363     Uint32 tcPtrI;
364     Uint32 info;
365   };
366 
getLength(Uint32 opDataInfo)367   static Uint32 getLength(Uint32 opDataInfo) { return opDataInfo >> 10; };
getRows(Uint32 opDataInfo)368   static Uint32 getRows(Uint32 opDataInfo) { return opDataInfo & 1023;}
369 };
370 
371 /**
372  * request info
373  *
374  o = received operations        - 7  Bits -> Max 255 (Bit 0-7)
375  s = status of scan             - 2  Bits -> Max ??? (Bit 8-?)
376 
377            1111111111222222222233
378  01234567890123456789012345678901
379  ooooooooss
380 */
381 
382 #define OPERATIONS_SHIFT     (0)
383 #define OPERATIONS_MASK      (0xFF)
384 
385 #define STATUS_SHIFT     (8)
386 #define STATUS_MASK      (0xFF)
387 
388 
389 /**
390  *
391  * SENDER:  Dbtc
392  * RECIVER: API
393  */
394 class ScanTabRef {
395   /**
396    * Reciver(s)
397    */
398   friend class NdbTransaction;         // Reciver
399 
400   /**
401    * Sender(s)
402    */
403   friend class Dbtc;
404 
405   /**
406    * For printing
407    */
408   friend bool printSCANTABREF(FILE * output, const Uint32 * theData, Uint32 len, Uint16 receiverBlockNo);
409 
410 public:
411   /**
412    * Length of signal
413    */
414   STATIC_CONST( SignalLength = 5 );
415 
416 private:
417 
418   // Type definitions
419 
420   /**
421    * DATA VARIABLES
422    */
423   UintR apiConnectPtr;        // DATA 0
424   UintR transId1;             // DATA 1
425   UintR transId2;             // DATA 2
426   UintR errorCode;            // DATA 3
427   UintR closeNeeded;          // DATA 4
428 
429 };
430 
431 /**
432  *
433  * SENDER:  API
434  * RECIVER: Dbtc
435  */
436 class ScanNextReq {
437   /**
438    * Reciver(s)
439    */
440   friend class Dbtc;         // Reciver
441 
442   /**
443    * Sender(s)
444    */
445   friend class NdbOperation;
446 
447   /**
448    * For printing
449    */
450   friend bool printSCANNEXTREQ(FILE * output, const Uint32 * theData, Uint32 len, Uint16 receiverBlockNo);
451 
452 public:
453   /**
454    * Length of signal
455    */
456   STATIC_CONST( SignalLength = 4 );
457 
458 private:
459 
460   // Type definitions
461 
462   /**
463    * DATA VARIABLES
464    */
465   UintR apiConnectPtr;        // DATA 0
466   UintR stopScan;             // DATA 1
467   UintR transId1;             // DATA 2
468   UintR transId2;             // DATA 3
469 
470   // stopScan = 1, stop this scan
471 
472 };
473 
474 #endif
475