1 /*
2    Copyright (c) 2003, 2021, Oracle and/or its affiliates.
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 TUP_KEY_H
26 #define TUP_KEY_H
27 
28 #include "SignalData.hpp"
29 
30 #define JAM_FILE_ID 57
31 
32 
33 class TupKeyReq {
34   /**
35    * Reciver(s)
36    */
37   friend class Dbtup;
38 
39   /**
40    * Sender(s)
41    */
42   friend class Dblqh;
43 
44   /**
45    * For printing
46    */
47   friend bool printTUPKEYREQ(FILE * output, const Uint32 * theData, Uint32 len, Uint16 receiverBlockNo);
48 
49 public:
50   STATIC_CONST( SignalLength = 21 );
51 
52 private:
53 
54   /**
55    * DATA VARIABLES
56    */
57   Uint32 connectPtr;
58   Uint32 request;
59   Uint32 keyRef1;
60   Uint32 keyRef2;
61   Uint32 attrBufLen;
62   Uint32 opRef;
63   Uint32 applRef;
64   Uint32 storedProcedure;
65   Uint32 transId1;
66   Uint32 transId2;
67   Uint32 fragPtr;
68   Uint32 primaryReplica;
69   Uint32 coordinatorTC;
70   Uint32 tcOpIndex;
71   Uint32 savePointId;
72   Uint32 disk_page;
73   Uint32 m_row_id_page_no;
74   Uint32 m_row_id_page_idx;
75   Uint32 attrInfoIVal;
76   Uint32 deferred_constraints;
77   Uint32 disable_fk_checks;
78 
79   static Uint32 getDirtyFlag(Uint32 const& requestInfo);
80   static Uint32 getSimpleFlag(Uint32 const& requestInfo);
81   static Uint32 getOperation(Uint32 const& requestInfo);
82   static Uint32 getInterpretedFlag(Uint32 const& requestInfo);
83   static Uint32 getRowidFlag(Uint32 const& requestInfo);
84   static Uint32 getReorgFlag(Uint32 const& requestInfo);
85   static Uint32 getPrioAFlag(Uint32 const& requestInfo);
86   static void setDirtyFlag(Uint32 & requestInfo, Uint32 value);
87   static void setSimpleFlag(Uint32 & requestInfo, Uint32 value);
88   static void setOperation(Uint32 & requestInfo, Uint32 value);
89   static void setInterpretedFlag(Uint32 & requestInfo, Uint32 value);
90   static void setRowidFlag(Uint32 & requestInfo, Uint32 value);
91   static void setReorgFlag(Uint32 & requestInfo, Uint32 value);
92   static void setPrioAFlag(Uint32 & requestInfo, Uint32 value);
93 
94   /*
95     Request Info
96 
97               111111 1111222222222233
98     0123456789012345 6789012345678901
99     ds....ooo.izrra. ................
100   */
101 
102   enum RequestInfo {
103     DIRTY_POS       =  0, DIRTY_MASK       = 1,
104     SIMPLE_POS      =  1, SIMPLE_MASK      = 1,
105     OPERATION_POS   =  6, OPERATION_MASK   = 7,
106     INTERPRETED_POS = 10, INTERPRETED_MASK = 1,
107     ROWID_POS       = 11, ROWID_MASK       = 1,
108     REORG_POS       = 12, REORG_MASK       = 3,
109     PRIO_A_POS      = 14, PRIO_A_MASK      = 1
110   };
111 };
112 
113 inline Uint32
getDirtyFlag(Uint32 const & requestInfo)114 TupKeyReq::getDirtyFlag(Uint32 const& requestInfo)
115 {
116   return (requestInfo >> DIRTY_POS) & DIRTY_MASK;
117 }
118 
119 inline Uint32
getSimpleFlag(Uint32 const & requestInfo)120 TupKeyReq::getSimpleFlag(Uint32 const& requestInfo)
121 {
122   return (requestInfo >> SIMPLE_POS) & SIMPLE_MASK;
123 }
124 
125 inline Uint32
getOperation(Uint32 const & requestInfo)126 TupKeyReq::getOperation(Uint32 const& requestInfo)
127 {
128   return (requestInfo >> OPERATION_POS) & OPERATION_MASK;
129 }
130 
131 inline Uint32
getInterpretedFlag(Uint32 const & requestInfo)132 TupKeyReq::getInterpretedFlag(Uint32 const& requestInfo)
133 {
134   return (requestInfo >> INTERPRETED_POS) & INTERPRETED_MASK;
135 }
136 
137 inline Uint32
getRowidFlag(Uint32 const & requestInfo)138 TupKeyReq::getRowidFlag(Uint32 const& requestInfo)
139 {
140   return (requestInfo >> ROWID_POS) & ROWID_MASK;
141 }
142 
143 inline Uint32
getReorgFlag(Uint32 const & requestInfo)144 TupKeyReq::getReorgFlag(Uint32 const& requestInfo)
145 {
146   return (requestInfo >> REORG_POS) & REORG_MASK;
147 }
148 
149 inline Uint32
getPrioAFlag(Uint32 const & requestInfo)150 TupKeyReq::getPrioAFlag(Uint32 const& requestInfo)
151 {
152   return (requestInfo >> PRIO_A_POS) & PRIO_A_MASK;
153 }
154 
155 inline void
setDirtyFlag(Uint32 & requestInfo,Uint32 value)156 TupKeyReq::setDirtyFlag(Uint32 & requestInfo, Uint32 value)
157 {
158   assert(value <= DIRTY_MASK);
159   assert((requestInfo & (DIRTY_MASK << DIRTY_POS)) == 0);
160   requestInfo |= value << DIRTY_POS;
161 }
162 
163 inline void
setSimpleFlag(Uint32 & requestInfo,Uint32 value)164 TupKeyReq::setSimpleFlag(Uint32 & requestInfo, Uint32 value)
165 {
166   assert(value <= SIMPLE_MASK);
167   assert((requestInfo & (SIMPLE_MASK << SIMPLE_POS)) == 0);
168   requestInfo |= value << SIMPLE_POS;
169 }
170 
171 inline void
setOperation(Uint32 & requestInfo,Uint32 value)172 TupKeyReq::setOperation(Uint32 & requestInfo, Uint32 value)
173 {
174   assert(value <= OPERATION_MASK);
175   assert((requestInfo & (OPERATION_MASK << OPERATION_POS)) == 0);
176   requestInfo |= value << OPERATION_POS;
177 }
178 
179 inline void
setInterpretedFlag(Uint32 & requestInfo,Uint32 value)180 TupKeyReq::setInterpretedFlag(Uint32 & requestInfo, Uint32 value)
181 {
182   assert(value <= INTERPRETED_MASK);
183   assert((requestInfo & (INTERPRETED_MASK << INTERPRETED_POS)) == 0);
184   requestInfo |= value << INTERPRETED_POS;
185 }
186 
187 inline void
setRowidFlag(Uint32 & requestInfo,Uint32 value)188 TupKeyReq::setRowidFlag(Uint32 & requestInfo, Uint32 value)
189 {
190   assert(value <= ROWID_MASK);
191   assert((requestInfo & (ROWID_MASK << ROWID_POS)) == 0);
192   requestInfo |= value << ROWID_POS;
193 }
194 
195 inline void
setReorgFlag(Uint32 & requestInfo,Uint32 value)196 TupKeyReq::setReorgFlag(Uint32 & requestInfo, Uint32 value)
197 {
198   assert(value <= REORG_MASK);
199   assert((requestInfo & (REORG_MASK << REORG_POS)) == 0);
200   requestInfo |= value << REORG_POS;
201 }
202 
203 inline void
setPrioAFlag(Uint32 & requestInfo,Uint32 value)204 TupKeyReq::setPrioAFlag(Uint32 & requestInfo, Uint32 value)
205 {
206   assert(value <= PRIO_A_MASK);
207   assert((requestInfo & (PRIO_A_MASK << PRIO_A_POS)) == 0);
208   requestInfo |= value << PRIO_A_POS;
209 }
210 
211 class TupKeyConf {
212   /**
213    * Reciver(s)
214    */
215   friend class Dblqh;
216 
217   /**
218    * Sender(s)
219    */
220   friend class Dbtup;
221 
222   /**
223    * For printing
224    */
225   friend bool printTUPKEYCONF(FILE * output, const Uint32 * theData, Uint32 len, Uint16 receiverBlockNo);
226 
227 public:
228   STATIC_CONST( SignalLength = 7 );
229 
230 private:
231 
232   /**
233    * DATA VARIABLES
234    */
235   Uint32 userPtr;
236   Uint32 readLength;  // Length in Uint32 words
237   Uint32 writeLength;
238   Uint32 numFiredTriggers;
239   Uint32 lastRow;
240   Uint32 rowid;
241   // Number of interpreter instructions executed.
242   Uint32 noExecInstructions;
243 };
244 
245 class TupKeyRef {
246   /**
247    * Reciver(s)
248    */
249   friend class Dblqh;
250 
251   /**
252    * Sender(s)
253    */
254   friend class Dbtup;
255 
256   /**
257    * For printing
258    */
259   friend bool printTUPKEYREF(FILE * output, const Uint32 * theData, Uint32 len, Uint16 receiverBlockNo);
260 
261 public:
262   STATIC_CONST( SignalLength = 3 );
263 
264 private:
265 
266   /**
267    * DATA VARIABLES
268    */
269   Uint32 userRef;
270   Uint32 errorCode;
271   // Number of interpreter instructions executed.
272   Uint32 noExecInstructions;
273 };
274 
275 
276 #undef JAM_FILE_ID
277 
278 #endif
279