1 /*
2    Copyright (c) 2003, 2019, 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 #ifndef ACC_SCAN_HPP
26 #define ACC_SCAN_HPP
27 
28 #include "SignalData.hpp"
29 
30 #define JAM_FILE_ID 121
31 
32 
33 /*
34  * Used by ACC and TUX and TUP scan.
35  */
36 
37 class AccScanReq {
38   /**
39    * Sender(s)
40    */
41   friend class Dblqh;
42 
43   /**
44    * Reciver(s)
45    */
46   friend class Dbacc;
47   friend class Dbtux;
48   friend class Dbtup;
49 public:
50   STATIC_CONST( SignalLength = 8 );
51 
52 private:
53   Uint32 senderData;
54   Uint32 senderRef;
55   Uint32 tableId;
56   Uint32 fragmentNo;
57   Uint32 requestInfo;
58   Uint32 transId1;
59   Uint32 transId2;
60   union {
61     Uint32 savePointId;
62     Uint32 gci;
63   };
64   Uint32 maxPage;
65 
66   /**
67    * Previously there where also a scan type
68    */
69   static Uint32 getLockMode(const Uint32 & requestInfo);
70   static Uint32 getReadCommittedFlag(const Uint32 & requestInfo);
71   static Uint32 getDescendingFlag(const Uint32 & requestInfo);
72 
73   static void setLockMode(Uint32 & requestInfo, Uint32 lockMode);
74   static void setReadCommittedFlag(Uint32 & requestInfo, Uint32 readCommitted);
75   static void setDescendingFlag(Uint32 & requestInfo, Uint32 descending);
76 
77   static Uint32 getNoDiskScanFlag(const Uint32 & requestInfo);
78   static void setNoDiskScanFlag(Uint32 & requestInfo, Uint32 nodisk);
79 
80   static Uint32 getNRScanFlag(const Uint32 & requestInfo);
81   static void setNRScanFlag(Uint32 & requestInfo, Uint32 nr);
82 
83   static Uint32 getLcpScanFlag(const Uint32 & requestInfo);
84   static void setLcpScanFlag(Uint32 & requestInfo, Uint32 nr);
85 
86   static Uint32 getStatScanFlag(const Uint32 & requestInfo);
87   static void setStatScanFlag(Uint32 & requestInfo, Uint32 nr);
88 
89   static Uint32 getCopyFragScanFlag(const Uint32 & requestInfo);
90   static void setCopyFragScanFlag(Uint32 & requestInfo, Uint32 nr);
91 };
92 
93 /**
94  * Request Info
95  *
96  * l = Lock Mode             - 1  Bit 2
97  * h = Read Committed        - 1  Bit 5
98  * z = Descending (TUX)      - 1  Bit 6
99  * d = No disk scan          - 1  Bit 7
100  * n = Node recovery scan    - 1  Bit 8
101  * c = LCP scan              - 1  Bit 9
102  * s = Statistics scan       - 1  Bit 4
103  * f = Copy fragment scan    - 1  Bit 10
104  *
105  *           1111111111222222222233
106  * 01234567890123456789012345678901
107  *   l shzdncf
108  */
109 #define AS_LOCK_MODE_SHIFT       (2)
110 #define AS_LOCK_MODE_MASK        (1)
111 #define AS_READ_COMMITTED_SHIFT  (5)
112 #define AS_DESCENDING_SHIFT      (6)
113 #define AS_NO_DISK_SCAN          (7)
114 #define AS_NR_SCAN               (8)
115 #define AS_LCP_SCAN              (9)
116 #define AS_STAT_SCAN             (4)
117 #define AS_COPY_FRAG_SCAN        (10)
118 
119 inline
120 Uint32
getLockMode(const Uint32 & requestInfo)121 AccScanReq::getLockMode(const Uint32 & requestInfo){
122   return (requestInfo >> AS_LOCK_MODE_SHIFT) & AS_LOCK_MODE_MASK;
123 }
124 
125 inline
126 Uint32
getReadCommittedFlag(const Uint32 & requestInfo)127 AccScanReq::getReadCommittedFlag(const Uint32 & requestInfo){
128   return (requestInfo >> AS_READ_COMMITTED_SHIFT) & 1;
129 }
130 
131 inline
132 Uint32
getDescendingFlag(const Uint32 & requestInfo)133 AccScanReq::getDescendingFlag(const Uint32 & requestInfo){
134   return (requestInfo >> AS_DESCENDING_SHIFT) & 1;
135 }
136 
137 inline
138 void
setLockMode(UintR & requestInfo,UintR val)139 AccScanReq::setLockMode(UintR & requestInfo, UintR val){
140   ASSERT_MAX(val, AS_LOCK_MODE_MASK, "AccScanReq::setLockMode");
141   requestInfo |= (val << AS_LOCK_MODE_SHIFT);
142 }
143 
144 inline
145 void
setReadCommittedFlag(UintR & requestInfo,UintR val)146 AccScanReq::setReadCommittedFlag(UintR & requestInfo, UintR val){
147   ASSERT_BOOL(val, "AccScanReq::setReadCommittedFlag");
148   requestInfo |= (val << AS_READ_COMMITTED_SHIFT);
149 }
150 
151 inline
152 void
setDescendingFlag(UintR & requestInfo,UintR val)153 AccScanReq::setDescendingFlag(UintR & requestInfo, UintR val){
154   ASSERT_BOOL(val, "AccScanReq::setDescendingFlag");
155   requestInfo |= (val << AS_DESCENDING_SHIFT);
156 }
157 
158 inline
159 Uint32
getNoDiskScanFlag(const Uint32 & requestInfo)160 AccScanReq::getNoDiskScanFlag(const Uint32 & requestInfo){
161   return (requestInfo >> AS_NO_DISK_SCAN) & 1;
162 }
163 
164 inline
165 void
setNoDiskScanFlag(UintR & requestInfo,UintR val)166 AccScanReq::setNoDiskScanFlag(UintR & requestInfo, UintR val){
167   ASSERT_BOOL(val, "AccScanReq::setNoDiskScanFlag");
168   requestInfo |= (val << AS_NO_DISK_SCAN);
169 }
170 
171 inline
172 Uint32
getNRScanFlag(const Uint32 & requestInfo)173 AccScanReq::getNRScanFlag(const Uint32 & requestInfo){
174   return (requestInfo >> AS_NR_SCAN) & 1;
175 }
176 
177 inline
178 void
setNRScanFlag(UintR & requestInfo,UintR val)179 AccScanReq::setNRScanFlag(UintR & requestInfo, UintR val){
180   ASSERT_BOOL(val, "AccScanReq::setNoDiskScanFlag");
181   requestInfo |= (val << AS_NR_SCAN);
182 }
183 
184 inline
185 Uint32
getLcpScanFlag(const Uint32 & requestInfo)186 AccScanReq::getLcpScanFlag(const Uint32 & requestInfo){
187   return (requestInfo >> AS_LCP_SCAN) & 1;
188 }
189 
190 inline
191 void
setLcpScanFlag(UintR & requestInfo,UintR val)192 AccScanReq::setLcpScanFlag(UintR & requestInfo, UintR val){
193   ASSERT_BOOL(val, "AccScanReq::setNoDiskScanFlag");
194   requestInfo |= (val << AS_LCP_SCAN);
195 }
196 
197 inline
198 Uint32
getStatScanFlag(const Uint32 & requestInfo)199 AccScanReq::getStatScanFlag(const Uint32 & requestInfo){
200   return (requestInfo >> AS_STAT_SCAN) & 1;
201 }
202 
203 inline
204 void
setStatScanFlag(UintR & requestInfo,UintR val)205 AccScanReq::setStatScanFlag(UintR & requestInfo, UintR val){
206   ASSERT_BOOL(val, "AccScanReq::setStatScanScanFlag");
207   requestInfo |= (val << AS_STAT_SCAN);
208 }
209 
210 inline
211 Uint32
getCopyFragScanFlag(const Uint32 & requestInfo)212 AccScanReq::getCopyFragScanFlag(const Uint32 & requestInfo){
213   return (requestInfo >> AS_COPY_FRAG_SCAN) & 1;
214 }
215 
216 inline
217 void
setCopyFragScanFlag(UintR & requestInfo,UintR val)218 AccScanReq::setCopyFragScanFlag(UintR & requestInfo, UintR val){
219   ASSERT_BOOL(val, "AccScanReq::setCopyFragScanFlag");
220   requestInfo |= (val << AS_COPY_FRAG_SCAN);
221 }
222 
223 class AccScanConf {
224   /**
225    * Sender(s)
226    */
227   friend class Dbacc;
228   friend class Dbtux;
229   friend class Dbtup;
230 
231   /**
232    * Reciver(s)
233    */
234   friend class Dblqh;
235 
236   enum {
237     ZEMPTY_FRAGMENT = 0,
238     ZNOT_EMPTY_FRAGMENT = 1
239   };
240 
241 public:
242   STATIC_CONST( SignalLength = 8 );
243 
244 private:
245   Uint32 scanPtr;
246   Uint32 accPtr;
247   Uint32 unused1;
248   Uint32 unused2;
249   Uint32 unused3;
250   Uint32 unused4;
251   Uint32 unused5;
252   Uint32 flag;
253 };
254 
255 class AccScanRef {
256   friend class Dbtux;
257   friend class Dblqh;
258   friend class Dbtup;
259   friend class Dbacc;
260 
261   enum ErrorCode {
262     TuxNoFreeScanOp = 909,
263     TuxIndexNotOnline = 910,
264     TuxInvalidKeySize = 911,
265     TuxInvalidLockMode = 912,
266     TuxNoFreeStatOp = 915,
267     TupNoFreeScanOp = 925,
268     AccNoFreeScanOp = 926,
269   };
270 
271 public:
272   STATIC_CONST( SignalLength = 3 );
273 
274 private:
275   Uint32 scanPtr;
276   Uint32 accPtr;
277   Uint32 errorCode;
278 };
279 
280 class AccCheckScan {
281   friend class Dbacc;
282   friend class Dbtux;
283   friend class Dbtup;
284   friend class Dblqh;
285   enum {
286     ZCHECK_LCP_STOP     = 0,   // Execution should check-in with LQH
287     ZNOT_CHECK_LCP_STOP = 1    // Execution should not check-in with LQH
288   };
289 
290 public:
291   STATIC_CONST( SignalLength = 2 );
292 private:
293   Uint32 accPtr;                // scanptr.i in ACC/TUX/TUP
294   Uint32 checkLcpStop;          // from enum
295 };
296 
297 class CheckLcpStop
298 {
299   friend class Dbacc;
300   friend class Dbtux;
301   friend class Dbtup;
302   friend class Dblqh;
303 
304   enum ScanState
305   {
306     ZSCAN_RUNNABLE = 0,               // Scan runnable immediately
307     ZSCAN_RESOURCE_WAIT = 1,          // Scan waiting for something
308     ZSCAN_RUNNABLE_YIELD = 2,         // Scan runnable, yielding cpu
309     ZSCAN_RESOURCE_WAIT_STOPPABLE = 3 // Scan waiting for something
310   };
311 
312   enum Reply
313   {
314     // In signal[0] after EXECUTE_DIRECT
315     ZTAKE_A_BREAK = RNIL,
316     ZABORT_SCAN = 0
317   };
318 public:
319   STATIC_CONST( SignalLength = 2);
320 private:
321   Uint32 scanPtrI;            // scanptr.i from ACC/TUX/TUP
322   Uint32 scanState;
323 };
324 
325 #undef JAM_FILE_ID
326 
327 #endif
328