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 ALTER_TABLE_HPP
26 #define ALTER_TABLE_HPP
27 
28 #include "SignalData.hpp"
29 
30 #define JAM_FILE_ID 112
31 
32 
33 struct AlterTableReq {
34   STATIC_CONST( SignalLength = 8 );
35 
36   Uint32 clientRef;
37   Uint32 clientData;
38   Uint32 transId;
39   Uint32 transKey;
40   Uint32 requestInfo;
41   Uint32 tableId;
42   Uint32 tableVersion;
43   Uint32 changeMask;
44 
45   SECTION( DICT_TAB_INFO = 0 );
46 
47 /**
48  * ChangeMask
49  */
50 
51 /*
52   n = Changed name
53   f = Changed frm
54   d = Changed fragment data
55   r = Changed range or list array
56   t = Changed tablespace name array
57   s = Changed tablespace id array
58   a = Add attribute
59   f = Add fragment(s)
60   r = Reorg fragment(s)
61 
62            1111111111222222222233
63  01234567890123456789012345678901
64  nfdrtsafr-----------------------
65 */
66 #define NAME_SHIFT        (0)
67 #define FRM_SHIFT         (1)
68 #define FRAG_DATA_SHIFT   (2)
69 #define RANGE_LIST_SHIFT  (3)
70 #define TS_NAME_SHIFT     (4)
71 #define TS_SHIFT          (5)
72 #define ADD_ATTR_SHIFT    (6)
73 #define ADD_FRAG_SHIFT    (7)
74 #define REORG_FRAG_SHIFT  (8)
75 #define REORG_COMMIT_SHIFT   (9)
76 #define REORG_COMPLETE_SHIFT (10)
77 #define REORG_SUMA_ENABLE (11)
78 #define REORG_SUMA_FILTER (12)
79 
80  /**
81    * Getters and setters
82    */
83   static Uint8 getNameFlag(const UintR & changeMask);
84   static void setNameFlag(UintR &  changeMask, Uint32 nameFlg);
85   static Uint8 getFrmFlag(const UintR & changeMask);
86   static void setFrmFlag(UintR &  changeMask, Uint32 frmFlg);
87   static Uint8 getFragDataFlag(const UintR & changeMask);
88   static void setFragDataFlag(UintR &  changeMask, Uint32 fragFlg);
89   static Uint8 getRangeListFlag(const UintR & changeMask);
90   static void setRangeListFlag(UintR &  changeMask, Uint32 rangeFlg);
91   static Uint8 getTsNameFlag(const UintR & changeMask);
92   static void setTsNameFlag(UintR &  changeMask, Uint32 tsNameFlg);
93   static Uint8 getTsFlag(const UintR & changeMask);
94   static void setTsFlag(UintR &  changeMask, Uint32 tsFlg);
95   static Uint8 getAddAttrFlag(const UintR & changeMask);
96   static void setAddAttrFlag(UintR &  changeMask, Uint32 tsFlg);
97   static Uint8 getAddFragFlag(const UintR & changeMask);
98   static void setAddFragFlag(UintR &  changeMask, Uint32 tsFlg);
99   static Uint8 getReorgFragFlag(const UintR & changeMask);
100   static void setReorgFragFlag(UintR &  changeMask, Uint32 tsFlg);
101   static Uint8 getReorgCommitFlag(const UintR & changeMask);
102   static void setReorgCommitFlag(UintR &  changeMask, Uint32 tsFlg);
103   static Uint8 getReorgCompleteFlag(const UintR & changeMask);
104   static void setReorgCompleteFlag(UintR &  changeMask, Uint32 tsFlg);
105   static Uint8 getReorgSumaEnableFlag(const UintR & changeMask);
106   static void setReorgSumaEnableFlag(UintR &  changeMask, Uint32 tsFlg);
107   static Uint8 getReorgSumaFilterFlag(const UintR & changeMask);
108   static void setReorgSumaFilterFlag(UintR &  changeMask, Uint32 tsFlg);
109 
getReorgSubOpAlterTableReq110   static bool getReorgSubOp(const UintR & changeMask){
111     return
112       getReorgCommitFlag(changeMask) ||
113       getReorgCompleteFlag(changeMask) ||
114       getReorgSumaEnableFlag(changeMask) ||
115       getReorgSumaFilterFlag(changeMask);
116   }
117 };
118 
119 inline
120 Uint8
getTsFlag(const UintR & changeMask)121 AlterTableReq::getTsFlag(const UintR & changeMask){
122   return (Uint8)((changeMask >> TS_SHIFT) & 1);
123 }
124 
125 inline
126 void
setTsFlag(UintR & changeMask,Uint32 tsFlg)127 AlterTableReq::setTsFlag(UintR & changeMask, Uint32 tsFlg){
128   changeMask |= (tsFlg << TS_SHIFT);
129 }
130 
131 inline
132 Uint8
getNameFlag(const UintR & changeMask)133 AlterTableReq::getNameFlag(const UintR & changeMask){
134   return (Uint8)((changeMask >> NAME_SHIFT) & 1);
135 }
136 
137 inline
138 void
setNameFlag(UintR & changeMask,Uint32 nameFlg)139 AlterTableReq::setNameFlag(UintR & changeMask, Uint32 nameFlg){
140   changeMask |= (nameFlg << NAME_SHIFT);
141 }
142 
143 inline
144 Uint8
getFrmFlag(const UintR & changeMask)145 AlterTableReq::getFrmFlag(const UintR & changeMask){
146   return (Uint8)((changeMask >> FRM_SHIFT) & 1);
147 }
148 
149 inline
150 void
setFrmFlag(UintR & changeMask,Uint32 frmFlg)151 AlterTableReq::setFrmFlag(UintR & changeMask, Uint32 frmFlg){
152   changeMask |= (frmFlg << FRM_SHIFT);
153 }
154 
155 inline
156 Uint8
getFragDataFlag(const UintR & changeMask)157 AlterTableReq::getFragDataFlag(const UintR & changeMask){
158   return (Uint8)((changeMask >> FRAG_DATA_SHIFT) & 1);
159 }
160 
161 inline
162 void
setFragDataFlag(UintR & changeMask,Uint32 fragDataFlg)163 AlterTableReq::setFragDataFlag(UintR & changeMask, Uint32 fragDataFlg){
164   changeMask |= (fragDataFlg << FRAG_DATA_SHIFT);
165 }
166 
167 inline
168 Uint8
getRangeListFlag(const UintR & changeMask)169 AlterTableReq::getRangeListFlag(const UintR & changeMask){
170   return (Uint8)((changeMask >> RANGE_LIST_SHIFT) & 1);
171 }
172 
173 inline
174 void
setRangeListFlag(UintR & changeMask,Uint32 rangeFlg)175 AlterTableReq::setRangeListFlag(UintR & changeMask, Uint32 rangeFlg){
176   changeMask |= (rangeFlg << RANGE_LIST_SHIFT);
177 }
178 
179 inline
180 Uint8
getTsNameFlag(const UintR & changeMask)181 AlterTableReq::getTsNameFlag(const UintR & changeMask){
182   return (Uint8)((changeMask >> TS_NAME_SHIFT) & 1);
183 }
184 
185 inline
186 void
setTsNameFlag(UintR & changeMask,Uint32 tsNameFlg)187 AlterTableReq::setTsNameFlag(UintR & changeMask, Uint32 tsNameFlg){
188   changeMask |= (tsNameFlg << TS_NAME_SHIFT);
189 }
190 
191 inline
192 Uint8
getAddAttrFlag(const UintR & changeMask)193 AlterTableReq::getAddAttrFlag(const UintR & changeMask){
194   return (Uint8)((changeMask >> ADD_ATTR_SHIFT) & 1);
195 }
196 
197 inline
198 void
setAddAttrFlag(UintR & changeMask,Uint32 addAttrFlg)199 AlterTableReq::setAddAttrFlag(UintR & changeMask, Uint32 addAttrFlg){
200   changeMask |= (addAttrFlg << ADD_ATTR_SHIFT);
201 }
202 
203 inline
204 Uint8
getAddFragFlag(const UintR & changeMask)205 AlterTableReq::getAddFragFlag(const UintR & changeMask){
206   return (Uint8)((changeMask >> ADD_FRAG_SHIFT) & 1);
207 }
208 
209 inline
210 void
setAddFragFlag(UintR & changeMask,Uint32 addAttrFlg)211 AlterTableReq::setAddFragFlag(UintR & changeMask, Uint32 addAttrFlg){
212   changeMask |= (addAttrFlg << ADD_FRAG_SHIFT);
213 }
214 
215 inline
216 Uint8
getReorgFragFlag(const UintR & changeMask)217 AlterTableReq::getReorgFragFlag(const UintR & changeMask){
218   return (Uint8)((changeMask >> REORG_FRAG_SHIFT) & 1);
219 }
220 
221 inline
222 void
setReorgFragFlag(UintR & changeMask,Uint32 reorgAttrFlg)223 AlterTableReq::setReorgFragFlag(UintR & changeMask, Uint32 reorgAttrFlg){
224   changeMask |= (reorgAttrFlg << REORG_FRAG_SHIFT);
225 }
226 
227 inline
228 Uint8
getReorgCommitFlag(const UintR & changeMask)229 AlterTableReq::getReorgCommitFlag(const UintR & changeMask){
230   return (Uint8)((changeMask >> REORG_COMMIT_SHIFT) & 1);
231 }
232 
233 inline
234 void
setReorgCommitFlag(UintR & changeMask,Uint32 reorgAttrFlg)235 AlterTableReq::setReorgCommitFlag(UintR & changeMask, Uint32 reorgAttrFlg){
236   changeMask |= (reorgAttrFlg << REORG_COMMIT_SHIFT);
237 }
238 
239 
240 inline
241 Uint8
getReorgCompleteFlag(const UintR & changeMask)242 AlterTableReq::getReorgCompleteFlag(const UintR & changeMask){
243   return (Uint8)((changeMask >> REORG_COMPLETE_SHIFT) & 1);
244 }
245 
246 inline
247 void
setReorgCompleteFlag(UintR & changeMask,Uint32 reorgAttrFlg)248 AlterTableReq::setReorgCompleteFlag(UintR & changeMask, Uint32 reorgAttrFlg){
249   changeMask |= (reorgAttrFlg << REORG_COMPLETE_SHIFT);
250 }
251 
252 inline
253 Uint8
getReorgSumaEnableFlag(const UintR & changeMask)254 AlterTableReq::getReorgSumaEnableFlag(const UintR & changeMask){
255   return (Uint8)((changeMask >> REORG_SUMA_ENABLE) & 1);
256 }
257 
258 inline
259 void
setReorgSumaEnableFlag(UintR & changeMask,Uint32 reorgAttrFlg)260 AlterTableReq::setReorgSumaEnableFlag(UintR & changeMask, Uint32 reorgAttrFlg){
261   changeMask |= (reorgAttrFlg << REORG_SUMA_ENABLE);
262 }
263 
264 inline
265 Uint8
getReorgSumaFilterFlag(const UintR & changeMask)266 AlterTableReq::getReorgSumaFilterFlag(const UintR & changeMask){
267   return (Uint8)((changeMask >> REORG_SUMA_FILTER) & 1);
268 }
269 
270 inline
271 void
setReorgSumaFilterFlag(UintR & changeMask,Uint32 reorgAttrFlg)272 AlterTableReq::setReorgSumaFilterFlag(UintR & changeMask, Uint32 reorgAttrFlg){
273   changeMask |= (reorgAttrFlg << REORG_SUMA_FILTER);
274 }
275 
276 struct AlterTableConf {
277   STATIC_CONST( SignalLength = 6 );
278 
279   Uint32 senderRef;
280   union {
281     Uint32 clientData;
282     Uint32 senderData;
283   };
284   Uint32 transId;
285   Uint32 tableId;
286   Uint32 tableVersion;
287   Uint32 newTableVersion;
288 };
289 
290 struct AlterTableRef {
291   STATIC_CONST( SignalLength = 9 );
292 
293   enum ErrorCode {
294     NoError = 0,
295     InvalidTableVersion = 241,
296     DropInProgress      = 283,
297     Busy = 701,
298     BusyWithNR = 711,
299     NotMaster = 702,
300     InvalidFormat = 703,
301     AttributeNameTooLong = 704,
302     TableNameTooLong = 705,
303     Inconsistency = 706,
304     NoMoreTableRecords = 707,
305     NoMoreAttributeRecords = 708,
306     NoSuchTable = 709,
307     AttributeNameTwice = 720,
308     TableAlreadyExist = 721,
309     ArraySizeTooBig = 737,
310     RecordTooBig = 738,
311     InvalidPrimaryKeySize  = 739,
312     NullablePrimaryKey = 740,
313     UnsupportedChange = 741,
314     BackupInProgress = 762,
315     IncompatibleVersions = 763,
316     SingleUser = 299,
317     TableDefinitionTooBig = 793
318   };
319 
320   Uint32 senderRef;
321   union {
322     Uint32 clientData;
323     Uint32 senderData;
324   };
325   Uint32 transId;
326   Uint32 errorCode;
327   Uint32 errorLine;
328   Uint32 errorNodeId;
329   Uint32 masterNodeId;
330   Uint32 errorStatus;
331   Uint32 errorKey;
332 };
333 
334 /**
335  * Inform API about change of table definition
336  */
337 struct AlterTableRep
338 {
339   friend bool printALTER_TABLE_REP(FILE*, const Uint32*, Uint32, Uint16);
340 
341   STATIC_CONST( SignalLength = 3 );
342 
343   enum Change_type
344   {
345     CT_ALTERED = 0x1,
346     CT_DROPPED = 0x2
347   };
348 
349   Uint32 tableId;
350   Uint32 tableVersion;
351   Uint32 changeType;
352 
353   SECTION( TABLE_NAME = 0 );
354 };
355 
356 
357 #undef JAM_FILE_ID
358 
359 #endif
360