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