1 /*
2    Copyright (c) 2003, 2013, 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 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 
90 /**
91  * Request Info
92  *
93  * l = Lock Mode             - 1  Bit 2
94  * h = Read Committed        - 1  Bit 5
95  * z = Descending (TUX)      - 1  Bit 6
96  * d = No disk scan          - 1  Bit 7
97  * n = Node recovery scan    - 1  Bit 8
98  * c = LCP scan              - 1  Bit 9
99  * s = Statistics scan       - 1  Bit 4
100  *
101  *           1111111111222222222233
102  * 01234567890123456789012345678901
103  *   l shzdn
104  */
105 #define AS_LOCK_MODE_SHIFT       (2)
106 #define AS_LOCK_MODE_MASK        (1)
107 #define AS_READ_COMMITTED_SHIFT  (5)
108 #define AS_DESCENDING_SHIFT      (6)
109 #define AS_NO_DISK_SCAN          (7)
110 #define AS_NR_SCAN               (8)
111 #define AS_LCP_SCAN              (9)
112 #define AS_STAT_SCAN             (4)
113 
114 inline
115 Uint32
getLockMode(const Uint32 & requestInfo)116 AccScanReq::getLockMode(const Uint32 & requestInfo){
117   return (requestInfo >> AS_LOCK_MODE_SHIFT) & AS_LOCK_MODE_MASK;
118 }
119 
120 inline
121 Uint32
getReadCommittedFlag(const Uint32 & requestInfo)122 AccScanReq::getReadCommittedFlag(const Uint32 & requestInfo){
123   return (requestInfo >> AS_READ_COMMITTED_SHIFT) & 1;
124 }
125 
126 inline
127 Uint32
getDescendingFlag(const Uint32 & requestInfo)128 AccScanReq::getDescendingFlag(const Uint32 & requestInfo){
129   return (requestInfo >> AS_DESCENDING_SHIFT) & 1;
130 }
131 
132 inline
133 void
setLockMode(UintR & requestInfo,UintR val)134 AccScanReq::setLockMode(UintR & requestInfo, UintR val){
135   ASSERT_MAX(val, AS_LOCK_MODE_MASK, "AccScanReq::setLockMode");
136   requestInfo |= (val << AS_LOCK_MODE_SHIFT);
137 }
138 
139 inline
140 void
setReadCommittedFlag(UintR & requestInfo,UintR val)141 AccScanReq::setReadCommittedFlag(UintR & requestInfo, UintR val){
142   ASSERT_BOOL(val, "AccScanReq::setReadCommittedFlag");
143   requestInfo |= (val << AS_READ_COMMITTED_SHIFT);
144 }
145 
146 inline
147 void
setDescendingFlag(UintR & requestInfo,UintR val)148 AccScanReq::setDescendingFlag(UintR & requestInfo, UintR val){
149   ASSERT_BOOL(val, "AccScanReq::setDescendingFlag");
150   requestInfo |= (val << AS_DESCENDING_SHIFT);
151 }
152 
153 inline
154 Uint32
getNoDiskScanFlag(const Uint32 & requestInfo)155 AccScanReq::getNoDiskScanFlag(const Uint32 & requestInfo){
156   return (requestInfo >> AS_NO_DISK_SCAN) & 1;
157 }
158 
159 inline
160 void
setNoDiskScanFlag(UintR & requestInfo,UintR val)161 AccScanReq::setNoDiskScanFlag(UintR & requestInfo, UintR val){
162   ASSERT_BOOL(val, "AccScanReq::setNoDiskScanFlag");
163   requestInfo |= (val << AS_NO_DISK_SCAN);
164 }
165 
166 inline
167 Uint32
getNRScanFlag(const Uint32 & requestInfo)168 AccScanReq::getNRScanFlag(const Uint32 & requestInfo){
169   return (requestInfo >> AS_NR_SCAN) & 1;
170 }
171 
172 inline
173 void
setNRScanFlag(UintR & requestInfo,UintR val)174 AccScanReq::setNRScanFlag(UintR & requestInfo, UintR val){
175   ASSERT_BOOL(val, "AccScanReq::setNoDiskScanFlag");
176   requestInfo |= (val << AS_NR_SCAN);
177 }
178 
179 inline
180 Uint32
getLcpScanFlag(const Uint32 & requestInfo)181 AccScanReq::getLcpScanFlag(const Uint32 & requestInfo){
182   return (requestInfo >> AS_LCP_SCAN) & 1;
183 }
184 
185 inline
186 void
setLcpScanFlag(UintR & requestInfo,UintR val)187 AccScanReq::setLcpScanFlag(UintR & requestInfo, UintR val){
188   ASSERT_BOOL(val, "AccScanReq::setNoDiskScanFlag");
189   requestInfo |= (val << AS_LCP_SCAN);
190 }
191 
192 inline
193 Uint32
getStatScanFlag(const Uint32 & requestInfo)194 AccScanReq::getStatScanFlag(const Uint32 & requestInfo){
195   return (requestInfo >> AS_STAT_SCAN) & 1;
196 }
197 
198 inline
199 void
setStatScanFlag(UintR & requestInfo,UintR val)200 AccScanReq::setStatScanFlag(UintR & requestInfo, UintR val){
201   ASSERT_BOOL(val, "AccScanReq::setStatScanScanFlag");
202   requestInfo |= (val << AS_STAT_SCAN);
203 }
204 
205 class AccScanConf {
206   /**
207    * Sender(s)
208    */
209   friend class Dbacc;
210   friend class Dbtux;
211   friend class Dbtup;
212 
213   /**
214    * Reciver(s)
215    */
216   friend class Dblqh;
217 
218   enum {
219     ZEMPTY_FRAGMENT = 0,
220     ZNOT_EMPTY_FRAGMENT = 1
221   };
222 
223 public:
224   STATIC_CONST( SignalLength = 8 );
225 
226 private:
227   Uint32 scanPtr;
228   Uint32 accPtr;
229   Uint32 unused1;
230   Uint32 unused2;
231   Uint32 unused3;
232   Uint32 unused4;
233   Uint32 unused5;
234   Uint32 flag;
235 };
236 
237 class AccScanRef {
238   friend class Dbtux;
239   friend class Dblqh;
240 
241   enum ErrorCode {
242     TuxNoFreeScanOp = 909,
243     TuxIndexNotOnline = 910,
244     TuxNoFreeStatOp = 911,
245     TuxInvalidLockMode = 912
246   };
247 
248 public:
249   STATIC_CONST( SignalLength = 3 );
250 
251 private:
252   Uint32 scanPtr;
253   Uint32 accPtr;
254   Uint32 errorCode;
255 };
256 
257 class AccCheckScan {
258   friend class Dbacc;
259   friend class Dbtux;
260   friend class Dbtup;
261   friend class Dblqh;
262   enum {
263     ZCHECK_LCP_STOP = 0,
264     ZNOT_CHECK_LCP_STOP = 1
265   };
266 public:
267   STATIC_CONST( SignalLength = 2 );
268 private:
269   Uint32 accPtr;                // scanptr.i in ACC or TUX
270   Uint32 checkLcpStop;          // from enum
271 };
272 
273 
274 #undef JAM_FILE_ID
275 
276 #endif
277